Examples
70 runnable programs in src/examples, built with the rest of MNE-CPP. Find one by what you want to do, the recordings you work with, or the library you are learning; each page explains the method, links the API it uses and shows the complete source.
- Average epochs into an evoked response
Average stimulus-locked epochs of a raw FIFF recording into an evoked response, with event selection and EOG rejection.
- Compute an MNE or dSPM source estimate
L2 minimum-norm or dSPM estimate of the sample evoked response from a precomputed inverse operator.
- Connectivity metrics on simulated coupled signals
Connectivity metrics on synthetic data with a known coupling.
- Design and apply an FIR filter
FIR filter design, application and storage with the dsp library.
- Multitaper spectra and cross-spectral density
Multitaper spectra, power spectral density and cross-spectral density of random test signals.
- Plot raw data as image, line and time-frequency maps
Disp library widgets: image map, line plot and time-frequency plot of raw data.
- Plot types and colour maps
Disp plots: colour maps, bar and spline histograms, line plots, image and time-frequency maps.
- Read a segment of raw data
Read a segment of a raw FIFF recording with channel picking, SSP projectors and CTF compensation.
- Read an evoked response
Read an evoked data set from FIFF and print its measurement info and coordinate transforms.
- Read epochs from a raw recording
Read stimulus-locked epochs from a raw FIFF recording with event selection and artifact rejection.
- Spectral analysis and filtering of known signals
Spectral and filtering tools of the dsp library on signals with known content.
- Time-frequency plot of an evoked channel
Spectrogram of one evoked channel shown as a time-frequency plot.
- Band-pass filter a raw recording
Band-pass filter the MEG channels of a raw FIFF recording with a cosine FIR filter and write the result.
- Buffers, logging, montages and reports
Utilities library: buffers, observers, logging, file formats, montages, layouts and reports.
- Copy a raw recording to a new FIFF file
Copy a raw FIFF recording buffer by buffer into a new file with FiffStream.
- Linear algebra and numerics helpers
Math library on inputs with known answers.
- List the conditions of an evoked file
List the evoked data sets (conditions) stored in a FIFF file.
- Make a 2D channel layout from sensor positions
Project the 3D sensor positions of a FIFF file onto a 2D channel layout.
- Read and cluster a forward solution
Read a forward solution, print its gain matrix and source geometry, and cluster it by cortical parcellation.
- Read and write a BEM model
Read a BEM model from FIFF, write it back and verify the round trip.
- Read and write BIDS datasets
BIDS library: paths, sidecar TSVs, BrainVision/EDF readers and a raw-data round trip.
- Read any FIFF file with FiffIO
Read the data sets of a FIFF file through the generic FiffIO interface and write its raw data back to disk.
- Read FreeSurfer surfaces, labels and atlases
FreeSurfer library: surfaces, curvature, parcellations, labels and an atlas volume.
- Read MGH, MGZ and NIfTI volumes
MRI library: MGH/MGZ and NIfTI volumes, voxel/RAS transforms, slicing and COR sets.
- sEEG leads, bipolar montages and surface painting
IEEG library: group sEEG contacts into a lead, derive a bipolar montage and paint contact values onto a surface.
- Show a source space with its parcellation in 3D
Read a forward solution and show its source space with the FreeSurfer parcellation in 3D.
- Show FreeSurfer surfaces in 3D
Load the pial, inflated, original and white FreeSurfer surfaces of a subject and show them in 3D.
- Spectra, filters, peaks and envelopes
DSP library: Welch PSD, FIR filtering, peak finding, envelope correlation, SPHARA and simulation.
- Statistical tests on data with known answers
Statistics library on small literal data sets with known answers.
- Stream data with Lab Streaming Layer
LSL library: publish a stream, discover it and receive its samples over loopback.
- Thin-plate-spline warping
Example demonstrating thin-plate-spline (TPS) warping with UTILSLIB::Warp.
- Tour of the FIFF data structures
FIFF library: measurement info, channels, digitizer, transforms, projectors, covariance, events, annotations, evoked sets and the low-level file structure.
- Contextual minimum-norm estimate (CMNE)
Contextual minimum-norm estimate (CMNE) of the auditory evoked response in both auditory cortices.
- Histogram of source amplitudes
Histogram of the source amplitudes of a clustered MNE, dSPM or sLORETA estimate of the sample evoked response.
- BEM surfaces, source spaces and epochs
MNE library: BEM surfaces, surface projection, ICP, source spaces and epochs.
- Benchmark connectivity methods
Benchmark the run time of connectivity methods over channel and sample counts.
- Build a 3D scene of sensors, electrodes and MRI slices
Disp3D scene data: sensor-to-surface interpolation, electrodes, MRI slices, video overlay and layers.
- Build and run an MNA processing graph
MNA library: register operations, build and run a graph, bind parameters and save a project.
- Change the CTF gradient compensation grade
Build the CTF software gradient compensator that converts an evoked data set between compensation grades.
- Coils, BEM models and forward solutions
Forward library: coil definitions, BEM and sphere models, field maps and forward solutions.
- Compute the MEG/EEG forward solution
Compute the MEG/EEG forward solution of the sample subject from its BEM, source space and head-MRI transform.
- Coregister digitizer points to the head surface
Coregistration workflow: fit digitizer points to the head surface with ICP.
- Detect and repair artifacts
Artifact detection and repair with the dsp library on a recording with planted defects.
- Epochs, compensation and the FIFF file directory
FIFF library: fixed-length epochs, CTF compensation, the file directory and raw buffers, and handing recordings to another application.
- Estimate the head position from HPI coils
Inverse library: continuous head position (HPI) fitting.
- Fit an equivalent current dipole
Inverse library: equivalent current dipole fitting in a sphere model.
- Interpolate sensor values onto a surface
Map evoked MEG values onto a surface mesh with surface-constrained distances (GeometryInfo) and interpolation weights.
- LCMV and DICS beamformers and RAP-MUSIC scanners
Inverse library: LCMV and DICS beamformers and the RAP-MUSIC family of dipole scanners.
- Make and apply MEG, EEG and combined inverse operators
Assemble MEG+EEG, MEG-only and EEG-only inverse operators from a forward solution and a regularized noise covariance, then apply them.
- Parse a FIFF file from a memory buffer
Read a FIFF file from a memory buffer with a chosen byte order and summarise its contents.
- Preprocessing tools on simulated data
Preprocessing tools of the dsp library on synthetic data with a known ground truth.
- Run ONNX models with the ML library
ML library: tensors, ONNX inference through the MlModel interface, and the Python trainer.
- Source estimate of an evoked response from raw data
Average epochs of a raw recording and compute an MNE, dSPM or sLORETA source estimate of the response.
- Spatial decoding and ICA component labelling
Spatial decoders and ICA labelling on synthetic mixtures with a known ground truth.
- Tangential amplitude of planar gradiometers
Compute tangential gradient amplitudes from planar gradiometer data.
- Tour of the inverse library
Inverse library: minimum-norm estimates, resolution matrices, label time courses, sparse solvers and source-estimate I/O.
- Compare connectivity metrics side by side
Compare connectivity metrics side by side on the same averaged sensor- or source-level data.
- Fit continuous HPI coils
Fit continuous HPI coils on raw data with SSP and write the head positions for comparison with MaxFilter.
- Functional connectivity shown as a 3D network
Sensor- or source-level functional connectivity of averaged MEG/EEG data with a selectable metric, shown as a 3D network.
- Localize dipoles with Powell RAP-MUSIC
Localize dipole pairs in the sample evoked response with Powell-accelerated RAP-MUSIC on a clustered forward solution.
- Localize dipoles with RAP-MUSIC
Localize dipole pairs in the sample evoked response with RAP-MUSIC on a clustered forward solution.
- Maxwell filtering (SSS) and movement compensation
DSP Maxwell filtering: SSS, bad-channel detection, movement compensation, fine calibration and cHPI removal.
- MNE, dSPM and sLORETA with a clustered forward model
Cluster the forward solution by cortical parcellation and compute an MNE, dSPM or sLORETA estimate of an evoked response.
- Powell RAP-MUSIC on raw data with a clustered forward model
Average a raw recording and localize dipole pairs with Powell RAP-MUSIC on a parcellation-clustered forward solution.
- Powell RAP-MUSIC restricted to regions of interest
Restrict the forward solution to selected parcellation labels and localize dipole pairs with Powell RAP-MUSIC.
- RAP-MUSIC on raw data with a clustered forward model
Average a raw recording and localize dipole pairs with RAP-MUSIC on a parcellation-clustered forward solution.
- Real-time averaging, covariance and inverse workers
DSP real-time workers: averaging, covariance, noise spectrum, connectivity, HPI fitting and inverse operators.
- Show a source estimate on the cortex in 3D
Compute a clustered MNE, dSPM or sLORETA estimate of the sample evoked response and show it on the cortex with Disp3D.
- Single-trial dipole localization with Powell RAP-MUSIC
Localize dipole pairs in single trials of a raw recording with Powell RAP-MUSIC on a clustered forward solution.
- Source estimate from raw data with a clustered forward model
Average a raw recording and compute an MNE, dSPM or sLORETA estimate with a parcellation-clustered forward solution.













