You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We recently fit GLMs to edge timeseries (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC10369861/) in order to look at fluctuations of attention at the network level. We believe it's an exciting approach that offers novel information and which is really easy to implement.
Almost all of the code was based off of nilearn - it mostly involved just changing FirstLevelModel().fit to take numpy arrays, rather than niimgs, so that we could give it the 2D arrays (n_features x n_scans).
It would be really great to bake this feature directly into nilearn, so that it can be easily kept up to date with other nilearn features and bug-fixes. I believe the changes to the code would be minimal, and add little-to-no maintenance, and I would be happy to submit the pull request myself.
I have some example pieces of potential changes below.
Benefits to the change
This would add flexibility to the nilearn code for fitting first-level models - letting it fit edges, or even just data that is in a significantly different format (e.g., open data that was already preprocessed and parcellated with some atlas). It would cost very little to maintain.
Pseudocode for the new behavior, if applicable
# insert your code belowdeffit(...):
if (self.mask_imgisNone) & (type(run_imgs[0])==np.ndarray):
assertrun_imgs[0].shape==2# nFeatures x nScans
...
iftype(run_img)==np.ndarray:
Y=run_imgelse:
run_img=check_niimg(run_img, ensure_ndim=4)
Y=self.masker_.transform(run_img, sample_mask=sample_mask)
ifdesign_matricesisNone:
n_scans=Y.shape[-1]
defcompute_contrast(...):
...
ifself.masker_isNone:
output=estimate_else:
output=self.masker_.inverse_transform(estimate_)
The text was updated successfully, but these errors were encountered:
Given that the GLM is natively implemented on arrays, it is indeed easy to do. The only that has to be done is to create a high-level API that encapsulates the function. So the cost is minimal.
I don't think we should advertise much these functions, but I think it is OK to have them.
Any other opinion ?
To clarify: @bthirion are you suggesting making a new function specifically designed to take lists of numpy arrays? My initial idea was to just modify FirstLevelModel.fit and .compute_contrast to be able to handle numpy arrays, in addition to niimgs.
I think it would increase a lot the complexity of the object. It also makes debugging difficult, when you hit an error in a complex pipeline and are not sure whether a given argument is an image, an array or whatever.
henrymj
added a commit
to henrymj/nilearn
that referenced
this issue
Nov 16, 2023
Is there an existing issue for this?
Describe your proposed enhancement in detail.
We recently fit GLMs to edge timeseries (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC10369861/) in order to look at fluctuations of attention at the network level. We believe it's an exciting approach that offers novel information and which is really easy to implement.
Almost all of the code was based off of nilearn - it mostly involved just changing FirstLevelModel().fit to take numpy arrays, rather than niimgs, so that we could give it the 2D arrays (n_features x n_scans).
It would be really great to bake this feature directly into nilearn, so that it can be easily kept up to date with other nilearn features and bug-fixes. I believe the changes to the code would be minimal, and add little-to-no maintenance, and I would be happy to submit the pull request myself.
I have some example pieces of potential changes below.
Benefits to the change
This would add flexibility to the nilearn code for fitting first-level models - letting it fit edges, or even just data that is in a significantly different format (e.g., open data that was already preprocessed and parcellated with some atlas). It would cost very little to maintain.
Pseudocode for the new behavior, if applicable
The text was updated successfully, but these errors were encountered: