Loading...

MNE-Python

Open-source Python package for exploring, visualizing, and analyzing MEG and EEG data

Neuroscience-Specific Analysis Tools Advanced Analysis Software
Quick Info
  • Category: Neuroscience-Specific Analysis Tools
  • Level: Advanced
  • Type: Analysis Software
  • Requires:

Why We Recommend MNE-Python

MNE-Python provides a comprehensive, well-documented toolkit for processing electrophysiological data. It handles the full analysis pipeline from raw recordings to publication-ready results, with strong support for time-frequency analysis, source localization, and connectivity measures.

Common Use Cases

  • Process raw EEG/MEG recordings to clean, analyzed data
  • Perform time-frequency analysis and connectivity studies
  • Build encoding and decoding models for brain signals
  • Create publication-quality visualizations of brain activity

Getting Started

MNE-Python is an open-source Python package for exploring, visualizing, and analyzing human neurophysiological data (MEG, EEG, sEEG, ECoG, and more). It provides a complete pipeline from raw data to publication-ready figures.

Why MNE-Python?

  • Comprehensive: Full analysis pipeline in one package
  • Open Source: Free, transparent, and community-driven
  • Well-Documented: Extensive tutorials and examples
  • Publication-Ready: High-quality visualizations
  • Active Development: Regular updates and new features

Key Features

Data Import and Preprocessing

import mne

# Load raw data
raw = mne.io.read_raw_fif('data.fif', preload=True)

# Filter
raw.filter(l_freq=1.0, h_freq=40.0)

# Find and interpolate bad channels
raw.info['bads'] = ['EEG 001']
raw.interpolate_bads()

# Re-reference
raw.set_eeg_reference('average')

Epoching

# Create events from annotations
events, event_id = mne.events_from_annotations(raw)

# Extract epochs around events
epochs = mne.Epochs(
    raw, events, event_id,
    tmin=-0.2, tmax=0.5,
    baseline=(None, 0),
    preload=True
)

# Compute evoked responses
evoked = epochs.average()
evoked.plot()

Time-Frequency Analysis

from mne.time_frequency import tfr_morlet

# Compute power over time and frequency
freqs = np.arange(8, 40, 2)
power = tfr_morlet(
    epochs, freqs=freqs,
    n_cycles=freqs/2,
    return_itc=False
)
power.plot()

Source Localization

# Compute forward solution
fwd = mne.make_forward_solution(
    raw.info, trans, src, bem
)

# Inverse solution
inv = mne.minimum_norm.make_inverse_operator(
    raw.info, fwd, noise_cov
)

# Apply to data
stc = mne.minimum_norm.apply_inverse(evoked, inv)

Machine Learning

from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from mne.decoding import Vectorizer

# Build classifier
clf = make_pipeline(
    Vectorizer(),
    StandardScaler(),
    LogisticRegression()
)

# Decode from epochs
X = epochs.get_data()
y = epochs.events[:, -1]
clf.fit(X, y)

Analysis Pipeline

1. Preprocessing

  • Import raw data
  • Filter (highpass, lowpass, notch)
  • Mark and interpolate bad channels
  • Re-reference
  • ICA for artifact removal

2. Epoching

  • Define events of interest
  • Extract time-locked epochs
  • Reject bad trials
  • Baseline correction

3. Analysis

  • Evoked responses (ERPs)
  • Time-frequency representations
  • Connectivity analysis
  • Statistical testing

4. Visualization

  • Topographic maps
  • Source space plots
  • Time-frequency plots
  • Statistical clusters

Getting Started

Install MNE-Python:

conda install -c conda-forge mne
# or
pip install mne

Basic example:

import mne
from mne.datasets import sample

# Load sample data
data_path = sample.data_path()
raw_fname = data_path + '/MEG/sample/sample_audvis_raw.fif'
raw = mne.io.read_raw_fif(raw_fname, preload=True)

# Basic preprocessing
raw.filter(1, 40)
raw.set_eeg_reference('average')

# Visualize
raw.plot()

Tips

  • Start with tutorials on the MNE website
  • Use raw.info to check recording parameters
  • Always visualize data at each processing step
  • Use ICA to remove eye blinks and heartbeat
  • Leverage MNE’s interactive plotting tools
  • Check the MNE discourse forum for help
  • Consider using MNE-BIDS for data organization
Top