New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add keep_masked_maps to NiftiMapsMasker #3732
Conversation
👋 @mtorabi59 Thanks for creating a PR! Until this PR is ready for review, you can include the [WIP] tag in its title, or leave it as a github draft. Please make sure it is compliant with our contributing guidelines. In particular, be sure it checks the boxes listed below.
For new features:
For bug fixes:
We will review it as quick as possible, feel free to ping us with questions if needed. |
Codecov Report
@@ Coverage Diff @@
## main #3732 +/- ##
==========================================
- Coverage 91.53% 91.53% -0.01%
==========================================
Files 133 133
Lines 15600 15611 +11
Branches 3246 3249 +3
==========================================
+ Hits 14279 14289 +10
Misses 774 774
- Partials 547 548 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
So I found out that interestingly a parameter called |
Is the deprecation warning in the right place? |
I would say yes, the warning is in the right place and we should remove it from the function too -- I don't think keeping outputs for empty regions with arbitrary values is a useful feature. but you might want to use the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting keep_masked_maps to True or False does not change anything, am I right ?
@bthirion could you share the code that results in the same behavior? for me it does make a difference. the following code returns signals with shape (17, 3) when
|
Indeed. Sorry, I did not spot where in the code the decisive change takes place. |
@bthirion Do you think it needs to be clarified? |
I think it should for further reference and fixes. Thx ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a look at the documentation and here's my attempt to understand it. I hope this makes the behaviour clearer and help us to improve the documentation 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this is clearer now. Thx !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! The docs is really clear now. Just have another look at the deprecation warning and perhaps move some of the explanation to tje change log. Otherwise it's almost good!
nilearn/regions/signal_extraction.py
Outdated
"Map image only contains " | ||
f"{len(labels_after_mask)} maps.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Map image only contains " | |
f"{len(labels_after_mask)} maps.", | |
f"Out of {len(labels_before_mask)} maps, the " | |
"masked map image only contains " | |
f"{len(labels_after_mask)} maps.", |
nilearn/regions/signal_extraction.py
Outdated
'Starting in version 0.15, the behavior of "NiftiMapsMasker" ' | ||
'will change when a mask is supplied through the "mask_img" ' | ||
'parameter. The atlases are masked by "mask_img" before any ' | ||
'signal extraction happens. However, some maps in the atlas ' | ||
'may contain no brain coverage after applying the mask, ' | ||
'resulting in an invalid map with only zeroes (not suitable ' | ||
'for signal extraction). These invalid maps used to be kept. ' | ||
'In the new behavior, they will be removed from the output. ' | ||
'\n\n' | ||
'If "keep_masked_maps" is set to True, the masked atlas with ' | ||
'these invalid maps will be retained in the output, resulting ' | ||
'in corresponding time series with zeros only (old behavior). ' | ||
'To enable this ' | ||
'behavior, specify the parameter "keep_masked_maps=True" when ' | ||
'initializing the "NiftiMapsMasker" object.\n\n' | ||
'Starting from version 0.13, the default behavior will be ' | ||
'changed to "keep_masked_maps=False". If "keep_masked_maps" ' | ||
'is set to False, the invalid maps will be removed from the ' | ||
'trimmed atlas, ensuring no empty time series are present in ' | ||
'the output (new behavior). ' | ||
'To explicitly disable the retention of masked ' | ||
'maps, specify the parameter "keep_masked_maps=False" when ' | ||
'initializing the "NiftiMapsMasker" object.' | ||
'"keep_masked_maps" parameter will be removed ' | ||
'in version 0.15.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is way too long for a deprecation warning.
I would just state three things
- The output will contain empty time series.
- Starting from version 0.13, the default behavior will be
keep_masked_maps=False
keep_masked_maps
will be removed in version 0.15
Just point the users to read the docs.
Probably tighten this up and put it in the change log?
How is this? Does it need to be shorter? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as for #3722 -- how do we make it easier for users to match masker output dimensions with atlas maps / region names? is this left for another PR?
nilearn/maskers/nifti_maps_masker.py
Outdated
|
||
keep_masked_maps : :obj:`bool`, optional | ||
If True, masked atlas with invalid maps (maps with no brain coverage | ||
after applying the mask) will be retained in the output, resulting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure "no brain coverage" is very clear -- maybe maps that contain only zeros after applying the mask?
nilearn/regions/signal_extraction.py
Outdated
keep_masked_maps : :obj:`bool`, optional | ||
If True, masked atlas with invalid maps (maps with no brain coverage | ||
after applying the mask) will be retained in the output, resulting | ||
in corresponding time series containing zeros only. If False, the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you want you can use the _utils.fill_doc
to avoid having to update the docstring in several places
Yes, it will be handled in another PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is overlap with #3722, let's work on merging that one first and then rebasing this on main. Pretty much the same comments apply but I'll give a more thorough review after that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just minor formatting things
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks @mtorabi59 !
Thank you @ymzayek !! |
# keep_masked_maps | ||
docdict["keep_masked_maps"] = """ | ||
keep_masked_maps : :obj:`bool`, optional | ||
If True, masked atlas with invalid maps (maps that contain only | ||
zeros after applying the mask) will be retained in the output, resulting | ||
in corresponding time series containing zeros only. If False, the | ||
invalid maps will be removed from the trimmed atlas, resulting in | ||
no empty time series in the output. | ||
|
||
.. deprecated:: 0.10.2.dev | ||
|
||
The 'True' option for ``keep_masked_maps`` is deprecated. | ||
The default value will change to 'False' in 0.13, | ||
and the ``keep_masked_maps`` parameter will be removed in 0.15. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mtorabi59
entries in this docs.py are supposed to be sorted alphabetically so this should probably be moved.
I can do it in #3621 after this is merged, just wanted to let you know. 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Remi-Gau I'll have that in mind for next time! Thnx!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no worries but having things sorted can become helpful for long lists like this (also helps make sure you prevent the blood pressure of maintainers with sub-clinical OCD from rising too much)
Addresses #3085 .
Changes proposed in this pull request:
keep_masked_maps
parameter toimg_to_signals_maps
, andNiftiMapsMasker
keep_masked_maps=True
, which is the default, it will maintain the old behavior. ow, it will remove the maps, or regions, that were masked and became empty bymask_img
.