Skip to content

Conversation

m-miedema
Copy link

So far this is a quick addition to the data_loader: I added a new function (nifti2arraywmask) that allows the use of the 3-D mask file to extract BOLD signals. I also modified the main data loader function (nifti2timeseries) to support its use - at least for single subject/single session data.

To-dos from here could include adding multi-session support, adding in an example of usage to the demos, and providing more guidance on creating a mask (I have a script I can contribute to that).

I added a new function (nifti2arraywmask) that allows the use of the 3-D mask file to extract BOLD signals. I also modified the main data loader function (nifti2timeseries) to support its use - at least for single subject/single session data :)
@mtorabi59 mtorabi59 self-requested a review July 4, 2025 18:16
@mtorabi59 mtorabi59 marked this pull request as ready for review July 4, 2025 18:22
Comment on lines 316 to 317
if mask_file is not None and n_rois is not None:
print("Warning: specified mask_file will be used, ignoring n_rois.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if mask_file is not None and n_rois is not None:
print("Warning: specified mask_file will be used, ignoring n_rois.")
if mask_file is not None and n_rois is not None:
n_rois = None
warnings.warn("specified mask_file will be used, ignoring n_rois.")

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and maybe import warnings

Comment on lines 313 to 314
if mask_file is None and n_rois is None:
print("Either mask_file or n_rois must be defined.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to raise an error here:

Suggested change
if mask_file is None and n_rois is None:
print("Either mask_file or n_rois must be defined.")
if mask_file is None and n_rois is None:
raise ValueError("Either mask_file or n_rois must be defined.")

@mtorabi59
Copy link
Collaborator

@m-miedema Thanks so much for implementing this new functionality! Overall it looks good. I have put a few suggestions. Also, since nifti2arraywmask has a lot in common with nifti2array I think it makes sense if we merge them, so it's just nifti2array with a new argument and a bit of change.
Additionally, since nilearn supports different kinds of maskers - NiftiLabelsMasker, NiftiMapsMasker, NiftiSpheresMasker, even SurfaceMasker, it'd be useful for the user if we clarify that this added functionality is only using NiftiLabelsMasker for now. So for instance we can call the mask_file, labels_img, or sth like labels_masker_file. What do you think?

@mtorabi59
Copy link
Collaborator

And regarding an example, I think that's a great idea. If we can have a separate example dedicated to use casing of your functionality, based on the script you already have, it'll be super useful for the users.

@mtorabi59
Copy link
Collaborator

@m-miedema , please take a look at the new changes I made to the data_loader module once you pull them. I have implemented support for NiftiSpheresMasker. Let me know if it works for what you want to do!

@m-miedema
Copy link
Author

The new additions look good to me! Would you prefer I create a separate demo notebook to add to the future examples directory? I think they will be a good place to highlight considerations for mask creation and to document several potential pitfalls that come with specifying a list of labels I've encountered while testing on my own masks and data.

@mtorabi59
Copy link
Collaborator

The new additions look good to me! Would you prefer I create a separate demo notebook to add to the future examples directory? I think they will be a good place to highlight considerations for mask creation and to document several potential pitfalls that come with specifying a list of labels I've encountered while testing on my own masks and data.

Creating a new notebook is a great idea @m-miedema ! I'll create a new directory for examples containing a copy of the current demos and then you can add your new notebook there!

@mtorabi59
Copy link
Collaborator

@m-miedema you can pull the new directory now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants