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.input_data.NiftiMapsMasker#

class nilearn.input_data.NiftiMapsMasker(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=Memory(location=None), memory_level=0, verbose=0, reports=True)[source]#

Class for masking of Niimg-like objects.

NiftiMapsMasker is useful when data from overlapping volumes should be extracted (contrarily to nilearn.maskers.NiftiLabelsMasker). Use case: Summarize brain signals from large-scale networks obtained by prior PCA or ICA.

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

Parameters
maps_img4D niimg-like object

See http://nilearn.github.io/manipulating_images/input_output.html Set of continuous maps. One representative time course per map is extracted using least square regression.

mask_img3D niimg-like object, optional

See http://nilearn.github.io/manipulating_images/input_output.html Mask to apply to regions before extracting signals.

allow_overlapboolean, optional

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

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{False, True, ‘zscore’, ‘psc’}, optional

Strategy to standardize the signal. ‘zscore’: the signal is z-scored. Timeseries are shifted to zero mean and scaled to unit variance. ‘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. Timeseries are shifted to zero mean and scaled to unit variance. False : Do not standardize the data. Default=False.

standardize_confoundsboolean, optional

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

high_variance_confoundsboolean, optional

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

detrendboolean, optional

This parameter is passed to signal.clean. Please see the related documentation for details. Default=False.

low_passNone or float, optional

This parameter is passed to signal.clean. Please see the related documentation for details

high_passNone or float, optional

This parameter is passed to signal.clean. Please see the related documentation for details

t_rfloat, optional

This parameter is passed to signal.clean. Please see the related documentation for details

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}, optional.

Gives which image gives the final shape/size. For example, if resampling_target is “mask” then maps_img and images provided to fit() are resampled to the shape and affine of mask_img. “None” means no resampling: if shapes and affines do not match, a ValueError is raised. Default=”data”.

memoryjoblib.Memory or str, optional

Used to cache the region extraction process. By default, no caching is done. If a string is given, it is the path to the caching directory.

memory_levelint, optional

Aggressiveness of memory caching. The higher the number, the higher the number of functions that will be cached. Zero means no caching. Default=0.

verboseinteger, optional

Indicate the level of verbosity. By default, nothing is printed. Default=0.

reportsboolean, optional

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

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=Memory(location=None), memory_level=0, verbose=0, reports=True)[source]#
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”, optional

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)

Default=10.

Returns
reportnilearn.reporting.html_report.HTMLReport

HTML report for the masker.

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

Prepare signal extraction from regions.

All parameters are unused, they are for scikit-learn compatibility.

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

Prepare and perform signal extraction.

transform_single_imgs(imgs, confounds=None, sample_mask=None)[source]#

Extract signals from a single 4D niimg.

Parameters
imgs3D/4D Niimg-like object

See http://nilearn.github.io/manipulating_images/input_output.html Images to process. It must boil down to a 4D image with scans number as last dimension.

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.

New in version 0.8.0.

Returns
region_signals2D numpy.ndarray

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

inverse_transform(region_signals)[source]#

Compute voxel signals from region signals

Any mask given at initialization is taken into account.

Parameters
region_signals2D numpy.ndarray

Signal for each region. shape: (number of scans, number of regions)

Returns
voxel_signalsnibabel.Nifti1Image

Signal for each voxel. shape: that of maps.

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.

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.

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

Apply mask, spatial and temporal preprocessing

Parameters
imgs3D/4D Niimg-like object

See http://nilearn.github.io/manipulating_images/input_output.html Images to process. It must boil down to a 4D image with scans number as last dimension.

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.

New in version 0.8.0.

Returns
region_signals2D numpy.ndarray

Signal for each element. shape: (number of scans, number of elements)