CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-mne

MNE-Python provides comprehensive tools for analyzing MEG, EEG, and other neuroimaging data with advanced source estimation and connectivity analysis.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

MNE-Python

A comprehensive Python library for analyzing magnetoencephalography (MEG), electroencephalography (EEG), and other neuroimaging data. MNE-Python provides complete workflows from raw data processing through advanced source estimation and connectivity analysis, supporting over 20 file formats and offering both command-line tools and programmatic APIs.

Package Information

  • Package Name: mne
  • Language: Python
  • Installation: pip install mne
  • Documentation: https://mne.tools/

Core Imports

import mne

Common patterns for data loading and analysis:

import mne
from mne import read_raw_fif, create_info, EpochsArray
from mne.preprocessing import ICA
from mne.time_frequency import tfr_morlet
import numpy as np

Basic Usage

import mne
import numpy as np

# Load sample data
sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = (sample_data_folder / 'MEG' / 'sample' / 
                       'sample_audvis_filt-0-40_raw.fif')
raw = mne.io.read_raw_fif(sample_data_raw_file, preload=True)

# Basic preprocessing
raw.filter(1, 40, fir_design='firwin')  # Band-pass filter
raw.notch_filter(60)  # Remove line noise

# Create epochs around events
events = mne.find_events(raw)
epochs = mne.Epochs(raw, events, tmin=-0.2, tmax=0.5, preload=True)

# Compute evoked response
evoked = epochs.average()

# Visualize data
raw.plot()  # Interactive raw data browser
evoked.plot()  # Plot evoked response
evoked.plot_topomap()  # Topographic map

Architecture

MNE-Python follows a modular architecture organized around key data structures and processing stages:

  • Core Data Containers: Raw, Epochs, Evoked, Info objects store and manage neuroimaging data with rich metadata
  • I/O Module: Comprehensive support for 20+ file formats with unified interfaces
  • Preprocessing Pipeline: Filtering, artifact detection, ICA, Maxwell filtering, and signal space projection
  • Time-Frequency Analysis: Spectral estimation, wavelets, cross-spectral density, and connectivity
  • Source Analysis: Forward modeling, minimum norm estimation, beamforming, and dipole fitting
  • Statistical Framework: Cluster-based permutation testing and multiple comparisons correction
  • Visualization Engine: Interactive plotting, 3D brain visualization, and publication-quality figures

This design enables seamless data flow from raw recordings to publication-ready results while maintaining flexibility for custom analysis workflows.

Capabilities

Data Input/Output

Complete support for neuroimaging file formats including FIF, EDF, BrainVision, EEGLAB, CTF, KIT, and many others. Provides unified interfaces for reading, writing, and converting between formats.

def read_raw_fif(fname: str, preload: bool = False) -> Raw: ...
def read_raw_edf(fname: str, preload: bool = False) -> Raw: ...
def read_epochs(fname: str, preload: bool = True) -> Epochs: ...
def read_evokeds(fname: str) -> List[Evoked]: ...
def create_info(ch_names: List[str], sfreq: float, ch_types: Union[str, List[str]]) -> Info: ...
def find_events(raw: Raw, stim_channel: Optional[str] = None) -> ArrayLike: ...
def compute_covariance(epochs: Epochs, tmin: Optional[float] = None, tmax: Optional[float] = None) -> Covariance: ...

Data I/O

Data Preprocessing

Comprehensive preprocessing tools including filtering, artifact detection and removal, independent component analysis (ICA), Maxwell filtering, and signal space projection (SSP).

class ICA:
    def fit(self, inst: Union[Raw, Epochs], picks: Optional[Union[str, List]] = None) -> 'ICA': ...
    def apply(self, inst: Union[Raw, Epochs], exclude: Optional[List[int]] = None) -> Union[Raw, Epochs]: ...
    def find_bads_ecg(self, inst: Union[Raw, Epochs]) -> List[int]: ...

def maxwell_filter(raw: Raw, origin: Union[str, Tuple[float, float, float]] = 'auto') -> Raw: ...
def annotate_amplitude(raw: Raw, peak: Optional[float] = None) -> Annotations: ...

Preprocessing

Time-Frequency Analysis

Advanced spectral analysis including power spectral density estimation, time-frequency decomposition using wavelets and multitaper methods, and cross-spectral density computation.

def tfr_morlet(epochs: Epochs, freqs: ArrayLike, n_cycles: Union[float, ArrayLike]) -> AverageTFR: ...
def psd_welch(inst: Union[Raw, Epochs], fmin: float = 0, fmax: float = np.inf) -> Spectrum: ...
def csd_morlet(epochs: Epochs, frequencies: ArrayLike) -> CrossSpectralDensity: ...

class Spectrum:
    def plot(self, picks: Optional[Union[str, List]] = None) -> Figure: ...
    def plot_topomap(self, bands: Dict[str, Tuple[float, float]]) -> Figure: ...

Time-Frequency Analysis

Source Analysis and Inverse Solutions

Complete source analysis pipeline including forward modeling, boundary element modeling, minimum norm estimation, beamforming, and dipole fitting for localizing brain activity.

def make_forward_solution(info: Info, trans: Transform, src: SourceSpaces, bem: Union[str, BEM]) -> Forward: ...
def make_inverse_operator(info: Info, forward: Forward, noise_cov: Covariance) -> InverseOperator: ...
def apply_inverse(evoked: Evoked, inverse_operator: InverseOperator, lambda2: float) -> SourceEstimate: ...
def make_lcmv(info: Info, forward: Forward, data_cov: Covariance) -> Beamformer: ...

Source Analysis

Statistical Analysis

Statistical methods including cluster-based permutation testing, multiple comparisons correction, and specialized ERP analysis tools designed for neuroimaging data.

def permutation_cluster_test(X: ArrayLike, threshold: float, adjacency: Optional[ArrayLike] = None) -> Tuple: ...
def fdr_correction(pvals: ArrayLike, alpha: float = 0.05) -> Tuple[ArrayLike, float]: ...
def linear_regression(design_matrix: ArrayLike, data: ArrayLike) -> Dict: ...

Statistical Analysis

Visualization

Comprehensive visualization tools including interactive data browsers, topographic maps, 3D brain visualization, and publication-quality plotting functions.

def plot_topomap(data: ArrayLike, info: Info, **kwargs) -> Figure: ...
def plot_evoked_joint(evoked: Evoked, times: Optional[ArrayLike] = None) -> Figure: ...

class Brain:
    def __init__(self, subject: str, hemi: str, surf: str, subjects_dir: str): ...
    def add_data(self, array: ArrayLike, **kwargs) -> Brain: ...

Visualization

Machine Learning and Decoding

Machine learning tools for decoding neural signals including common spatial patterns (CSP), temporal decoding, encoding models, and cross-validation utilities.

class CSP:
    def fit(self, X: ArrayLike, y: ArrayLike) -> 'CSP': ...
    def transform(self, X: ArrayLike) -> ArrayLike: ...

class SlidingEstimator:
    def __init__(self, base_estimator, scoring: Optional[str] = None): ...
    def fit(self, X: ArrayLike, y: ArrayLike) -> 'SlidingEstimator': ...
    def predict(self, X: ArrayLike) -> ArrayLike: ...

Machine Learning

Sample Datasets

Built-in access to standard neuroimaging datasets for testing, tutorials, and benchmarking including sample MEG/EEG data, phantom measurements, and specialized datasets.

def data_path(path: Optional[str] = None, force_update: bool = False) -> str: ...
def load_data(path: Optional[str] = None) -> Dict: ...

# Available datasets
sample: SampleDataset
somato: SomatoDataset  
multimodal: MultimodalDataset
spm_face: SPMFaceDataset

Sample Datasets

Types

class Info:
    """Measurement information container with channel details and acquisition parameters."""
    ch_names: List[str]
    sfreq: float
    bads: List[str]
    def copy(self) -> 'Info': ...

class Raw:
    """Continuous data container with methods for filtering and preprocessing."""
    info: Info
    def load_data(self) -> 'Raw': ...
    def filter(self, l_freq: Optional[float], h_freq: Optional[float]) -> 'Raw': ...
    def plot(self, **kwargs) -> Figure: ...

class Epochs:
    """Epoched data container for event-related analysis."""
    info: Info
    events: ArrayLike
    def average(self) -> Evoked: ...
    def get_data(self) -> ArrayLike: ...

class Evoked:
    """Averaged evoked response container."""
    info: Info
    data: ArrayLike
    times: ArrayLike
    def plot(self, **kwargs) -> Figure: ...
    def plot_topomap(self, **kwargs) -> Figure: ...

class SourceEstimate:
    """Source-level activity estimates on cortical surface."""
    data: ArrayLike
    vertices: List[ArrayLike]
    tmin: float
    tstep: float
    def plot(self, **kwargs) -> Brain: ...

docs

data-io.md

datasets.md

index.md

machine-learning.md

preprocessing.md

source-analysis.md

statistics.md

time-frequency.md

visualization.md

tile.json