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
[ENH] Add new returns to NiftiLabelsMasker
's transform
output
#3761
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. |
Hi, I want to add new outputs to |
Also, I can add |
@mtorabi59 it's a breaking change so we would have to go with a deprecation. However, I need to brush up a bit on the issue. I'm wondering if it would make sense to instead add the new returns as attributes to the |
@ymzayek I think that makes sense. because they are not depending on |
I face a problem here because I'm adding a new output to |
Actually, we should strive to have always the same outputs for a given function. Using a dictionary is a bit cheating and will make it harder to find bugs I'm afraid. Isn't there a way to change systematically the output of this function ? |
Yes, I agree. Do you mean the output of |
I just mean that this function is called from many different places in the codebase. So the change may be quite important. |
So I added a optional argument called |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3761 +/- ##
=======================================
Coverage 91.81% 91.82%
=======================================
Files 144 144
Lines 16173 16187 +14
Branches 3360 3364 +4
=======================================
+ Hits 14850 14864 +14
Misses 781 781
Partials 542 542 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
For this error from documentation builder: |
looks like sphinx is trying to build a hyperlink not sure why it is happening there and not for other places in the code base where we have this |
FIXED by this commit. The name of the attribute with a trailing underscore was not the problem. this_is_ok_ : Niimg-like object
Something like this will not be ok --> this_is_ok_
But this is is fine --> ``this_is_ok_`` |
…o add_regions_labels
Is the documentation error from my part? I don't find the error message referring to the line that is causing this:/ |
keep_masked_labels=self.keep_masked_labels, | ||
mask_img=self.mask_img, | ||
) | ||
return signals, (labels, masked_labels_img) |
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.
And here since this is a private function we can just add the new return without making part of a tuple
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.
@ymzayek no, the tuple is because _filter_and_extract
gets only two inputs and we didn't want to change 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.
Ok and not wanting to change _filter_and_extract
is because it is called by other maskers not dealt with in this PR? I think we can leave it like this for this PR but just noting that it seems reasonable to me to change its return behavior if other maskers will be changed to support returning a masked image as well.
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.
@ymzayek yes we have to change it's behavior in future
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 the updates! I want to give it another full review but seems like it's good to go
nilearn/regions/signal_extraction.py
Outdated
background_label : number, default=0 | ||
Number representing background in labels_img. | ||
background_label : number, optional | ||
Number representing background in labels_img. Default=0. | ||
|
||
order : :obj:`str`, default="F" | ||
Ordering of output array ("C" or "F"). | ||
order : :obj:`str`, optional | ||
Ordering of output array ("C" or "F"). Default="F". | ||
|
||
strategy : :obj:`str`, default="mean" | ||
strategy : :obj:`str`, optional | ||
The name of a valid function to reduce the region with. | ||
Must be one of: sum, mean, median, minimum, maximum, variance, | ||
standard_deviation. | ||
standard_deviation. Default="mean". | ||
%(keep_masked_labels)s |
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.
Here we shouldn't see a diff. The default values were moved up to the type definition in another PR so maybe this is a result of incorrect merge conflict resolution
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.
Minor stuff
NiftiLabelsMasker
's transform
output
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 can you make the following changes?
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.
The PR LGTM. @ymzayek proposed an additional test thatw e could add.
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 ! LGTM
Thank you @ymzayek ! |
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.
Merging 🚀 |
@mtorabi59 |
region_ids_ : dict | ||
A dictionary containing the region ids corresponding | ||
to each column in region_signal. | ||
The region id corresponding to ``region_signal[:,i]`` | ||
is ``region_ids_[i]``. | ||
``region_ids_['background']`` is the background label. | ||
|
||
.. versionadded:: 0.11.0.dev | ||
|
||
region_names_ : dict | ||
A dictionary containing the region names corresponding | ||
to each column in region_signal. | ||
The region names correspond to the labels provided | ||
in labels in input. | ||
The region name corresponding to ``region_signal[:,i]`` | ||
is ``region_names_[i]``. | ||
|
||
.. versionadded:: 0.11.0.dev | ||
|
||
region_atlas_ : Niimg-like object | ||
Regions definition as labels. | ||
The labels correspond to the indices in ``region_ids_``. | ||
The region in ``region_atlas_`` that takes the value ``region_ids_[i]`` | ||
is used to compute the signal in ``region_signal[:,i]``. | ||
|
||
.. versionadded:: 0.11.0.dev | ||
|
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
Random question on this PR: why was it chosen for those attributes to have a trailing underscore?
Why couldn't we have:
- region_names
- region_atlas
- region_ids
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 it means that these quantities are estimated, i.e. fit-/data-dependent.
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.
ha. I guess we should probably mention that somewhere in our style guide, because it is clearly not obvious.
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.
It's an sklearn convention, but you're right.
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 am fine just pointing to the scikit learn doc: https://scikit-learn.org/stable/developers/develop.html#estimated-attributes
Addresses #3085 .
Changes proposed in this pull request:
NiftiLabelsMasker
transform_single_imgs
besidesregion_signals
, including:region_ids
andregion_img