# Examples Gallery#

The examples gallery provides working code samples demonstrating various analysis and visualization techniques. These examples often lack the narrative explanations seen in the tutorials, and do not follow any specific order. These examples are a useful way to discover new analysis or plotting ideas, or to see how a particular technique you’ve read about can be applied using MNE-Python.

Note

If example-scripts contain plots and are run locally, using the
interactive interactive flag with `python -i tutorial_script.py`

keeps them open.

Warning

These examples sometimes use simulations or shortcuts (such as intentionally adding noise to recordings) to illustrate a point. Use caution when copy-pasting code samples.

## Input/Output#

Recipes for reading and writing files. See also our tutorials on reading data from various recording systems and our tutorial on manipulating MNE-Python data structures.

Getting averaging info from .fif files

How to use data in neural ensemble (NEO) format

Reading/Writing a noise covariance matrix

## Data Simulation#

Tools to generate simulation data.

Compare simulated and estimated source activity

Generate simulated evoked data

Simulate raw data using subject anatomy

Generate simulated source data

## Preprocessing#

Examples related to data preprocessing (artifact detection / rejection etc.)

Cortical Signal Suppression (CSS) for removal of cortical signals

Define target events based on time lag, plot evoked response

Identify EEG Electrodes Bridged by too much Gel

Transform EEG data using current source density (CSD)

Reduce EOG artifacts through regression

Find MEG reference channel artifacts

Visualise NIRS artifact correction methods

Compare the different ICA algorithms in MNE

Interpolate bad channels for MEG/EEG channels

Maxwell filter data with movement compensation

Annotate movement artifacts and reestimate dev_head_t

Removing muscle ICA components

Plot sensor denoising using oversampled temporal projection

Shifting time-scale in evoked data

## Visualization#

Looking at data and processing output.

How to convert 3D electrode positions to a 2D image

Visualize channel over epochs as an image

Plotting EEG sensors on the scalp

Plotting topographic arrowmaps of evoked data

Plotting topographic maps of evoked data

Whitening evoked data with a noise covariance

Plotting sensor layouts of MEG systems

Plotting sensor layouts of EEG systems

Make figures more publication ready

Plot single trial activity, grouped by ROI and sorted by RT

Show noise levels from empty room data

Sensitivity map of SSP projections

Compare evoked responses for different conditions

Plot custom topographies for MEG sensors

## Time-Frequency Examples#

Some examples of how to explore time-frequency content of M/EEG data with MNE.

Compute a cross-spectral density (CSD) matrix

Compute Power Spectral Density of inverse solution from single epochs

Compute power and phase lock in label of the source space

Compute source power spectral density (PSD) in a label

Compute source power spectral density (PSD) of VectorView and OPM data

Compute induced power in the source space with dSPM

Temporal whitening with AR model

Compute and visualize ERDS maps

Explore event-related dynamics for specific frequency bands

Time-frequency on simulated data (Multitaper vs. Morlet vs. Stockwell vs. Hilbert)

## Statistics Examples#

Some examples of how to compute statistics on M/EEG data with MNE.

Permutation F-test on sensor data with 1D cluster level

FDR correction on T-test on sensor data

Regression on continuous data (rER[P/F])

Permutation T-test on sensor data

Analysing continuous features with binning and regression in sensor space

## Machine Learning (Decoding, Encoding, and MVPA)#

Decoding, encoding, and general machine learning examples.

Motor imagery decoding from EEG data using the Common Spatial Pattern (CSP)

Decoding in time-frequency space using Common Spatial Patterns (CSP)

Representational Similarity Analysis

Continuous Target Decoding with SPoC

Decoding sensor space data with generalization across time and conditions

Analysis of evoked response using ICA and PCA reduction techniques

Compute effect-matched-spatial filtering (EMS)

Linear classifier on sensor data with plot patterns and filters

Receptive Field Estimation and Prediction

Compute Spectro-Spatial Decomposition (SSD) spatial filters

## Connectivity Analysis Examples#

Examples demonstrating connectivity analysis in sensor and source space.

Note

Connectivity functionality has moved into the
`mne_connectivity`

package. Examples can be found at
Examples.

## Forward modeling#

From BEM segmentation, coregistration, setting up source spaces to actual computation of forward solution.

Display sensitivity maps for EEG and MEG sensors

Generate a left cerebellum volume source space

## Inverse problem and source analysis#

Estimate source activations, extract activations in labels, morph data between subjects etc.

Compute MNE-dSPM inverse solution on single epochs

Compute sLORETA inverse solution on raw data

Compute MNE-dSPM inverse solution on evoked data in volume source space

Source localization with a custom inverse solver

Compute source level time-frequency timecourses using a DICS beamformer

Compute source power using DICS beamformer

Compute evoked ERS source power using DICS, LCMV beamformer, and dSPM

Compute a sparse inverse solution using the Gamma-MAP empirical Bayesian method

Extracting time course from source_estimate object

Generate a functional label from source estimates

Extracting the time series of activations in a label

Compute sparse inverse solution with mixed norm: MxNE and irMxNE

Compute MNE inverse solution on evoked data with a mixed source space

Compute source power estimate by projecting the covariance with MNE

Morph volumetric source estimate

Computing source timecourses with an XFit-like multi-dipole model

Compute iterative reweighted TF-MxNE with multiscale time-frequency dictionary

Visualize source leakage among labels using a circular graph

Plot point-spread functions (PSFs) and cross-talk functions (CTFs)

Compute cross-talk functions for LCMV beamformers

Plot point-spread functions (PSFs) for a volume

Compute Rap-Music on evoked data

Compute spatial resolution metrics in source space

Compute spatial resolution metrics to compare MEG with EEG+MEG

Estimate data SNR using an inverse

Compute MxNE with time-frequency sparse prior

Plotting the full vector-valued MNE solution

## Examples on open datasets#

Some demos on common/public datasets using MNE.

Brainstorm raw (median nerve) dataset

Single trial linear regression analysis with the LIMO dataset

Optically pumped magnetometer (OPM) data

From raw data to dSPM on SPM Faces dataset