Reference documentation: all nilearn functions#
This is the class and function reference of nilearn. Please refer to the user guide for more information and usage examples.
List of modules
nilearn.connectome
: Functional Connectivitynilearn.datasets
: Automatic Dataset Fetchingnilearn.decoding
: Decodingnilearn.decomposition
: Multivariate Decompositionsnilearn.image
: Image Processing and Resampling Utilitiesnilearn.interfaces
: Loading components from interfacesnilearn.maskers
: Extracting Signals from Brain Imagesnilearn.masking
: Data Masking Utilitiesnilearn.regions
: Operating on Regionsnilearn.mass_univariate
: Mass-Univariate Analysisnilearn.plotting
: Plotting Brain Datanilearn.plotting.displays
: Interacting with figures
nilearn.signal
: Preprocessing Time Seriesnilearn.glm
: Generalized Linear Modelsnilearn.reporting
: Reporting Functionsnilearn.surface
: Manipulating Surface Data
nilearn.connectome
: Functional Connectivity#
Tools for computing functional connectivity matrices and also implementation of algorithm for sparse multi subjects learning of Gaussian graphical models.
Classes:
|
A class that computes different kinds of functional connectivity matrices. |
|
Covariance and precision matrix estimator. |
|
Sparse inverse covariance w/ cross-validated choice of the parameter. |
Functions:
|
Return the flattened lower triangular part of an array. |
|
Return the symmetric matrix given its flattened lower triangular part. |
|
Compute sparse precision matrices and covariance matrices. |
|
Return correlation matrix for a given covariance matrix. |
|
Return partial correlation matrix for a given precision matrix. |
nilearn.datasets
: Automatic Dataset Fetching#
Helper functions to download NeuroImaging datasets
User guide: See the Fetching open datasets from Internet section for further details.
Templates#
Functions:
|
Download and load the ICBM152 template (dated 2009). |
|
Downloads ICBM152 template first, then loads the 'gm' mask. |
|
Download a Freesurfer fsaverage surface. |
|
Load the MNI152 whole-brain mask. |
|
Load the MNI152 grey-matter mask. |
|
Load the MNI152 grey-matter template. |
|
Load the MNI152 skullstripped T1 template. |
|
Load the MNI152 white-matter mask. |
|
Load the MNI152 white-matter template. |
Atlases#
Functions:
|
Downloads and returns the AAL template for SPM 12. |
|
Download and return file names for the Allen and MIALAB ICA Probabilistic atlas (dated 2011). |
|
Downloads and loads multiscale functional brain parcellations. |
|
Download and return file names for the Craddock 2012 parcellation. |
|
Download and load the Destrieux cortical deterministic atlas (dated 2009). |
|
Fetch DiFuMo brain atlas. |
|
Load Harvard-Oxford parcellations from FSL. |
|
Load Juelich parcellations from FSL. |
|
Download and load the MSDL brain Probabilistic atlas. |
|
Download the Pauli et al. (2017) atlas. |
|
Download and return file names for the Schaefer 2018 parcellation. |
|
Download and load the Smith ICA and BrainMap Probabilistic atlas (2009). |
|
Download and load Destrieux et al, 2010 cortical Deterministic atlas. |
|
Download the Talairach Deterministic atlas. |
|
Download and return file names for the Yeo 2011 parcellation. |
|
Load the Dosenbach et al. 160 ROIs. |
|
Download and load the Power et al. brain atlas composed of 264 ROIs. |
|
Load the Seitzman et al. 300 ROIs. |
Preprocessed datasets#
Functions:
|
Fetch ABIDE dataset. |
|
Download and load the ADHD resting-state dataset. |
|
Download language localizer example bids dataset. |
|
Fetch movie watching based brain development dataset (fMRI) |
|
Fetch URLs for files from the ds000030 BIDS dataset. |
|
Download a first-level fiac fMRI dataset (2 sessions) |
|
Download and loads complete haxby dataset. |
Download language localizer demo dataset. |
|
|
Download a first-level localizer fMRI dataset |
|
Download and loads Miyawaki et al. 2008 dataset (153MB). |
|
Download a file with OpenNeuro BIDS dataset index. |
|
Function to fetch SPM auditory single-subject data. |
|
Fetcher for Multi-modal Face Dataset. |
|
Download and load the NKI enhanced resting-state dataset, preprocessed and projected to the fsaverage5 space surface. |
Statistical maps/derivatives#
Functions:
|
Fetch left vs right button press contrast maps from the localizer. |
Fetch calculation task contrast maps from the localizer. |
|
|
Download and load Brainomics/Localizer dataset (94 subjects). |
|
Downloads and returns Network Matrices data from MegaTrawls release in HCP. |
|
Fetch Jimura "mixed gambles" dataset. |
|
Download and load Oasis "cross-sectional MRI" dataset (416 subjects). |
Fetch a contrast map from NeuroVault showing the effect of mental subtraction upon auditory instructions |
|
|
Fetch left vs right button press group contrast map from NeuroVault. |
General functions#
Functions:
|
Download data from neurovault.org that match certain criteria. |
|
Download specific images and collections from neurovault.org. |
|
Download OpenNeuro BIDS dataset. |
|
Returns the directories in which nilearn looks for data. |
|
Add symlinks for files not named according to BIDS conventions. |
|
Select subset of urls with given filters. |
nilearn.decoding
: Decoding#
Decoding tools and algorithms.
Classes:
|
A wrapper for popular classification strategies in neuroimaging. |
|
A wrapper for popular regression strategies in neuroimaging. |
|
State of the art decoding scheme applied to usual classifiers. |
|
State of the art decoding scheme applied to usual regression estimators. |
|
Classification learners with sparsity and spatial priors. |
|
Regression learners with sparsity and spatial priors. |
|
Implement search_light analysis using an arbitrary type of classifier. |
nilearn.decomposition
: Multivariate Decompositions#
The nilearn.decomposition
module includes a subject level
variant of the ICA called Canonical ICA.
Classes:
|
Perform Canonical Independent Component Analysis [R637c2563345c-1] [R637c2563345c-2]. |
|
Perform a map learning algorithm based on spatial component sparsity, over a CanICA initialization [Rd0eec3116114-1]. |
nilearn.image
: Image Processing and Resampling Utilities#
Mathematical operations working on Niimg-like objects like a (3+)D block of data, and an affine.
Functions:
|
Binarize an image such that its values are either 0 or 1. |
|
Improve SNR on masked fMRI signals. |
|
Concatenate a list of 3D/4D niimgs of varying lengths. |
|
Convert the x, y, z coordinates from one image space to another |
|
Copy an image to a nibabel.Nifti1Image. |
|
Crops an image as much as possible. |
|
Get the image data as a |
|
Return confounds signals extracted from input signals with highest variance. |
|
Indexes into a 4D Niimg-like object in the fourth dimension. |
|
Iterates over a 4D Niimg-like object in the fourth dimension. |
Return the largest connected component of an image or list of images. |
|
|
Load a Niimg-like object from filenames or list of filenames. |
|
Interpret a numpy based string formula using niimg in named parameters. |
|
Compute the mean of the images over time or the 4th dimension. |
|
Create a new image of the same class as the reference image |
|
Resample a Niimg-like object |
|
Resample a Niimg-like source image on a target Niimg-like image (no registration is performed: the image should already be aligned). |
|
Returns an image with the affine diagonal (by permuting axes). |
|
Smooth images by applying a Gaussian filter. |
|
Performs swapping of hemispheres in the indicated NIfTI image. |
|
Threshold the given input image, mostly statistical or atlas images. |
nilearn.interfaces
: Loading components from interfaces#
Interfaces for Nilearn.
nilearn.interfaces.bids
#
The nilearn.interfaces.bids
module includes tools to work with
BIDS format data.
Functions:
|
Search for files in a BIDS dataset following given constraints. |
|
Return dictionary with parsed information from file path. |
|
Save GLM results to BIDS-like files. |
nilearn.interfaces.fmriprep
#
The nilearn.interfaces.fmriprep
module includes tools to preprocess
neuroimaging data and access fMRIPrep generated confounds.
Functions:
|
Use confounds from fMRIPrep. |
|
Use preset strategy to load confounds from fMRIPrep. |
nilearn.interfaces.fsl
#
Functions for working with the FSL library.
Functions:
|
Extract design matrix dataframe from FSL mat file. |
nilearn.maskers
: Extracting Signals from Brain Images#
The nilearn.maskers
contains masker objects.
User guide: See the NiftiMasker: applying a mask to load time-series section for further details.
Classes:
Base class for NiftiMaskers. |
|
|
Applying a mask to extract time-series from Niimg-like objects. |
|
Class for masking of Niimg-like objects. |
|
Class for masking of Niimg-like objects. |
|
Class for masking of Niimg-like objects. |
|
Class for masking of Niimg-like objects using seeds. |
nilearn.masking
: Data Masking Utilities#
Utilities to compute and operate on brain masks
User guide: See the Masking the data: from 4D image to 2D array section for further details.
Functions:
|
Compute a brain mask from fMRI data in 3D or 4D |
|
Compute a common mask for several sessions or subjects of fMRI data. |
|
Compute the whole-brain, grey-matter or white-matter mask. |
|
Compute the whole-brain, grey-matter or white-matter mask for a list of images. |
|
Compute a brain mask for the images by guessing the value of the background from the border of the image. |
|
Compute a common mask for several sessions or subjects of data. |
|
Compute intersection of several masks. |
|
Extract signals from images using specified mask. |
|
Take masked data and bring them back into 3D/4D. |
nilearn.regions
: Operating on Regions#
The nilearn.regions
class module includes region extraction
procedure on a 4D statistical/atlas maps and its function.
Functions:
|
Extraction of brain connected regions into separate regions. |
|
Extract connected regions from a brain atlas image defined by labels (integers). |
|
Extract region signals from image. |
|
Create image from region signals defined as labels. |
|
Extract region signals from image. |
|
Create image from region signals defined as maps. |
Classes:
|
Class for brain region extraction. |
|
Learn parcellations on fMRI images. |
|
Recursive Neighbor Agglomeration (ReNA): Recursively merges the pair of clusters according to 1-nearest neighbors criterion. |
|
Hierarchical KMeans: First clusterize the samples into big clusters. |
nilearn.mass_univariate
: Mass-Univariate Analysis#
Defines a Massively Univariate Linear Model estimated with OLS and permutation test
Functions:
|
Massively univariate group analysis with permuted OLS. |
nilearn.plotting
: Plotting Brain Data#
Plotting code for nilearn
Functions:
|
Find 'good' cross-section slicing positions along a given axis. |
|
Find the center of the largest activation connected component. |
|
Return coordinates of center of mass of 3D parcellation atlas. |
|
Return coordinates of center probabilistic atlas 4D image. |
|
Plot cuts of an anatomical image (by default 3 cuts: Frontal, Axial, and Lateral) |
|
Plot cuts of a given image (by default Frontal, Axial, and Lateral) |
|
Plot cuts of an EPI image (by default 3 cuts: Frontal, Axial, and Lateral) |
|
Plot the given matrix. |
|
Plot cuts of an ROI/mask image (by default 3 cuts: Frontal, Axial, and Lateral) |
|
Plot cuts of an ROI/mask image (by default 3 cuts: Frontal, Axial, and Lateral) |
|
Plot 2d projections of an ROI/mask image (by default 3 projections: Frontal, Axial, and Lateral). |
|
Plot connectome on top of the brain glass schematics. |
|
Plot network nodes (markers) on top of the brain glass schematics. |
|
Plot the probabilistic atlases onto the anatomical image by default MNI template |
|
Plot an image representation of voxel intensities across time. |
|
Plotting of surfaces with optional background and data |
|
Plotting ROI on a surface mesh with optional background |
|
Plotting contours of ROIs on a surface, optionally over a statistical map. |
|
Plotting a stats map on a surface mesh with optional background |
|
Convenience function to plot multiple views of plot_surf_stat_map in a single figure. |
|
Creates plots to compare two lists of images and measure correlation. |
|
Plot a design matrix provided as a |
|
Creates plot for event visualization. |
|
Creates plot for contrast definition. |
|
Insert a surface plot of a surface map into an HTML page. |
|
Insert a surface plot of a statistical map into an HTML page. |
|
Insert a 3d plot of a connectome into an HTML page. |
|
Insert a 3d plot of markers in a brain into an HTML page. |
|
Interactive html viewer of a statistical map, with optional background. |
|
Show all the figures generated by nilearn and/or matplotlib. |
nilearn.plotting.displays
: Interacting with figures#
Display objects and utilities.
These objects are returned by plotting functions
from the plotting
module.
Functions:
|
Retrieve a projector from a given display mode. |
|
Retrieve a slicer from a given display mode. |
Classes:
|
A class to create linked axes for plotting orthogonal projections of 3D maps. |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
An MPL axis-like object that displays a 2D view of 3D volumes. |
|
An MPL axis-like object that displays a cut of 3D volumes. |
|
An MPL axis-like object that displays a 2D projection of 3D volumes with a schematic view of the brain. |
|
BaseSlicer implementation which main purpose is to auto adjust the axes size to the data with different layout of cuts. |
|
A class to create 3 linked axes for plotting orthogonal cuts of 3D maps. |
|
Implementation of a surface figure obtained with plotly engine. |
|
A class to create 3 axes for plotting orthogonal cuts of 3D maps, organized in a 2x2 grid. |
|
A class to create 3 |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
nilearn.signal
: Preprocessing Time Series#
Preprocessing functions for time series.
All functions in this module should take X matrices with samples x features
Functions:
|
Apply a low-pass, high-pass or band-pass Butterworth filter. |
|
|
|
Return confounds time series extracted from series with highest variance. |
nilearn.glm
: Generalized Linear Models#
Analysing fMRI data using GLMs.
- Note that the nilearn.glm module is experimental.
It may change in any future (>0.7.0) release of Nilearn.
Classes:
|
The contrast class handles the estimation of statistical contrasts on a given model: student (t) or Fisher (F). |
|
Results from an F contrast of coefficients in a parametric model. |
|
Results from a t contrast of coefficients in a parametric model. |
|
A regression model with an AR(p) covariance structure. |
|
A simple ordinary least squares model. |
|
Class to contain results from likelihood models. |
|
This class summarizes the fit of a linear regression model. |
|
This class contains only information of the model fit necessary for contrast computation. |
Functions:
|
Compute the specified contrast given an estimated glm |
|
Compute the fixed effects, given images of effects and variance |
|
Converts a string describing a contrast to a contrast vector |
|
Return the Benjamini-Hochberg FDR threshold for the input z_vals |
|
Report the proportion of active voxels for all clusters defined by the input threshold. |
|
Compute the required threshold level and return the thresholded map |
nilearn.glm.first_level
#
Classes:
|
Implementation of the General Linear Model for single session fMRI data. |
Functions:
|
Check that the provided DataFrame is indeed a valid design matrix descriptor, and returns a triplet of fields |
|
This is the main function to convolve regressors with hrf model |
|
Create FirstLevelModel objects and fit arguments from a BIDS dataset. |
|
Implementation of the Glover dispersion derivative hrf model |
|
Implementation of the Glover hrf model |
|
Implementation of the Glover time derivative hrf (dhrf) model |
|
Generate a design matrix from the input parameters |
|
Scaling of the data to have percent of baseline change along the specified axis |
|
GLM fit for an fMRI data matrix |
|
Implementation of the SPM dispersion derivative hrf model |
|
Implementation of the SPM hrf model |
|
Implementation of the SPM time derivative hrf (dhrf) model |
nilearn.glm.second_level
#
Classes:
|
Implementation of the General Linear Model for multiple subject fMRI data. |
Functions:
|
Sets up a second level design. |
|
Generate p-values corresponding to the contrasts provided based on permutation testing. |
nilearn.reporting
: Reporting Functions#
Reporting code for nilearn
Classes:
|
A report written as HTML. |
Functions:
|
Creates pandas dataframe with img cluster statistics. |
|
Returns HTMLReport object for a report which shows all important aspects of a fitted GLM. |
nilearn.surface
: Manipulating Surface Data#
Functions for surface manipulation.
Functions:
|
Loading data to be represented on a surface mesh. |
|
Loading a surface mesh geometry |
|
Extract surface data from a Nifti image. |