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
[FIX] Disable extrapolation of out-of-bounds volumes #4028
Conversation
👋 @jhuguetn 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 @jhuguetn thanks for opening the PR! Could you also add a test to |
Codecov Report
@@ Coverage Diff @@
## main #4028 +/- ##
==========================================
- Coverage 91.59% 91.52% -0.08%
==========================================
Files 145 143 -2
Lines 16238 16086 -152
Branches 3376 3342 -34
==========================================
- Hits 14874 14722 -152
- Misses 817 819 +2
+ Partials 547 545 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 77 files with indirect coverage changes 📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today! |
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 agree that we definitely need a test for (preferably not just a smoke test) |
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.
Initially it seemed that this is a bug fix with limited scope, hence the current solution could be ok. However, it is a behavioral change and to me the impact on user code is hard to tell so I agree with @htwangtw that it is safest to go through a deprecation cycle especially since the faulty implementation did not actually fail any user code IIUC. So I would follow the suggestions as laid out by @htwangtw and @Remi-Gau to expose extrapolate
in signal clean, keep default behavior, throw a deprecation warning in the appropriate place to tell the user to set extrapolate=False
. The warning should say that the default behavior will change in release 0.13
. @jhuguetn is it clear?
372356b
to
db5a970
Compare
Yes, it is @ymzayek. Thanks! |
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 probably want to add a test to ensure that no extrapolation is performed.
Yes, I am working on that. I have encountered a small bump that perhaps any of you all can help me with. When extrapolation is disabled, scipy While testing the new
To cope with that I've tried dropping the NaNs, but then by design some posterior steps in charge of volume censoring in
As an alternative, I thought we could assign a fix/hardcoded value temporarily to those NaNs (which would be censored later) or replace them by the original data, but still I don't like the idea since I lose notion of what's been discarded in the interpolation step. In addition, it might have an impact doing so on posterior steps. As an example see below a
I am interested in knowing what you folks think. Thanks! |
The NaN issue mentioned by @jhuguetn - I pointed out this potential issue in the original discussion. I could have elaborated it more. After the Lines 821 to 826 in db5a970
What you will need a new sample_mask that's for the volumes of the heads and tails you want to discard.Let me know if this makes sense. I can implement it if need be. |
Thanks @htwangtw for the suggestion, I will try that |
db5a970
to
3b9e093
Compare
Hi @jhuguetn did you accidentally close this or would you like one of the core developers to take over working on it? |
Sorry, I discarded the first changes and replaced them with new ones based on suggestions made. |
I have now included a proposal for dealing with the NaNs issue following your advice @htwangtw of reseting the
The problem of using In addition, my PR includes now a test 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.
We need a new test for clean
as there are code modified beyond the private function.
I suggest to look for all instance of sample_mask
after _handle_scrubbed_volumes
and see what's the impact of the NaN values.
Let me know if you would prefer me to take over.
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.
We're almost there I think ! 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.
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.
@jhuguetn can you add a test checking that the warning is raised? And can you also add a whatsnew entry to doc/changes/latest.rst
and your name to CITATION.cff
? (see https://nilearn.github.io/dev/development.html#changelog for more detail)
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 would recommand adding one more test in nilearn/tests/test_signal.py::test_sample_mask
to test all the subsequent processes are performed correctly.
|
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 now! Thanks for all the hard work!
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 @jhuguetn ! The failure is unrelated to this PR. Merging
* expose CubicSpline extrapolate parameter (nilearn#4028) * [FIX] discard non-interpolated volumes and reset the sample_mask indexes * [REF] discard non-interpolated volumes and reset sample_mask in '_handle_scrubbed_volumes' * [FMT] black formatting * improve deprecation warning message * check that extrapolation warning is raised * add changelog and contribution entries * check consistency of modified sample_mask * assert modified sample_mask can be applied to signals and confounds * [REF] split signal extrapolation testing in 2 tests
* remove leading underscore from non private functions * rm underscores in datasets * rm underscores in decoding * update script * rename module * rm more leading underscore from decoding mass_univariate datasets * rename module * move functions * add doc string * rename functions * rename function * Update doc/changes/0.10.1.rst * flake8 * fix * Update nilearn/signal.py Co-authored-by: Yasmin <63292494+ymzayek@users.noreply.github.com> * typo (#4091) * [MAINT] update DOI and add RRID (#4032) * update DOI * update which DOI is used and add RRID * [DOC] mention checking badges during release (#4085) * [MAINT] Fix Zenodo DOI badge (#4093) * pre-commit hooks auto-update (#4097) Co-authored-by: Remi-Gau <Remi-Gau@users.noreply.github.com> * Remove extraneous hash symbols (#4096) * [DOC] Improve docstring rendering for typed experimental surface module (#4049) * Correct linking * Fix note * Add tagging (#4100) * [FIX] Disable extrapolation of out-of-bounds volumes (#4028) * expose CubicSpline extrapolate parameter (#4028) * [FIX] discard non-interpolated volumes and reset the sample_mask indexes * [REF] discard non-interpolated volumes and reset sample_mask in '_handle_scrubbed_volumes' * [FMT] black formatting * improve deprecation warning message * check that extrapolation warning is raised * add changelog and contribution entries * check consistency of modified sample_mask * assert modified sample_mask can be applied to signals and confounds * [REF] split signal extrapolation testing in 2 tests * [BOT] update AUTHORS.rst and doc/changes/names.rst (#4102) Co-authored-by: ymzayek <ymzayek@users.noreply.github.com> * [MAINT] Add listing utilities (#2991) * Add listing utilities * Add possibility to filter by modules * Add some tests * Fix PEP8 * Clarify ignored modules by default * Add section on Nilearn API in the user guide * Export at the end * [circle full] Add whats new * revert * more revert * lint * fix tests * lint * adapt tests to check number of public functions and classes * update doc strings * fix --------- Co-authored-by: Remi Gau <remi_gau@hotmail.com> * fix number of functions * adapt number of functions * update changelog --------- Co-authored-by: Yasmin <63292494+ymzayek@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Remi-Gau <Remi-Gau@users.noreply.github.com> Co-authored-by: Jordi Huguet <jhuguetn@gmail.com> Co-authored-by: ymzayek <ymzayek@users.noreply.github.com> Co-authored-by: Gensollen <nicolas.gensollen@gmail.com>
Changes proposed in this pull request:
extrapolate
parameter in thesignal._interpolate_volumes()
function, exposing the identically named parameter from the Scipy class used underneath for the Splines-based interpolation (see https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.CubicSpline.html#scipy.interpolate.CubicSpline).extrapolate
new parameter value to False, disabling the undesired interpolation on out-of-bounds volumes