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

[NF] migrate package load_confounds main function load_confounds #2946

Merged
merged 74 commits into from Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
7e6b887
[NF] migrate load_confounds base class
htwangtw Sep 7, 2021
7ccf22e
LINT PEP8
htwangtw Sep 7, 2021
63ea3a5
LINT force PEP8 to skip long URL
htwangtw Sep 7, 2021
cafb0da
LINT more PEP8
htwangtw Sep 7, 2021
82844fd
DOCS supported fMRIprep version specified
htwangtw Sep 7, 2021
775e188
ADD modified load_confounds demo
htwangtw Sep 7, 2021
20ea698
Apply suggestions from code review
htwangtw Sep 8, 2021
d3239ff
DOCS/FIX update load_confounds in docs and demo
htwangtw Sep 8, 2021
24d1db6
EHN more readable parameter names and migrate functions
htwangtw Sep 8, 2021
e199f40
TEST/DOC Test for scrubbing/sample mask
htwangtw Sep 8, 2021
a3a62d9
Apply suggestions from code review
htwangtw Sep 9, 2021
b57d1b0
Apply suggestions from code review
htwangtw Sep 9, 2021
0b14f32
DOCS improve formatting according to pydocstyle
htwangtw Sep 9, 2021
66ca69b
ENH simplify coompcor options
htwangtw Sep 9, 2021
7a300f8
[circle full] and some flake8 issues
htwangtw Sep 9, 2021
c1dac14
Typo
htwangtw Sep 9, 2021
df7ee6a
[circile full] FIX Title underline too short
htwangtw Sep 9, 2021
8d09b06
[circle full] ADD fmriprep dependency warning
htwangtw Sep 9, 2021
3a3447a
Proposal: DRY tests
NicolasGensollen Sep 10, 2021
c25e5f8
PEP8
htwangtw Sep 10, 2021
d165dd6
TEST Replace empty image file with temporary func
htwangtw Sep 10, 2021
92f1bc3
TEST add docstrings
htwangtw Sep 10, 2021
a23606f
TEST clean up path not replaced by tmp path
htwangtw Sep 11, 2021
50558a7
pep8
htwangtw Sep 11, 2021
f161aa6
ENH/TEST Remove PCA motion regressor option
htwangtw Sep 13, 2021
59ac369
Remove irrelevant comment
htwangtw Sep 13, 2021
03f3f54
[circle full] Update the demo with meaningful name
htwangtw Sep 13, 2021
29c5ba2
[circle full] pep8
htwangtw Sep 13, 2021
7380052
EHN update sample_mask application in maskers
htwangtw Sep 13, 2021
3fcffca
[circle full] RF load_confounds function replaces class Confounds
htwangtw Sep 14, 2021
4cb9070
[circle full] PEP8
htwangtw Sep 14, 2021
d3f0afd
[circle full] PEP8
htwangtw Sep 14, 2021
ab6e9c5
[circle full] DOCS/EHN correct module template and a few formatting d…
htwangtw Sep 14, 2021
e81394b
[circle full] ENH explicitly write the function inputs
htwangtw Sep 15, 2021
f8de52e
ENH migrate load_confounds to input_data
htwangtw Sep 16, 2021
77b3f55
DOCS update descriptions for user guilde
htwangtw Sep 16, 2021
4977716
Typos
htwangtw Sep 16, 2021
05e4049
PEP8
htwangtw Sep 16, 2021
f04de9a
[circle full]DOCS update function reference
htwangtw Sep 16, 2021
39f6432
[circle full] fix function reference in API ref
htwangtw Sep 16, 2021
2b2000e
DOCS remove non existance reference
htwangtw Sep 16, 2021
d51dc26
typo
htwangtw Sep 16, 2021
d59322a
rename the modules to relect the link with fmriprep
htwangtw Sep 16, 2021
fc48651
TEST change how simulated signal is generated
htwangtw Sep 16, 2021
8d1e6f2
Apply suggestions from code review
htwangtw Sep 17, 2021
41764b1
Apply suggestions from code review
htwangtw Sep 17, 2021
c36fb7f
Address some small comments on docs and format
htwangtw Sep 17, 2021
f1fe8d6
DOCS use BibTex for literatures
htwangtw Sep 17, 2021
23ae062
DOCS missing field journal
htwangtw Sep 17, 2021
7a95338
DOCS date --> year
htwangtw Sep 17, 2021
25bf9f5
DOCS Update example text
htwangtw Sep 17, 2021
1ab365b
TEST confounds extended in the same manner of test data
htwangtw Sep 17, 2021
94f8c43
BREAK test_nilearn_standardize broke by demean=False
htwangtw Sep 21, 2021
c040b2f
ENH/TEST demean option doc
htwangtw Sep 23, 2021
ba32963
Typos
htwangtw Sep 23, 2021
5321364
TEST FIX the missing parameter
htwangtw Sep 23, 2021
3392e30
Apply suggestions from code review
htwangtw Sep 24, 2021
93ac7b1
ENH demean default change back to True
htwangtw Sep 24, 2021
96c0717
LINT example
htwangtw Sep 24, 2021
1f5d9ea
TEST increase the degree of freedom in simulation
htwangtw Sep 24, 2021
0b463b3
TEST the option for standardize_confounds,detrend
htwangtw Sep 24, 2021
0347bfe
TEST remove standardize=False from test_nilearn_standardize
htwangtw Sep 27, 2021
bfec196
Update nilearn/input_data/fmriprep_confounds.py
htwangtw Sep 28, 2021
8787d97
TEST increase DoF and add randome seed to improve stability
htwangtw Sep 28, 2021
939ac4b
[circle full] Add what's new entry
htwangtw Sep 28, 2021
bbdf73f
[circle full] typo
htwangtw Sep 28, 2021
edb77f3
[circle full] fall back to random seed in test for version <3.7
htwangtw Sep 28, 2021
a8727bd
[circle full] typo in reference to NifitMasker
htwangtw Sep 28, 2021
764de48
[circle full] Update nilearn/input_data/fmriprep_confounds.py
htwangtw Sep 29, 2021
c1c8454
Apply suggestions from code review
htwangtw Oct 11, 2021
6c86349
[circle full] [ENH] expose full scrubbing segment length
htwangtw Oct 11, 2021
c24b0c9
[circle full] fix example to fit the new srub parameter
htwangtw Oct 11, 2021
461fae8
[circle full] default value is not useful in private function
htwangtw Oct 11, 2021
6ff1f1b
[circle full] fix scrubbing related tests; add doctring
htwangtw Oct 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/03_connectivity/plot_signal_extraction.py
Expand Up @@ -79,7 +79,7 @@

##############################################################################
# Extract signals and compute a connectivity matrix without confounds removal
# -------------------------------------------------------------------
# ---------------------------------------------------------------------------
# After covering the basic of signal extraction and functional connectivity
# matrix presentation, let's look into the impact of confounds to :term:`fMRI`
# signal and functional connectivity. Firstly let's find out what a functional
Expand Down
4 changes: 2 additions & 2 deletions nilearn/_utils/fmriprep_confounds.py
@@ -1,6 +1,6 @@
""" Misc utilities for the library.
""" Misc utilities for function nilearn.input_data.fmriprep_confounds.

Authors: load_confounds team
Author: Hao-Ting Wang
"""


Expand Down
22 changes: 10 additions & 12 deletions nilearn/input_data/fmriprep_confounds.py
@@ -1,6 +1,7 @@
"""Flexible method to load confounds generated by fMRIprep.

Authors: load_confounds team
Authors: Pierre Bellec, François Paugam, Hanad Sharmarke, Hao-Ting Wang,
Michael W. Weiss, Steven Meisler, Thibault Piront.
"""
import pandas as pd
from .fmriprep_confounds_utils import (_sanitize_confounds, _confounds_to_df,
Expand Down Expand Up @@ -62,7 +63,7 @@ def _check_error(missing):
def fmriprep_confounds(img_files,
strategy=["motion", "high_pass", "wm_csf"],
motion="full",
scrub="full", fd_thresh=0.2, std_dvars_thresh=3,
scrub=5, fd_thresh=0.2, std_dvars_thresh=3,
wm_csf="basic",
global_signal="basic",
compcor="anat_combined", n_compcor="all",
Expand Down Expand Up @@ -149,16 +150,13 @@ def fmriprep_confounds(img_files,
- "full" global signal + derivatives + quadratic terms + power2d
derivatives (4 parameters)

scrub : {'full', 'basic'}
Type of scrub of frames with excessive motion :footcite:`Power2014`

- "basic" remove time frames based on excessive framewise displacement
and DVARS.
- "full" also remove continuous segments containing fewer than 5
volumes.

One-hot encoding vectors are added as regressors for each scrubbed
frame.
scrub : int, default 5
After accounting for time frames with excessive motion, further remove
segments shorter than the given number. The default value is 5
(referred as full scrubbing in :footcite:`Power2014`). When the value
is 0, temove time frames based on excessive framewise displacement and
DVARS only. One-hot encoding vectors are added as regressors for each
scrubbed frame.

compcor : {'anat_combined', 'anat_separated', 'temporal',\
'temporal_anat_combined', 'temporal_anat_separated'}
Expand Down
8 changes: 5 additions & 3 deletions nilearn/input_data/fmriprep_confounds_components.py
Expand Up @@ -75,9 +75,11 @@ def _load_scrub(confounds_raw, scrub, fd_thresh, std_dvars_thresh):
motion_outliers_index = np.sort(
np.unique(np.concatenate((fd_outliers_index, dvars_outliers_index)))
)
# Do full scrubbing if desired, and motion outliers were detected
if scrub == "full" and len(motion_outliers_index) > 0:
motion_outliers_index = _optimize_scrub(motion_outliers_index, n_scans)
# when motion outliers were detected, remove segments with too few
# timeframes if desired
if scrub > 0 and len(motion_outliers_index) > 0:
motion_outliers_index = _optimize_scrub(motion_outliers_index, n_scans,
scrub)
# Make one-hot encoded motion outlier regressors
motion_outlier_regressors = pd.DataFrame(
np.transpose(np.eye(n_scans)[motion_outliers_index]).astype(int)
Expand Down
14 changes: 7 additions & 7 deletions nilearn/input_data/fmriprep_confounds_scrub.py
Expand Up @@ -3,25 +3,25 @@
import pandas as pd


def _optimize_scrub(motion_outliers_index, n_scans):
"""Remove continuous segments containing fewer than 5 volumes."""
def _optimize_scrub(motion_outliers_index, n_scans, scrub=5):
NicolasGensollen marked this conversation as resolved.
Show resolved Hide resolved
"""Remove continuous segments with fewer than a minimal segment length."""
# Start by checking if the beginning continuous segment is fewer than
# 5 volumes
if motion_outliers_index[0] < 5:
# a minimal segment length (default to 5)
if motion_outliers_index[0] < scrub:
motion_outliers_index = np.asarray(
list(range(motion_outliers_index[0])) + list(motion_outliers_index)
)
# Do the same for the ending segment of scans
if n_scans - (motion_outliers_index[-1] + 1) < 5:
if n_scans - (motion_outliers_index[-1] + 1) < scrub:
motion_outliers_index = np.asarray(
list(motion_outliers_index)
+ list(range(motion_outliers_index[-1], n_scans))
)
# Now do everything in between
fd_outlier_ind_diffs = np.diff(motion_outliers_index)
short_segments_inds = np.where(
np.logical_and(fd_outlier_ind_diffs > 1, fd_outlier_ind_diffs < 6)
)[0]
np.logical_and(fd_outlier_ind_diffs > 1,
fd_outlier_ind_diffs < (scrub + 1)))[0]
for ind in short_segments_inds:
motion_outliers_index = np.asarray(
list(motion_outliers_index)
Expand Down
5 changes: 1 addition & 4 deletions nilearn/input_data/fmriprep_confounds_utils.py
@@ -1,7 +1,4 @@
"""Helper functions for the manipulation of fmriprep output confounds.

Authors: load_confounds team
"""
"""Helper functions for the manipulation of fmriprep output confounds."""
import numpy as np
import pandas as pd
from sklearn.preprocessing import scale
Expand Down
7 changes: 4 additions & 3 deletions nilearn/input_data/tests/test_fmriprep_confounds.py
Expand Up @@ -483,11 +483,12 @@ def test_sample_mask(tmp_path):
)

reg, mask = fmriprep_confounds(
regular_nii, strategy=["motion", "scrub"], scrub="full", fd_thresh=0.15
regular_nii, strategy=["motion", "scrub"], scrub=5, fd_thresh=0.15
)
# the current test data has 6 time points marked as motion outliers,
# and one nonsteady state (overlap with the first motion outlier)
# 2 time points removed due to the "full" srubbing strategy
# 2 time points removed due to the "full" srubbing strategy (remove segment
# shorter than 5 volumes)
assert reg.shape[0] - len(mask) == 8
# nilearn requires unmasked confound regressors
assert reg.shape[0] == 30
Expand All @@ -504,7 +505,7 @@ def test_sample_mask(tmp_path):

# When no volumes needs removing (very liberal motion threshould)
reg, mask = fmriprep_confounds(
regular_nii, strategy=["motion", "scrub"], scrub="basic", fd_thresh=4
regular_nii, strategy=["motion", "scrub"], scrub=0, fd_thresh=4
)
assert mask is None

Expand Down