Ejemplo n.º 1
0
def test_strategy_scrubbing(tmp_path):
    """Check user specified input for scrubbing strategy."""
    file_nii, _ = create_tmp_filepath(tmp_path,
                                      image_type="regular",
                                      copy_confounds=True,
                                      copy_json=True)
    confounds, sample_mask = load_confounds_strategy(
        file_nii, denoise_strategy="scrubbing", fd_threshold=0.15)
    # out of 30 vols, should have 6 motion outliers from scrubbing,
    # and 2 vol removed by srubbing strategy "full"
    assert len(sample_mask) == 22
    # shape of confound regressors untouched
    assert confounds.shape[0] == 30
    # also load confounds with very liberal scrubbing thresholds
    # this should not produce an error
    confounds, sample_mask = load_confounds_strategy(
        file_nii,
        denoise_strategy="scrubbing",
        fd_threshold=1,
        std_dvars_threshold=5)
    assert len(sample_mask) == 29  # only non-steady volumes removed

    # maker sure global signal works
    confounds, sample_mask = load_confounds_strategy(
        file_nii, denoise_strategy="scrubbing", global_signal="full")
    for check in [
            "global_signal",
            "global_signal_derivative1",
            "global_signal_power2",
            "global_signal_derivative1_power2",
    ]:
        assert check in confounds.columns
Ejemplo n.º 2
0
def test_irrelevant_input(tmp_path):
    """Check invalid input raising correct warning or error message."""
    file_nii, _ = create_tmp_filepath(tmp_path,
                                      image_type="regular",
                                      copy_confounds=True,
                                      copy_json=True)
    warning_message = (r"parameters accepted: \['motion', 'wm_csf', "
                       "'global_signal', 'demean']")
    with pytest.warns(UserWarning, match=warning_message):
        load_confounds_strategy(file_nii,
                                denoise_strategy="simple",
                                ica_aroma="full")
    # invalid strategy
    with pytest.raises(KeyError, match="blah"):
        load_confounds_strategy(file_nii, denoise_strategy="blah")
Ejemplo n.º 3
0
def test_load_confounds_strategy(tmp_path, denoise_strategy, image_type):
    """Smoke test with no extra inputs."""
    file_nii, _ = create_tmp_filepath(tmp_path,
                                      image_type=image_type,
                                      copy_confounds=True,
                                      copy_json=True)
    confounds, _ = load_confounds_strategy(file_nii,
                                           denoise_strategy=denoise_strategy)
    assert isinstance(confounds, pd.DataFrame)
Ejemplo n.º 4
0
def test_strategy_compcor(tmp_path):
    """Check user specified input for compcor strategy."""
    file_nii, _ = create_tmp_filepath(tmp_path,
                                      image_type="regular",
                                      copy_confounds=True,
                                      copy_json=True)
    confounds, _ = load_confounds_strategy(file_nii,
                                           denoise_strategy="compcor")
    compcor_col_str_anat = "".join(confounds.columns)
    assert "t_comp_cor_" not in compcor_col_str_anat
    assert ("a_comp_cor_57" not in compcor_col_str_anat
            )  # this one comes from the white matter mask
Ejemplo n.º 5
0
def test_strategies(tmp_path, denoise_strategy, image_type):
    """Check defaults setting of each preset strategy."""
    file_nii, _ = create_tmp_filepath(tmp_path,
                                      image_type=image_type,
                                      copy_confounds=True,
                                      copy_json=True)
    confounds, _ = load_confounds_strategy(file_nii,
                                           denoise_strategy=denoise_strategy)
    # Check that all fixed name model categories have been successfully loaded
    list_check = _get_headers(denoise_strategy)
    for col in confounds.columns:
        # Check that all possible names exists
        checker = [
            re.match(keyword, col) is not None for keyword in list_check
        ]
        assert sum(checker) == 1
Ejemplo n.º 6
0
# Using predefined strategies
# ---------------------------
# Instead of customising the strategy through
# :func:`nilearn.interfaces.fmriprep.load_confounds`, one can use a predefined
# strategy with :func:`nilearn.interfaces.fmriprep.load_confounds_strategy`.
# Based on the confound variables generated through :term:`fMRIPrep`, and past
# benchmarks studies (:footcite:`Ciric2017`, :footcite:`Parker2018`): `simple`,
# `scrubbing`, `compcor`, `ica_aroma`.
# The following examples shows how to use the `simple` strategy and overwrite
# the motion default to basic.

from nilearn.interfaces.fmriprep import load_confounds_strategy

# use default parameters
confounds, sample_mask = load_confounds_strategy(fmri_filenames,
                                                 denoise_strategy="simple",
                                                 motion="basic")
time_series = masker.fit_transform(fmri_filenames,
                                   confounds=confounds,
                                   sample_mask=sample_mask)

correlation_matrix = correlation_measure.fit_transform([time_series])[0]

np.fill_diagonal(correlation_matrix, 0)

plotting.plot_matrix(correlation_matrix,
                     figure=(10, 8),
                     labels=labels[1:],
                     vmax=0.8,
                     vmin=-0.8,
                     title='simple',