MNE-Python

1.12.0 · active · verified Sun Apr 12

MNE-Python is an open-source Python package for exploring, visualizing, and analyzing human neurophysiological data such as MEG, EEG, sEEG, ECoG, NIRS, and more. It provides modules for data input/output, preprocessing, visualization, source estimation, time-frequency analysis, connectivity analysis, machine learning, and statistics. The library is actively developed, with stable releases occurring frequently, typically every few months.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates loading a sample MEG/EEG dataset, applying a basic filter to the continuous data, defining events, creating epoched data, computing an evoked response, and finally plotting the evoked activity.

import mne
import numpy as np

# Set MNE_DATA for sample dataset (optional, will download if not found)
os.environ['MNE_DATA'] = os.environ.get('MNE_DATA', mne.utils.get_config('MNE_DATA', default=''))

# Load a sample dataset
data_path = mne.datasets.sample.data_path()
raw_fname = data_path / 'MEG' / 'sample' / 'sample_audvis_raw.fif'

# Read raw data
raw = mne.io.read_raw_fif(raw_fname, preload=True, verbose='error')
raw.filter(1, 40, fir_design='firwin')

# Set up events and epochs
events = mne.find_events(raw, stim_channel='STI 014')
event_id = {'aud/left': 1, 'aud/right': 2, 'vis/left': 3, 'vis/right': 4}
t_min, t_max = -0.2, 0.5
epochs = mne.Epochs(raw, events, event_id, t_min, t_max, preload=True, verbose='error')

# Compute evoked response
evoked = epochs['aud/left'].average()

# Plot evoked data
evoked.plot()

print(f"Processed data has {len(epochs)} epochs and {len(raw.ch_names)} channels.")

view raw JSON →