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.MultiNiftiMapsMasker

class nilearn.maskers.MultiNiftiMapsMasker(maps_img, mask_img=None, allow_overlap=True, smoothing_fwhm=None, standardize=False, standardize_confounds=True, high_variance_confounds=False, detrend=False, low_pass=None, high_pass=None, t_r=None, dtype=None, resampling_target='data', memory=None, memory_level=0, verbose=0, reports=True, n_jobs=1, **kwargs)[source]

Class for extracting data from multiple Niimg-like objects using maps of potentially overlapping brain regions.

MultiNiftiMapsMasker is useful when data from overlapping volumes and from different subjects should be extracted (contrary to nilearn.maskers.NiftiMapsMasker).

Use case: summarize brain signals from several subjects from large-scale networks obtained by prior PCA or ICA.

Note

Inf or NaN present in the given input images are automatically put to zero rather than considered as missing data.

For more details on the definitions of maps in Nilearn, see the Extraction of signals from regions: NiftiLabelsMasker, NiftiMapsMasker section.

Parameters:
maps_img4D niimg-like object

See Input and output: neuroimaging data representation. Set of continuous maps. One representative time course per map is extracted using least square regression.

mask_img3D niimg-like object, optional

See Input and output: neuroimaging data representation. Mask to apply to regions before extracting signals.

allow_overlapbool, default=True

If False, an error is raised if the maps overlaps (ie at least two maps have a non-zero value for the same voxel).

smoothing_fwhmfloat, optional.

If smoothing_fwhm is not None, it gives the full-width at half maximum in millimeters of the spatial smoothing to apply to the signal.

standardize{‘zscore_sample’, ‘zscore’, ‘psc’, True, False}, default=False

Strategy to standardize the signal:

  • 'zscore_sample': The signal is z-scored. Timeseries are shifted to zero mean and scaled to unit variance. Uses sample std.

  • 'zscore': The signal is z-scored. Timeseries are shifted to zero mean and scaled to unit variance. Uses population std by calling default numpy.std with N - ddof=0.

  • 'psc': Timeseries are shifted to zero mean value and scaled to percent signal change (as compared to original mean signal).

  • True: The signal is z-scored (same as option zscore). Timeseries are shifted to zero mean and scaled to unit variance.

  • False: Do not standardize the data.

standardize_confoundsbool, default=True

If set to True, the confounds are z-scored: their mean is put to 0 and their variance to 1 in the time dimension.

high_variance_confoundsbool, default=False

If True, high variance confounds are computed on provided image with nilearn.image.high_variance_confounds and default parameters and regressed out.

detrendbool, optional

Whether to detrend signals or not.

low_passfloat or None, default=None

Low cutoff frequency in Hertz. If specified, signals above this frequency will be filtered out. If None, no low-pass filtering will be performed.

high_passfloat, default=None

High cutoff frequency in Hertz. If specified, signals below this frequency will be filtered out.

t_rfloat or None, default=None

Repetition time, in seconds (sampling period). Set to None if not provided.

dtype{dtype, “auto”}, optional

Data type toward which the data should be converted. If “auto”, the data will be converted to int32 if dtype is discrete and float32 if it is continuous.

resampling_target{“data”, “mask”, “maps”, None}, default=”data”

Gives which image gives the final shape/size:

  • “data” means the atlas is resampled to the shape of the data if needed

  • “mask” means the maps_img and images provided to fit() are resampled to the shape and affine of mask_img

  • “maps” means the mask_img and images provided to fit() are resampled to the shape and affine of maps_img

  • None means no resampling: if shapes and affines do not match, a ValueError is raised.

memoryNone, instance of joblib.Memory, str, or pathlib.Path

Used to cache the masking process. By default, no caching is done. If a str is given, it is the path to the caching directory.

memory_levelint, default=0

Rough estimator of the amount of memory used by caching. Higher value means more memory for caching. Zero means no caching.

n_jobsint, default=1

The number of CPUs to use to do the computation. -1 means ‘all CPUs’.

verboseint, default=0

Verbosity level (0 means no message).

reportsbool, default=True

If set to True, data is saved in order to produce a report.

kwargsdict

Keyword arguments to be passed to functions called within the masker. Kwargs prefixed with ‘clean__’ will be passed to clean. Within clean, kwargs prefixed with ‘butterworth__’ will be passed to the Butterworth filter (i.e., clean__butterworth__).

Attributes:
maps_img_nibabel.nifti1.Nifti1Image

The maps mask of the data.

n_elements_int

The number of overlapping maps in the mask. This is equivalent to the number of volumes in the mask image.

Added in version 0.9.2.

Notes

If resampling_target is set to “maps”, every 3D image processed by transform() will be resampled to the shape of maps_img. It may lead to a very large memory consumption if the voxel number in maps_img is large.

__init__(maps_img, mask_img=None, allow_overlap=True, smoothing_fwhm=None, standardize=False, standardize_confounds=True, high_variance_confounds=False, detrend=False, low_pass=None, high_pass=None, t_r=None, dtype=None, resampling_target='data', memory=None, memory_level=0, verbose=0, reports=True, n_jobs=1, **kwargs)[source]
transform_imgs(imgs_list, confounds=None, n_jobs=1, sample_mask=None)[source]

Extract signals from a list of 4D niimgs.

Parameters:
imgslist of Niimg-like objects

See Input and output: neuroimaging data representation. Images to process. Each element of the list is a 4D image.

confoundsCSV file or array-like, optional

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

sample_maskAny type compatible with numpy-array indexing, optional

shape: (number of scans - number of volumes removed, ) Masks the niimgs along time/fourth dimension to perform scrubbing (remove volumes with high motion) and/or non-steady-state volumes. This parameter is passed to nilearn.signal.clean.

Returns:
region_signalslist of 2D numpy.ndarray

List of signals for each map per subject. shape: list of (number of scans, number of maps)

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

Apply mask, spatial and temporal preprocessing.

Parameters:
imgslist of Niimg-like objects

See Input and output: neuroimaging data representation. Images to process. Each element of the list is a 4D image.

confoundsCSV file or array-like, optional

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

sample_maskAny type compatible with numpy-array indexing, optional

shape: (number of scans - number of volumes removed, ) Masks the niimgs along time/fourth dimension to perform scrubbing (remove volumes with high motion) and/or non-steady-state volumes. This parameter is passed to nilearn.signal.clean.

Returns:
region_signalslist of 2D numpy.ndarray

List of signals for each map per subject. shape: list of (number of scans, number of maps)

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

Prepare signal extraction from regions.

Parameters:
imgslist of Niimg-like objects

See Input and output: neuroimaging data representation. Image data passed to the reporter.

yNone

This parameter is unused. It is solely included for scikit-learn compatibility.

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

Prepare and perform signal extraction.

generate_report(displayed_maps=10)[source]

Generate an HTML report for the current NiftiMapsMasker object.

Note

This functionality requires to have Matplotlib installed.

Parameters:
displayed_mapsint, or list, or ndarray, or “all”, default=10

Indicates which maps will be displayed in the HTML report.

  • If “all”: All maps will be displayed in the report.

masker.generate_report("all")
  • If a list or ndarray: This indicates the indices of the maps to be displayed in the report. For example, the following code will generate a report with maps 6, 3, and 12, displayed in this specific order:

masker.generate_report([6, 3, 12])
  • If an int: This will only display the first n maps, n being the value of the parameter. By default, the report will only contain the first 10 maps. Example to display the first 16 maps:

masker.generate_report(16)
Returns:
reportnilearn.reporting.html_report.HTMLReport

HTML report for the masker.

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(region_signals)[source]

Compute voxel signals from region signals.

Any mask given at initialization is taken into account.

Parameters:
region_signals1D/2D numpy.ndarray

Signal for each region. If a 1D array is provided, then the shape should be (number of elements,), and a 3D img will be returned. If a 2D array is provided, then the shape should be (number of scans, number of elements), and a 4D img will be returned.

Returns:
voxel_signalsnibabel.Nifti1Image

Signal for each voxel. shape: that of maps.

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_inverse_transform_request(*, region_signals='$UNCHANGED$')

Request metadata passed to the inverse_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 inverse_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 inverse_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:
region_signalsstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for region_signals parameter in inverse_transform.

Returns:
selfobject

The updated object.

set_output(*, transform=None)

Set output container.

See Introducing the set_output API for an example on how to use the API.

Parameters:
transform{“default”, “pandas”}, default=None

Configure output of transform and fit_transform.

  • “default”: Default output format of a transformer

  • “pandas”: DataFrame output

  • “polars”: Polars output

  • None: Transform configuration is unchanged

Added in version 1.4: “polars” option was added.

Returns:
selfestimator instance

Estimator instance.

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_single_imgs(imgs, confounds=None, sample_mask=None)[source]

Extract signals from a single 4D niimg.

Parameters:
imgs3D/4D Niimg-like object

See Input and output: neuroimaging data representation. Images to process. If a 3D niimg is provided, a singleton dimension will be added to the output to represent the single scan in the niimg.

confoundsCSV file or array-like, optional

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

sample_maskAny type compatible with numpy-array indexing, optional

shape: (number of scans - number of volumes removed, ) Masks the niimgs along time/fourth dimension to perform scrubbing (remove volumes with high motion) and/or non-steady-state volumes. This parameter is passed to signal.clean.

Added in version 0.8.0.

Returns:
region_signals2D numpy.ndarray

Signal for each map. shape: (number of scans, number of maps)

Warns:
DeprecationWarning

If a 3D niimg input is provided, the current behavior (adding a singleton dimension to produce a 2D array) is deprecated. Starting in version 0.12, a 1D array will be returned for 3D inputs.

Examples using nilearn.maskers.MultiNiftiMapsMasker

Comparing connectomes on different reference atlases

Comparing connectomes on different reference atlases