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
[NF] migrate package load_confounds
main function load_confounds
#2946
[NF] migrate package load_confounds
main function load_confounds
#2946
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2946 +/- ##
==========================================
+ Coverage 89.31% 89.78% +0.46%
==========================================
Files 100 105 +5
Lines 13912 14256 +344
Branches 2711 2781 +70
==========================================
+ Hits 12426 12800 +374
+ Misses 896 869 -27
+ Partials 590 587 -3
Continue to review full report at Codecov.
|
I have done some research on the minimal version of fMRIprep output we can support and added them to the existing docstrings. We can fully support everything from 1.4.X, and 1.2.X except There are two aspect that I would like @NicolasGensollen to make an executive call on:
from nilearn.fmriprep import Confounds This can be a place for all potential future fmriprep helper functions. WDYT? cc @pbellec |
@htwangtw can the module work generally with BIDS derivatives (especially w.r.t. bids-standard/bids-specification#519, which proposes rules that are probably what dictate fMRIPrep's derivatives)? I think a |
@tsalo Thanks for bringing this up! I had a quick read through of BEP 012. From what I am aware, |
I feel like Currently, the main use case for the confounds features is for fMRIprep users. I am not aware of software using the BIDS fMRI derivatives at the moment, and I am not sure that fMRIprep itself conforms to the standard, which is still a draft as far as I can tell. Also, BIDS is most commonly associated with raw data, and unless |
@pbellec one motivation I have for |
so if there is a push for a set of bids tools in nilearn,
Another option would be to have long and explicit class names, like what is done for the masker classes.
|
Thanks for opening this @htwangtw ! 👍 |
I can certainly add an examples. We do have an existing demo jupyter notebook based on a NiftiMasker example. It needs some updates but I can certainly put it somewhere. |
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 for this PR !
Now I better understand why the code refers to fMRIprep rather than BIDS.
What i don't understand atm is why we need a Confound class, not a function ? (functions are earsier to maintain).
nilearn/load_confounds/data/missing_desc-confounds_regressors.tsv
Outdated
Show resolved
Hide resolved
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 @htwangtw ! 👍
I made a first pass (mostly trying to understand how things are structured) and made a few small comments (see below).
w.r.t. fmriprep vs BIDS - Moving load_confounds to part of BIDS integration can be some work down the line. It will be a while before BEP 012 get merged and applied to fMRIPrep. That's a lot of things to anticipate and address for now, and I cannot see the changes of BEP 012 coming in the immediate future. At the moment load_confounds is for fMRIprep rather than BIDS. |
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 for addressing the reviews so quickly @htwangtw !
Below are a few comments and suggestions (mostly on documentation and formatting).
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.
@htwangtw I spent some time building the docs from your branch in strict mode which always fail because of annoying little things like wrong indents, missing blank lines and so on...
Below are a few things I had to fix to make it work as well as some suggestions for better linking of resources.
Note: Do not hesitate to request full builds from time to time by adding "[circle full]" in your commit message.
Regarding the suggestion on adding tests to private functions, I am only going to do a selective set.
|
@htwangtw I just pushed a commit to your PR in which I propose to refactor a little bit some tests. |
Thanks for the refactoring @NicolasGensollen |
@htwangtw The documentation build error wasn't related to this PR. I pushed a fix earlier today, so if you merge master you should have the CI all green again. ✔️ Concerning the design choice of having a class vs. functions for Confounds, I also feel like we don't really need the complexity of multiple classes inheriting from the Maybe the best way to decide is to compare the two designs (I can have a go at refactoring this if you want). |
Looks like there's problem with full build still, but partial build is fine. Great timing! I was leaving this comment to the last. I have time and just started a local branch for the refectoring and will see how it goes. |
Could not agree more. Thx ! |
@NicolasGensollen @bthirion I have refactored the code to function - was less work then I thought and not that much chance in the number of lines.
Is this okay? |
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 for refactoring this so quickly @htwangtw ! 👍
I just made a quick pass (see below), I will have another look later today.
The import will depend on the name we end up choosing but Having only |
Yes. So it will be like: from nilearn.load_confounds import minimal Function: from nilearn.load_confounds import load_confounds
def minimal(img_files, motion="full", wm_csf="basic", demean=True):
strategy = ["high_pass", "motion", "wm_csf", "non_steady_state"]
# some sanity checks here
return load_confounds(strategy=strategy, motion=motion, wm_csf=wm_csf, demean=demean) |
In terms of import path, I wonder whether it would not make sense put
this together with the maskers. I don't really like the name of the
modules where the maskers are based (I'm to blame).
Maybe an "io" module that groups the confounder loading and the maskers?
My 2 cents from the peanut gallery
|
load_confounds
main function load_confounds
Numpy retires the legacy random state after v1.21, which only supports python 3.7 and above
All builds passed 🎉 I will implement the four preset strategy next. |
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 @htwangtw !
Just a minor formatting suggestion but LGTM otherwise.
Co-authored-by: Gensollen <nicolas.gensollen@gmail.com>
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.
Will do asap... |
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.
Hi, I've simply foud a couple of typos. This good to go otherwise !
Thx again,
Co-authored-by: bthirion <bertrand.thirion@inria.fr>
`srub` now accept an integer from 0 to n. After removing high motion volumes, segments with number of frame < `scrub` will also be removed. Default value is 5. ADD explicit author names in th main fmriprep_confounds module.
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.
LGTM, thanks @htwangtw !
Thanks everyone for the work on this! 💯 |
Congrats @htwangtw for driving this PR home, and big thanks to the |
That's a great new feature indeed ! |
Closes nilearn#2946. This is the second part to merge pacakge `load_confounds`. * Add predefined strategy with a dictionary containing relevant parameters * New function fmriprep_confounds_strategy to parse user input for the predefined strategy * Add example and brief explaination of the four based strategy The example is super preliminary, please raise any suggestion and better way to introduce the function. Co-authored-by: Pierre Bellec <pierre.bellec@gmail.com>
* [NF] get fmriprep confounds with fixed strategy Closes #2946. This is the second part to merge pacakge `load_confounds`. * Add predefined strategy with a dictionary containing relevant parameters * New function fmriprep_confounds_strategy to parse user input for the predefined strategy * Add example and brief explaination of the four based strategy The example is super preliminary, please raise any suggestion and better way to introduce the function. Co-authored-by: Pierre Bellec <pierre.bellec@gmail.com> * LINT pep8 * DOCS limit of example dataset Some confound variables are not availible in the reduced experimental dataset Comment out the lines for now to let the test pass * Typos Co-authored-by: bthirion <bertrand.thirion@inria.fr> * Apply suggestions from code review Co-authored-by: Gensollen <nicolas.gensollen@gmail.com> * EHN raise error for invalid strategy Remove examples that cannot be executed correctly * LINT flake8 * Apply suggestions from code review Co-authored-by: Gensollen <nicolas.gensollen@gmail.com> * [DOCS] maybe demostrate the results of denoising through PCA * [TEST] factorise checks on preset strategy defaults * [DOCS] add a table to summarise the strategies * [DOCS] skip the table for pep8 * [FIX] remove irrelevant stuff added by my IDE * [DOCS]syntax error when referencing the functions * [FIX] simple strategy motion default should be 'full' * [DOC] fix the broken example due to change in default setting and limit of the example dataset * DOCS move strategy description from example to the function docstring * [circle-full] Add descriptions of fmriprep_confounds in the user guide * Apply suggestions from code review Co-authored-by: Gensollen <nicolas.gensollen@gmail.com> Co-authored-by: bthirion <bertrand.thirion@inria.fr> * [circle full] Fix the table formatting * DOCS fix sections in examples * [circle full] Trigger full build Co-authored-by: Pierre Bellec <pierre.bellec@gmail.com> Co-authored-by: bthirion <bertrand.thirion@inria.fr> Co-authored-by: Gensollen <nicolas.gensollen@gmail.com>
Start migrating
load_confounds
to nilearn (#2777) on behalf of all coauthors.Confounds
and all helper functionsConfounds
Few things still needs some discussions and/or changes:
Confounds
into a function?signal.clean
psc standardization.