Note

This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the user guide for the big picture.

nilearn.maskers.BaseMasker

class nilearn.maskers.BaseMasker[source]

Base class for NiftiMaskers.

fit(imgs=None, y=None)[source]

Present only to comply with sklearn estimators checks.

fit_transform(imgs, y=None, confounds=None, sample_mask=None, **fit_params)[source]

Fit to data, then transform it.

Parameters:
imgsNiimg-like object

See Input and output: neuroimaging data representation.

ynumpy array of shape [n_samples], default=None

Target values.

confoundsnumpy.ndarray, str, pathlib.Path, pandas.DataFrame or list of confounds timeseries, default=None

This parameter is passed to nilearn.signal.clean. Please see the related documentation for details. shape: (number of scans, number of confounds)

sample_maskAny type compatible with numpy-array indexing, default=None

shape = (total number of scans - number of scans removed) for explicit index (for example, sample_mask=np.asarray([1, 2, 4])), or shape = (number of scans) for binary mask (for example, sample_mask=np.asarray([False, True, True, False, True])). Masks the images along the last dimension to perform scrubbing: for example to remove volumes with high motion and/or non-steady-state volumes. This parameter is passed to nilearn.signal.clean.

Added in version 0.8.0.

Returns:
signalsnumpy.ndarray

Signal for each voxel. Output shape for :

  • 3D images: (number of elements,) array

  • 4D images: (number of scans, number of elements) array

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

inverse_transform(X)[source]

Transform the data matrix back to an image in brain space.

This step only performs spatial unmasking, without inverting any additional processing performed by transform, such as temporal filtering or smoothing.

Parameters:
signals1D/2D numpy.ndarray

Extracted signal. If a 1D array is provided, then the shape should be (number of elements,). If a 2D array is provided, then the shape should be (number of scans, number of elements).

Returns:
imgnibabel.nifti1.Nifti1Image

Transformed image in brain space. Output shape for :

See Input and output: neuroimaging data representation.

set_fit_request(*, imgs='$UNCHANGED$')

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
imgsstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for imgs parameter in fit.

Returns:
selfobject

The updated object.

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.

set_transform_request(*, confounds='$UNCHANGED$', imgs='$UNCHANGED$', sample_mask='$UNCHANGED$')

Request metadata passed to the transform method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
confoundsstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for confounds parameter in transform.

imgsstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for imgs parameter in transform.

sample_maskstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_mask parameter in transform.

Returns:
selfobject

The updated object.

transform(imgs, confounds=None, sample_mask=None)[source]

Apply mask, spatial and temporal preprocessing.

Parameters:
imgs3D/4D Niimg-like object

See Input and output: neuroimaging data representation. Images to process. If a 3D niimg is provided, a 1D array is returned.

confoundsnumpy.ndarray, str, pathlib.Path, pandas.DataFrame or list of confounds timeseries, default=None

This parameter is passed to nilearn.signal.clean. Please see the related documentation for details. shape: (number of scans, number of confounds)

sample_maskAny type compatible with numpy-array indexing, default=None

shape = (total number of scans - number of scans removed) for explicit index (for example, sample_mask=np.asarray([1, 2, 4])), or shape = (number of scans) for binary mask (for example, sample_mask=np.asarray([False, True, True, False, True])). Masks the images along the last dimension to perform scrubbing: for example to remove volumes with high motion and/or non-steady-state volumes. This parameter is passed to nilearn.signal.clean.

Added in version 0.8.0.

Returns:
signalsnumpy.ndarray

Signal for each voxel. Output shape for :

  • 3D images: (number of elements,) array

  • 4D images: (number of scans, number of elements) array

abstract transform_single_imgs(imgs, confounds=None, sample_mask=None, copy=True)[source]

Extract signals from a single niimg.

Parameters:
imgs3D/4D Niimg-like object

See Input and output: neuroimaging data representation. Images to process.

confoundsnumpy.ndarray, str, pathlib.Path, pandas.DataFrame or list of confounds timeseries, default=None

This parameter is passed to nilearn.signal.clean. Please see the related documentation for details. shape: (number of scans, number of confounds)

sample_maskAny type compatible with numpy-array indexing, default=None

shape = (total number of scans - number of scans removed) for explicit index (for example, sample_mask=np.asarray([1, 2, 4])), or shape = (number of scans) for binary mask (for example, sample_mask=np.asarray([False, True, True, False, True])). Masks the images along the last dimension to perform scrubbing: for example to remove volumes with high motion and/or non-steady-state volumes. This parameter is passed to nilearn.signal.clean.

Added in version 0.8.0.

copybool, default=True

Indicates whether a copy is returned or not.

Returns:
signalsnumpy.ndarray

Signal for each voxel. Output shape for :

  • 3D images: (number of elements,) array

  • 4D images: (number of scans, number of elements) array

Examples using nilearn.maskers.BaseMasker

Encoding models for visual stimuli from Miyawaki et al. 2008

Encoding models for visual stimuli from Miyawaki et al. 2008

ROI-based decoding analysis in Haxby et al. dataset

ROI-based decoding analysis in Haxby et al. dataset

Reconstruction of visual stimuli from Miyawaki et al. 2008

Reconstruction of visual stimuli from Miyawaki et al. 2008

Searchlight analysis of face vs house recognition

Searchlight analysis of face vs house recognition

The haxby dataset: different multi-class strategies

The haxby dataset: different multi-class strategies

Understanding Decoder

Understanding Decoder

Voxel-Based Morphometry on Oasis dataset

Voxel-Based Morphometry on Oasis dataset

Classification of age groups using functional connectivity

Classification of age groups using functional connectivity

Comparing connectomes on different reference atlases

Comparing connectomes on different reference atlases

Computing a connectome with sparse inverse covariance

Computing a connectome with sparse inverse covariance

Extract signals on spheres and plot a connectome

Extract signals on spheres and plot a connectome

Extracting signals from a brain parcellation

Extracting signals from a brain parcellation

Extracting signals of a probabilistic atlas of functional regions

Extracting signals of a probabilistic atlas of functional regions

Group Sparse inverse covariance for multi-subject connectome

Group Sparse inverse covariance for multi-subject connectome

Producing single subject maps of seed-to-voxel correlation

Producing single subject maps of seed-to-voxel correlation

Regions extraction using dictionary learning and functional connectomes

Regions extraction using dictionary learning and functional connectomes

Default Mode Network extraction of ADHD dataset

Default Mode Network extraction of ADHD dataset

Predicted time series and residuals

Predicted time series and residuals

Computing a Region of Interest (ROI) mask manually

Computing a Region of Interest (ROI) mask manually

Extracting signals from brain regions using the NiftiLabelsMasker

Extracting signals from brain regions using the NiftiLabelsMasker

Regions Extraction of Default Mode Networks using Smith Atlas

Regions Extraction of Default Mode Networks using Smith Atlas

Simple example of NiftiMasker use

Simple example of NiftiMasker use

Understanding NiftiMasker and mask computation

Understanding NiftiMasker and mask computation

Advanced decoding using scikit learn

Advanced decoding using scikit learn

Beta-Series Modeling for Task-Based Functional Connectivity and Decoding

Beta-Series Modeling for Task-Based Functional Connectivity and Decoding

Functional connectivity predicts age group

Functional connectivity predicts age group

Massively univariate analysis of a calculation task from the Localizer dataset

Massively univariate analysis of a calculation task from the Localizer dataset

Massively univariate analysis of a motor task from the Localizer dataset

Massively univariate analysis of a motor task from the Localizer dataset

Massively univariate analysis of face vs house recognition

Massively univariate analysis of face vs house recognition

Multivariate decompositions: Independent component analysis of fMRI

Multivariate decompositions: Independent component analysis of fMRI

NeuroVault cross-study ICA maps

NeuroVault cross-study ICA maps

Working with long time series fMRI images

Working with long time series fMRI images