MNE-Python Documentation
repository·main·Indexed 25 days ago
https://github.com/mne-tools/mne-pythonAn open-source Python package for exploring, visualizing, and analyzing human neurophysiological data, including MEG, EEG, sEEG, and ECoG. It provides tools for loading raw sensor data from various formats (e.g., FIF, EDF, BDF), managing channel montages, creating BEM meshes via watershed or FLASH images, and performing spherical spline interpolation to repair bad EEG channels.
What's inside MNE-Python
- MNE-Python provides tutorials and tools for defining cortical source locations (source spaces) and forward models (also known as leadfield matrices). These components are essential for modeling how neural activity at specific source locations is projected to the sensors (e.g., EEG, MEG).
Overview of MNE-Python introductory tutorials
mainThe introductory tutorials in MNE-Python provide a foundation for performing event-related analysis using EEG/MEG data. They cover the following core concepts:
- The EEG/MEG pipeline: Basic steps for event-related analysis.
- Core data structures: Introduction to
mne.Info,events, andmne.Annotations. - Sensor locations: How sensor positions and montages are handled within the library.
- Configuration: Overview of available configuration options for the MNE environment.
Overview of MNE-CPP integration
mainMNE-CPP is a cross-platform C++ framework designed for MEG/EEG data acquisition, analysis, and visualization. Developers can integrate the MNE-CPP API into standalone projects to gain capabilities such as full I/O support for the FIF-file format or files generated by the MNE and FreeSurfer suites. It features a modular structure with sub-libraries and uses the Qt3D module for 3D visualization with OpenGL.Overview of estimating evoked responses
mainThese tutorials provide guidance on estimating evoked responses, which are defined as averages calculated across several repetitions of a specific experimental condition.Overview of MNE-Python preprocessing tutorials
mainMNE-Python provides a series of tutorials focused on preprocessing techniques for continuous neurophysiological data (such as EEG, MEG, etc.). These tutorials cover various methods for cleaning and preparing data, as well as diagnostic plotting methods to assess data quality during the preprocessing pipeline.Visualize EEG/MEG data with mne.viz
mainThe
mne.vizmodule provides a comprehensive suite of functions for visualizing neurophysiological data. Key visualization capabilities include:- Brain & Source Imaging: Functions like
plot_brain,plot_bem,plot_source_estimates, andplot_volume_source_estimatesfor 3D brain rendering and source localization. - Time-Series & Evoked Data: Use
plot_rawfor continuous data,plot_epochsfor epoch-based data, andplot_evoked(includingplot_evoked_topo,plot_evoked_topomap, andplot_evoked_field) for averaged responses. - Topographic Maps: Functions such as
plot_topomap,plot_projs_topomap, andplot_tfr_topomapfor spatial distribution visualization. - Sensor & Montage Layouts: Use
plot_sensors,plot_layout, andplot_montageto visualize electrode or sensor configurations. - ICA & Component Analysis: Functions like
plot_ica_components,plot_ica_sources, andplot_ica_propertiesfor inspecting Independent Component Analysis results. - 3D Rendering Control: Manage 3D visualization settings using
set_3d_backend,use_3d_backend,set_3d_options, andset_3d_view.
- Brain & Source Imaging: Functions like
Understand floating-point precision in MNE-Python
mainMNE-Python performs all in-memory computations using 64-bit double-precision floating point format (
float64). Data is typecast tofloat64immediately upon being read into memory to ensure accuracy during operations like filtering and preprocessing.Warning on Precision Loss: By default, MNE-Python writes
.fiffiles to disk using 32-bit format to reduce file size. If you save intermediate results to disk and reload them later, you may experience a loss in precision. To maintain 64-bit precision, you should either:- Chain operations in memory and avoid saving intermediate steps.
- Explicitly specify the 64-bit format when saving files.
Access and fetch datasets in mne.datasets
mainThe
mne.datasetsmodule provides utilities to check for the existence of datasets, fetch them from remote sources, and locate their local data paths.Key functions include:
fetch_dataset: Generic function to fetch specific datasets.has_dataset: Checks if a dataset is already available locally.default_path: Returns the default directory where MNE datasets are stored.
Many submodules (e.g.,
eegbci,sample,fsaverage,limo) provide specific loading or fetching functions to retrieve specialized neurophysiological data or anatomical templates.Compute inverse solutions using Beamformers
mainThemne.beamformermodule provides beamforming algorithms such as LCMV (Linearly Constrained Minimum Variance) and DICS (Dynamic Imaging Combinatorial Spectrum). It includes methods to create beamformers, apply them to data, and estimate resolution matrices.Understand the Signal-Space Projection (SSP) method
mainSignal-Space Projection (SSP) is a method used to reject external disturbances (noise) from MEG/EEG data without requiring additional reference sensors. It works by identifying a 'noise subspace'—a low-dimensional basis set of field patterns that characterize the external noise. An orthogonal complement operator (the signal-space projection operator) is then applied to the data to suppress these patterns.
Key considerations for effectiveness:
- Completeness: The basis set must completely characterize the disturbance field patterns; otherwise, noise will leak through.
- Orthogonality: The angles between the noise subspace and the brain signal vectors should be as close to $\pi/2$ as possible. If brain signals are close to the noise subspace, the signal itself will be attenuated.
- Inverse Solutions: Because SSP modifies signal vectors, the projection must also be applied to the forward solution during inverse computations.
Warning: SSP can remove both the artifact and the signal of interest. Always verify how much your signal of interest is reduced after applying SSP.
Core MNE-Python data containers: Raw, Epochs, Evoked, and Info
mainMNE-Python's core functionality revolves around four primary classes used to represent different stages of neurophysiological data processing:
io.Raw: Represents continuous data (e.g., long recordings from EEG, MEG, or ECoG).Epochs: Represents segmented data, where continuous data has been cut into time segments relative to specific events (e.g., stimulus onset).Evoked: Represents the average of multiple epochs, typically used to study event-related potentials (ERPs) or evoked responses.Info: A metadata object that describes the recording (e.g., channel types, sampling rate, channel locations, and coordinate systems) and is typically attached toRaw,Epochs, andEvokedobjects.
Read and write MNE data files
mainMNE-Python provides a wide range of
read_*andwrite_*functions to handle various neuroimaging data formats, including EEG, MEG, source estimates, and BEM surfaces. Common data types supported include:- Epochs and Evoked data:
read_epochs,read_evokeds,read_epochs_eeglab,read_epochs_fieldtrip,read_evokeds_fieldtrip,read_evokeds_mff. - Source Space and Estimates:
read_source_spaces,read_source_estimate,read_forward_solution. - Anatomical and Surface data:
read_surface,read_bem_surfaces,read_label,read_morph_map. - Transformations and Projections:
read_trans,read_proj. - Events:
read_events,write_events.
For most data types, there is a corresponding
write_*function to save processed data back to disk.- Epochs and Evoked data: