Skip to content
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 scrubbing support in fMRIPrepConfoundRemover #421

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

synchon
Copy link
Member

@synchon synchon commented Jan 23, 2025

  • description of feature/fix
  • tests added/passed
  • add an entry for the latest changes

This PR adds scrubbing support in fMRIPrepConfoundRemover by using std_dvars from fMRIPrep output.

@synchon synchon added preprocess Issues or pull requests related to preprocessors enhancement New feature or request labels Jan 23, 2025
@synchon synchon added this to the 0.0.6 (alpha 5) milestone Jan 23, 2025
@synchon synchon requested a review from fraimondo January 23, 2025 18:33
Copy link

codecov bot commented Jan 23, 2025

Codecov Report

Attention: Patch coverage is 33.33333% with 8 lines in your changes missing coverage. Please review.

Project coverage is 85.44%. Comparing base (edaa261) to head (563fd39).

Files with missing lines Patch % Lines
.../preprocess/confounds/fmriprep_confound_remover.py 33.33% 6 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #421      +/-   ##
==========================================
- Coverage   85.55%   85.44%   -0.11%     
==========================================
  Files         133      133              
  Lines        5795     5807      +12     
  Branches      982      985       +3     
==========================================
+ Hits         4958     4962       +4     
- Misses        636      642       +6     
- Partials      201      203       +2     
Flag Coverage Δ
junifer 85.44% <33.33%> (-0.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
.../preprocess/confounds/fmriprep_confound_remover.py 94.91% <33.33%> (-4.48%) ⬇️

@synchon synchon force-pushed the feat/fmriprepconfoundremover-dvars-scrub branch 2 times, most recently from 15bab84 to 1332737 Compare January 24, 2025 16:31
Copy link

github-actions bot commented Jan 24, 2025

PR Preview Action v1.6.0

🚀 View preview at
https://juaml.github.io/junifer/pr-preview/pr-421/

Built to branch gh-pages at 2025-01-29 11:06 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@synchon synchon requested a review from fraimondo January 24, 2025 17:15
@fraimondo
Copy link
Contributor

Two comments:

  1. Why using DVARS? where did you get the reference for this method? I've seen scrubbing also using the FD
  2. As it is, it nows also adds DVARS as a regressor.

I think the implementation should come from nilearn: https://nilearn.github.io/stable/modules/generated/nilearn.interfaces.fmriprep.load_confounds.html#nilearn.interfaces.fmriprep.load_confounds

Basically here you can set the fd_threshold and std_dvars_threshold and it will give you the sample_mask

@synchon synchon force-pushed the feat/fmriprepconfoundremover-dvars-scrub branch from 2080792 to e392c7b Compare January 27, 2025 10:10
@synchon
Copy link
Member Author

synchon commented Jan 27, 2025

Two comments:

  1. Why using DVARS? where did you get the reference for this method? I've seen scrubbing also using the FD

nilearn.image.load_confounds has a parameter std_dvars_threshold for scrubbing, so I went for it as well. We support FD via the spike parameter of fMRIPrepConfoundRemover.

  1. As it is, it nows also adds DVARS as a regressor.

It generates a mask for indexing the time dimension and passes it to nilearn.image.clean as you suggested in your previous comment.

I think the implementation should come from nilearn: https://nilearn.github.io/stable/modules/generated/nilearn.interfaces.fmriprep.load_confounds.html#nilearn.interfaces.fmriprep.load_confounds

Basically here you can set the fd_threshold and std_dvars_threshold and it will give you the sample_mask

We don't use load_confounds but select the confounds we want to remove and pass it to nilearn.image.clean_img. Also, load_confounds relies on the confound file by following the path from the image file. Is that something we go for?

@fraimondo
Copy link
Contributor

Two comments:

  1. Why using DVARS? where did you get the reference for this method? I've seen scrubbing also using the FD

nilearn.image.load_confounds has a parameter std_dvars_threshold for scrubbing, so I went for it as well. We support FD via the spike parameter of fMRIPrepConfoundRemover.

spike is to add as a regressor, which is not scrubbing:

  1. As it is, it nows also adds DVARS as a regressor.

It generates a mask for indexing the time dimension and passes it to nilearn.image.clean as you suggested in your previous comment.

I see that you use input["confounds"] for the scrub mask and not confounds_df. We are good as long as dvars or any confounds used for the scrubbing appear in the confounds of clean_img

I think the implementation should come from nilearn: https://nilearn.github.io/stable/modules/generated/nilearn.interfaces.fmriprep.load_confounds.html#nilearn.interfaces.fmriprep.load_confounds
Basically here you can set the fd_threshold and std_dvars_threshold and it will give you the sample_mask

We don't use load_confounds but select the confounds we want to remove and pass it to nilearn.image.clean_img. Also, load_confounds relies on the confound file by following the path from the image file. Is that something we go for?

We need to somehow "mimic" that behaviour. That's what I meant. The scrubbing mask can be either from dvars or fd.

@synchon
Copy link
Member Author

synchon commented Jan 29, 2025

I see that you use input["confounds"] for the scrub mask and not confounds_df. We are good as long as dvars or any confounds used for the scrubbing appear in the confounds of clean_img

Do the new commits address it?

@synchon synchon force-pushed the feat/fmriprepconfoundremover-dvars-scrub branch from 54d8c96 to 563fd39 Compare January 29, 2025 09:48
@fraimondo
Copy link
Contributor

I see that you use input["confounds"] for the scrub mask and not confounds_df. We are good as long as dvars or any confounds used for the scrubbing appear in the confounds of clean_img

Do the new commits address it?

We are still missing the fd_threshold and the scrub parameter. Also check the reference for scrubbing: https://www.sciencedirect.com/science/article/abs/pii/S1053811913009117?via%3Dihub

Coverage is low, meaning that we are missing tests.

@synchon
Copy link
Member Author

synchon commented Jan 30, 2025

We are still missing the fd_threshold and the scrub parameter.

Just so that it's explicit:

  • Does fMRIPrepConfoundRemover's strategy take a key named scrub or does one pass it via the parameters?
  • From load_confounds docs: “scrub” regressors for Power et al.[[3]](https://nilearn.github.io/stable/modules/generated/nilearn.interfaces.fmriprep.load_confounds.html#footcite-power2014) scrubbing approach. Associated parameter: scrub, fd_threshold, std_dvars_threshold. It treats them as "regressors" and when you pass "scrub" in the strategy, it does not return either framewise_displacement or std_dvars in the returned confounds dataframe.

We are good as long as dvars or any confounds used for the scrubbing appear in the confounds of clean_img

I thought the columns should be in the returned dataframe?

  • If you are ok with how the std_dvars_threshold is currently implemented for fMRIPrepConfoundRemover, I can add fd_threshold as well. I'm not sure how scrub is supposed to be implemented?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request preprocess Issues or pull requests related to preprocessors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants