neurocaps.extraction.TimeseriesExtractor#
- class TimeseriesExtractor(space='MNI152NLin2009cAsym', parcel_approach={'Schaefer': {'n_rois': 400, 'resolution_mm': 1, 'yeo_networks': 7}}, standardize='zscore_sample', detrend=True, low_pass=None, high_pass=None, fwhm=None, use_confounds=True, confound_names='basic', fd_threshold=None, n_acompcor_separate=None, dummy_scans=None, dtype=None)[source]#
Timeseries Extractor Class.
Performs timeseries denoising, extraction, serialization (pickling), and visualization.
- Parameters:
space (
str, default=”MNI152NLin2009cAsym”) – The standard template space that the preprocessed bold data is registered to.parcel_approach (
ParcelConfig,ParcelApproach, orstr, default={“Schaefer”: {“n_rois”: 400, “yeo_networks”: 7, “resolution_mm”: 1}}) – Specifies the parcellation approach to use. Options are “Schaefer”, “AAL”, or “Custom”. Can be initialized with parameters, as a nested dictionary, or loaded from a pickle file. For detailed documentation on the expected structure, see the type definitions forParcelConfigandParcelApproachin the “See Also” section.standardize ({"zscore_sample", "zscore", "psc", True, False}, default="zscore_sample") – Standardizes the timeseries.
detrend (
bool, default=True) – Detrends the timeseries.low_pass (
float,int, orNone, default=None) – Filters out signals above the specified cutoff frequency.high_pass (
float,int, orNone`, default=None) – Filters out signals below the specified cutoff frequency.fwhm (
float,int, orNone, default=None) – Applies spatial smoothing to data (in millimeters).use_confounds (
bool, default=True) –If True, performs nuisance regression during timeseries extraction using the default or user-specified confounds in
confound_names.Important
Requires the confound tsv files to be in same directory as preprocessed BOLD images.
confound_names ({“basic”},
list[str], orNone, default=”basic”) –Names of confounds extracted from the confound tsv files if
use_confounds=True.If “basic”, the following confounds are used by default:
All cosine-basis parameters.
Six head-motion parameters and their first-order derivatives.
First six combined aCompcor components.
Important
Confound names follow fMRIPrep’s naming scheme (versions >= 1.2.0).
Wildcards are supported: e.g., “cosine*” matches all confounds starting with “cosine”.
Changed in version 0.23.0: Changed default from
Noneto"basic". The"basic"option provides the same functionality thatNonedid in previous versions.fd_threshold (
float,dict[str, float | int], orNone, default=None) –Threshold for volume censoring based on framewise displacement (FD).
If float, removes volumes where FD > threshold.
If dict, the following subkeys are available:
”threshold”: A float (Default=None). Removes volumes where FD > threshold.
”outlier_percentage”: A float in interval [0,1] (Default=None). Removes entire runs where proportion of censored volumes exceeds this threshold. Proportion calculated after dummy scan removal.
Note
A warning is issued when a run is flagged.
If
conditionspecified inself.get_bold(), only considers volumes associated with the condition.
”n_before”: An integer (Default=None). Indicates the number of volumes to remove before each flagged volume.
”n_after”: An integer (Default=None). Indicates the number of volumes to remove after each flagged volume.
”use_sample_mask”: A boolean (Default=False). Passes a sample mask to Nilearn’s
NiftiLabelsMasker. Also, setsclean__extrapolate=Falseto prevent interpolation of end volumes. If False, only after nuisance regression.”interpolate”: A boolean (Default=None). If True, uses scipy’s
CubicSplinefunction withextrapolate=Falseto perform cubic spline interpolation on censored frames.Note
Interpolation is only performed on frames that are flanked by non-censored frames on both ends. For example, given a
censor_mask=[0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0]where “0” indicates censored volumes, only the volumes at index 3, 5, 6, and 8 would be interpolated. If False or
Added in version 0.22.3: “interpolate” key added.
Important
A column named “framewise_displacement” must be available in the confounds file.
use_confoundsmust be set to True.Do not specify “framewise_displacement” in
confound_names.See Nilearn’s documentation for details on censored volume handling when “use_sample_mask” is True:
When “use_sample_mask” is False and
standardizeis not False, applying an additional within-run standardization (usingneurocaps.analysis.standardize) is recommended after outlier removal.If “interpolate” is True, then interpolation is only applied nuisance regression and parcellation steps have been completed.
See Scipy’s documentation on their CubicSpline function.
n_acompcor_separate (
intorNone, default=None) –Number of aCompCor components to extract separately from the white-matter (WM) and CSF masks. Uses first “n” components from each mask separately. For instance, if
n_acompcor_separate=5, then the the first 5 WM components and the first 5 CSF components (totaling 10 components) are regressed out.Important
use_confoundsmust be set to True.If specified, this parameter overrides any aCompCor components listed in
confound_names.
dummy_scans (
int,dict[str, bool | int], orNone, default=None) –Number of initial volumes to remove before timeseries extraction.
If int, removes first “n” volumes.
If dict, the following keys are supported:
”auto”: A boolean (Default=None). If True, automatically determines dummy scans from fMRIPrep confounds using the number of “non_steady_state_outlier_XX” columns in the confounds tsv file.
”min”: An integer (Default=None). Minimum volumes to remove when auto is set to True. If “auto” finds 2 outliers but
{"min": 3}, removes 3 volumes.”max”: An integer (Default=None). Maximum volumes to remove when auto=True. If “auto” finds 6 outliers but
{"max": 5}, removes 5 volumes.
Important
”min” and “max” keys only apply when “auto” is True.
dtype (
stror “auto”, default=None) – The NumPy dtype to convert NIfTI images to.
Properties#
- space:
str The standard template space that the preprocessed BOLD data is registered to.
- parcel_approach:
ParcelApproach Parcellation information with “maps” (path to parcellation file), “nodes” (labels), and “regions” (anatomical regions or networks).
- signal_clean_info:
dict[str, bool | int | float | str]orNone Dictionary containing signal cleaning parameters.
- task_info:
dict[str, str | int]orNone Dictionary containing all task-related information such.
- subject_ids:
list[str]orNone A list containing all subject IDs that have retrieved from PyBIDS and subjected to timeseries extraction.
- n_cores:
intorNone Number of cores used for multiprocessing with Joblib.
- subject_timeseries:
SubjectTimeseriesorNone A dictionary mapping subject IDs to their run IDs and their associated timeseries (TRs x ROIs) as a NumPy array.
See also
neurocaps.typing.ParcelConfigType definition representing the configuration options and structure for the Schaefer and AAL parcellations.
neurocaps.typing.ParcelApproachType definition representing the structure of the Schaefer, AAL, and Custom parcellation approaches.
neurocaps.typing.SubjectTimeseriesType definition representing the structure of the subject timeseries.
Note
Passed Parameters:
standardize,detrend,low_pass,high_pass,fwhm, and nuisance regressors (confound_names) usesnilearn.maskers.NiftiLabelsMasker. Thedtypeparameter is used bynilearn.image.load_img.Custom Parcellations: Refer to the NeuroCAPs’ Parcellation Documentation for detailed explanations and example structures for Custom parcellations.
Methods
get_bold(bids_dir, task[, session, runs, ...])Retrieve Preprocessed BOLD Data from BIDS Datasets.
timeseries_to_pickle(output_dir[, filename])Save the Extracted Subject Timeseries.
visualize_bold(subj_id, run[, roi_indx, ...])Plot the Extracted Subject Timeseries.