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.NiftiSpheresMasker#

class nilearn.maskers.NiftiSpheresMasker(seeds, radius=None, mask_img=None, allow_overlap=False, 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, memory=Memory(location=None), memory_level=1, verbose=0)[source]#

Class for masking of Niimg-like objects using seeds.

NiftiSpheresMasker is useful when data from given seeds should be extracted. Use case: Summarize brain signals from seeds that were obtained from prior knowledge.

Parameters
seedslist of triplet of coordinates in native space

Seed definitions. List of coordinates of the seeds in the same space as the images (typically MNI or TAL).

radiusfloat, optional

Indicates, in millimeters, the radius for the sphere around the seed. Default is None (signal is extracted on a single voxel).

mask_imgNiimg-like object, optional

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

allow_overlapbool, 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=False.

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_confoundsbool, 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_confoundsbool, 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.

detrendbool, 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.

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=1.

verboseint, optional

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

Attributes
n_elements_int

The number of seeds in the masker.

New in version 0.9.2.

seeds_list of list

The coordinates of the seeds in the masker.

__init__(seeds, radius=None, mask_img=None, allow_overlap=False, 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, memory=Memory(location=None), memory_level=1, verbose=0)[source]#
fit(X=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.

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 or pandas.DataFrame, 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

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. shape: (number of scans - number of volumes removed, )

New in version 0.8.0.

Returns
region_signals2D numpy.ndarray

Signal for each sphere. shape: (number of scans, number of spheres)

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 or pandas.DataFrame, 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

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. shape: (number of scans - number of volumes removed, )

New in version 0.8.0.

Returns
region_signals2D numpy.ndarray

Signal for each sphere. shape: (number of scans, number of spheres)

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.

inverse_transform(region_signals)[source]#

Compute voxel signals from spheres signals

Any mask given at initialization is taken into account. Throws an error if mask_img==None

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.nifti1.Nifti1Image

Signal for each sphere. shape: (mask_img, number of scans).

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_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

  • None: Transform configuration is unchanged

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.

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

New in version 0.8.0.

Returns
region_signals2D numpy.ndarray

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

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.NiftiSpheresMasker#

Producing single subject maps of seed-to-voxel correlation

Producing single subject maps of seed-to-voxel correlation

Producing single subject maps of seed-to-voxel correlation
Extract signals on spheres and plot a connectome

Extract signals on spheres and plot a connectome

Extract signals on spheres and plot a connectome
Default Mode Network extraction of ADHD dataset

Default Mode Network extraction of ADHD dataset

Default Mode Network extraction of ADHD dataset
Predicted time series and residuals

Predicted time series and residuals

Predicted time series and residuals
Beta-Series Modeling for Task-Based Functional Connectivity and Decoding

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

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