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
Adding keep_masked_labels parameter to Labels_masker #3722
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 #3722 +/- ##
==========================================
- Coverage 91.65% 91.53% -0.13%
==========================================
Files 139 133 -6
Lines 16562 15575 -987
Branches 3229 3233 +4
==========================================
- Hits 15180 14256 -924
+ Misses 1379 772 -607
- Partials 3 547 +544
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 87 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
2a3d8c3
to
1819e24
Compare
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.
Looks good so far!
we also need to change the behavior of the inverse transform. Should we do that after the deprecation cycle of the current change or we should do that in this cycle too? I mean for |
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, 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.
easier correspondance between the region names / labels and the masker output will be handled in another pr?
@@ -89,6 +90,22 @@ class NiftiLabelsMasker(BaseMasker, _utils.CacheMixin): | |||
Must be one of: sum, mean, median, minimum, maximum, variance, | |||
standard_deviation. Default='mean'. | |||
|
|||
keep_masked_labels : :obj:`bool`, optional | |||
When a mask is supplied through the "mask_img" parameter, some | |||
labels in the atlas may not have any brain coverage within 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.
I think we can still improve the docstring a little bit. maybe instead of "may not have any brain coverage within the masked region" we could say "some atlas regions may lie entirely outside of the brain mask"?
nilearn/regions/signal_extraction.py
Outdated
keep_masked_labels : :obj:`bool`, optional | ||
When a mask is supplied through the "mask_img" parameter, some | ||
labels in the atlas may not have any brain coverage within the | ||
masked region, resulting in empty time series for those labels. |
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.
you may want to take advantage of the _utils.fill_doc
mechanism to avoid repeating this docstring
Yes, I will work on that in another PR. Does that sound good? |
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 nice work! I was wondering if there is any reason some files were reformatted (perhaps with a tool like black)? If they are not formatted by us then we don't expect users to format them because it leads to large diffs making it harder to review relevant changes. If it has to do with flake8 failing for new code it's preferable to fix it manually.
@ymzayek yes it's because I used black since it was failing every time. But you are right. I will discard the changes and reformat only my part. |
According to the black config on your branch the following should not be touched by black:
|
my suggestion to fix: reset to before you fixed things with black and only run black on the files that need it (according to this last failed CI: https://github.com/nilearn/nilearn/actions/runs/5094502417/jobs/9158397158#step:5:12) git reset --hard 9bd9e49
black nilearn/regions/signal_extraction.py
black nilearn/regions/tests/test_signal_extraction.py
git add nilearn/regions
git commit -m 'run black' you will have to force push after that |
To make your life easier, you may want to install pre-commit so that you will only commit properly formatted code: https://nilearn.github.io/stable/development.html#pre-commit pre-commit will only fix files that have been staged so it should avoid fixing files you never touched. If I have done my job well pre-commit should also ignore files we have not reformated yet even you staged them. |
Thnx a lot @Remi-Gau !! |
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 thanks for making the changes! I think what is left is to add tests to make sure the 2 new warnings are raised. You could add with pytest.warns
to the test you already wrote and do another where keep_masked_labels=True
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.
Thx @mtorabi59 !
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
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.
thanks @mtorabi59 !
Addresses #3085 .
Changes proposed in this pull request:
keep_masked_labels
parameter toimg_to_signals_labels
, andNiftiLabelsMasker
keep_masked_labels=True
, which is the default, it will maintain the old behavior. ow, it will remove the labels, or regions, that were masked and became empty bymask_img
.