mne
MNE - Neurophysiology Analysis
MNE provides sophisticated tools for filtering brain signals, epoching data, and performing source localization (mapping signals back to brain anatomy).
When to Use
- Processing EEG/MEG recordings from clinical or research studies.
- Analyzing event-related potentials (ERPs).
- Source localization (finding where in the brain signals originate).
- Connectivity analysis between brain regions.
- Preprocessing neurophysiological data for machine learning.
Core Principles
Raw → Epochs → Evoked
The standard pipeline: continuous raw data → segmented epochs → averaged evoked responses.
Sensor Space vs. Source Space
Sensor space: signals at electrodes. Source space: signals reconstructed at brain locations.
Frequency Analysis
Brain signals are analyzed in frequency bands (delta, theta, alpha, beta, gamma).
Quick Reference
Standard Imports
import mne
import numpy as np
Basic Patterns
# 1. Load data
raw = mne.io.read_raw_fif("sample_audvis_raw.fif")
# Or: raw = mne.io.read_raw_edf("eeg.edf")
# 2. Filter and cleaning
raw.filter(l_freq=1, h_freq=40) # Bandpass filter
raw.notch_filter(freqs=[50, 100]) # Remove power line noise
# 3. Find events and create Epochs
events = mne.find_events(raw)
epochs = mne.Epochs(raw, events, event_id={'stimulus': 1}, tmin=-0.2, tmax=0.5)
epochs.average().plot() # Plot Evoked potential
# 4. Frequency analysis
epochs.compute_psd().plot()
Critical Rules
✅ DO
- Filter before epoching - Apply filters to continuous data, not epochs.
- Check data quality - Use
raw.plot()to visually inspect for artifacts. - Set montage - Assign electrode positions for proper visualization.
- Reject bad epochs - Remove epochs with artifacts before averaging.
❌ DON'T
- Don't filter too aggressively - Over-filtering removes signal along with noise.
- Don't ignore reference - EEG signals are relative. Know your reference electrode.
- Don't mix sampling rates - Ensure all channels have the same sampling rate.
Advanced Patterns
Source Localization
# Compute forward solution and inverse
fwd = mne.make_forward_solution(raw.info, trans, src, bem)
inv = mne.minimum_norm.make_inverse_operator(raw.info, fwd, cov)
stc = mne.minimum_norm.apply_inverse(evoked, inv)
stc.plot()
Connectivity Analysis
from mne.connectivity import spectral_connectivity
# Compute connectivity between channels
con, freqs, times, n_epochs, n_tapers = spectral_connectivity(
epochs, method='coh', mode='multitaper')
MNE is the gold standard for neurophysiological data analysis, enabling researchers to extract meaningful insights from the complex signals of the human brain.
More from tondevrel/scientific-agent-skills
xgboost-lightgbm
Industry-standard gradient boosting libraries for tabular data and structured datasets. XGBoost and LightGBM excel at classification and regression tasks on tables, CSVs, and databases. Use when working with tabular machine learning, gradient boosting trees, Kaggle competitions, feature importance analysis, hyperparameter tuning, or when you need state-of-the-art performance on structured data.
197opencv
Open Source Computer Vision Library (OpenCV) for real-time image processing, video analysis, object detection, face recognition, and camera calibration. Use when working with images, videos, cameras, edge detection, contours, feature detection, image transformations, object tracking, optical flow, or any computer vision task.
144ortools
Google Optimization Tools. An open-source software suite for optimization, specialized in vehicle routing, flows, integer and linear programming, and constraint programming. Features the world-class CP-SAT solver. Use for vehicle routing problems (VRP), scheduling, bin packing, knapsack problems, linear programming (LP), integer programming (MIP), network flows, constraint programming, combinatorial optimization, resource allocation, shift scheduling, job-shop scheduling, and discrete optimization problems.
75matplotlib
The foundational library for creating static, animated, and interactive visualizations in Python. Highly customizable and the industry standard for publication-quality figures. Use for 2D plotting, scientific data visualization, heatmaps, contours, vector fields, multi-panel figures, LaTeX-formatted plots, custom visualization tools, and plotting from NumPy arrays or Pandas DataFrames.
73plotly
A high-level interactive graphing library for Python. Ideal for web-based visualizations, 3D plots, and complex interactive dashboards. Built on plotly.js, it allows users to zoom, pan, and hover over data points in a browser-based environment. Use for interactive charts, web applications, Jupyter notebooks, 3D data visualization, geographic maps, financial charts, animations, time-series analysis, and building production-ready dashboards with Dash.
54scipy
Comprehensive guide for SciPy - the fundamental library for scientific and technical computing in Python. Use for integration, optimization, interpolation, linear algebra, signal processing, statistics, ODEs, Fourier transforms, and advanced scientific algorithms. Built on NumPy and essential for research and engineering.
51