Nilearn: Events of the same type that end simultaneously

Created on 29 Jan 2021  Â·  3Comments  Â·  Source: nilearn/nilearn

nilearn 0.7.0

Hi-
I've accidentally discovered a new way to break make_first_level_design_matrix, with overlapping events of the same trial_type but different durations. If two events like this end simultaneously, only one of them gets ended, leading to an elevated regressor for the rest of the frames.

Below is some example code, and the figure it produces:
break_make_first_level_design_matrix

It took a while to find this one! I think the reason I'm coming across these is that I'm modelling naturalistic stimuli using ratings, and using boxcars rather than creating regressors.
Very best
Rhodri

import pickle
import pandas as pd
from nilearn.glm.first_level import make_first_level_design_matrix
import numpy as np
from matplotlib import pyplot as plt

frame_times=np.arange(20)

fig, ax= plt.subplots(nrows=2)

# All good
events=pd.DataFrame({'onset': [2, 4, 4.5], 'duration': [1.0, 1.0, 1.0], 'trial_type': ['vanilla']*3})
X = make_first_level_design_matrix(frame_times, events= events, hrf_model=None)
ax[0].plot(X['vanilla'])

# Second and third events end at same time, so second event never ends!
events=pd.DataFrame({'onset': [2, 4, 4.5], 'duration': [1.0, 1.5, 1.0], 'trial_type': ['vanilla']*3})
X = make_first_level_design_matrix(frame_times, events= events, hrf_model=None)
ax[1].plot(X['vanilla'])

plt.savefig('break_make_first_level_design_matrix.jpg')
Bug

Most helpful comment

Yes, installing the current master branch fixes the problem for me too.
Thank you!


From: Taylor Salo notifications@github.com
Sent: Friday 29 January 2021 20:26
To: nilearn/nilearn nilearn@noreply.github.com
Cc: Rhodri Cusack rhodricusack@gmail.com; Author author@noreply.github.com
Subject: Re: [nilearn/nilearn] Events of the same type that end simultaneously (#2674)

I just ran your code locally using the current master branch and it looks different to me:

[image]https://user-images.githubusercontent.com/8228902/106323743-e76edd00-6245-11eb-8d44-4dd8d9570dde.png

Are you able to reproduce the bug on the current master branch?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHubhttps://github.com/nilearn/nilearn/issues/2674#issuecomment-770031515, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAL7HSP52J7WBSHAOIOCTWDS4MKYLANCNFSM4WZNMKCA.

All 3 comments

I just ran your code locally using the current master branch and it looks different to me:

image

Are you able to reproduce the bug on the current master branch?

Yes, installing the current master branch fixes the problem for me too.
Thank you!


From: Taylor Salo notifications@github.com
Sent: Friday 29 January 2021 20:26
To: nilearn/nilearn nilearn@noreply.github.com
Cc: Rhodri Cusack rhodricusack@gmail.com; Author author@noreply.github.com
Subject: Re: [nilearn/nilearn] Events of the same type that end simultaneously (#2674)

I just ran your code locally using the current master branch and it looks different to me:

[image]https://user-images.githubusercontent.com/8228902/106323743-e76edd00-6245-11eb-8d44-4dd8d9570dde.png

Are you able to reproduce the bug on the current master branch?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHubhttps://github.com/nilearn/nilearn/issues/2674#issuecomment-770031515, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAL7HSP52J7WBSHAOIOCTWDS4MKYLANCNFSM4WZNMKCA.

Since this will be fixed in the 0.7.1 release, I'm going to close it. For posterity- any users who come across this issue should update nilearn to >= 0.7.1 (or the master branch if 0.7.1 hasn't been released yet).

I'll also open a PR to update whats_new.rst with information about the bug. Thanks @rhodricusack for reporting the bug- otherwise, I'm not sure it would have been documented.

EDIT: Just to provide context, it looks like this was fixed in #2553.

Was this page helpful?
0 / 5 - 0 ratings