MNE-RT Logo

MNE-RT is an open-source Python library for real-time M/EEG signal processing and analysis, built on MNE-Python and MNE-LSL. It covers the full real-time pipeline — from amplifier to 3-D brain display, in a single, researcher-friendly API designed for neurofeedback, BCI, and clinical or basic-science monitoring applications.

Key capabilities#

Multiple real-time feature modalities — sensor power, ERD/ERS, Hjorth parameters, spectral centroid and peak, band ratio, cross-frequency coupling (CFC), connectivity, instantaneous phase (Hilbert analytic signal), graph-theory metrics, and more. See Real-time Feature Modalities for the full list.

Sensor and source-space processing using MNE inverse operators (eLORETA, MNE, dSPM). Compute and stream cortical-source activity.

Live artifact correctionORICA (online ICA), AdaptiveLMSFilter (adaptive least-mean-squares), GEDAIDenoiser (generalised eigendecomposition), ASRDenoiser (artifact subspace reconstruction), and RTMaxwellFilter (real-time Maxwell/SSS filtering for MEG). See Artifact Correction for algorithm details and benchmarks.

Real-time quality controlBadChannelDetector flags flat, noisy, or de-correlated channels every window using a robust rolling-vote mechanism. RiemannianPotatoDetector detects artifactual epochs by measuring Riemannian distance from a clean-data geometric mean on the SPD manifold.

Adaptive feedback protocolsThresholdProtocol, ZScoreProtocol, PercentileProtocol, LinearTrendProtocol (OLS-based trend reward — encourages sustained directional change rather than single-window threshold crossings), ShamProtocol (double-blind sham wrapper for within-session RCTs), UpDownStaircaseProtocol (adaptive psychophysics staircase converging to a target success rate), MultiBandProtocol (simultaneous two-band reward — e.g., alpha↑ + theta↓), RLProtocol (ε-greedy reinforcement-learning threshold search — fully self-calibrating), OperantProtocol (partial reinforcement schedules: FR, VR, FI, VI — wraps any inner protocol), and TransferProtocol (cross-session z-score seeded from a prior session file — zero warmup) give fine-grained control over when to issue a reward. See NF Protocols for formulas, selection guide, and examples.

Feature combiners — blend N parallel feature values into a single feedback score. WeightedSumCombiner (normalised weighted sum), GeometricMeanCombiner (weighted geometric mean — best for multiplicative power features), ZScoredNormCombiner (unit-free deviation-from-baseline Euclidean norm), and LearnedCombiner (any fitted sklearn-compatible estimator). See User Guide for usage examples.

Nine real-time visualisation windows — a scrolling NF NFPlot, a scrolling raw RawPlot (with bad-channel marking and bad-segment annotation), a continuous EpochPlot with trigger/epoch overlays, a live scalp TopomapPlot, an interactive BrainPlot (3-D cortical surface), a scalp-layout TopoPlot ERP display with ±SEM shading and re-referencing, an all-channel ButterflyPlot with region-colour coding, a per-channel CompareEvoked with peak markers, and a Morlet-wavelet TFRPlot (time-frequency heatmaps, induced or evoked mode). All plots update live and support EEG and MEG data.

Dual feedback output — broadcast values via OSC (Max/MSP, SuperCollider, TouchDesigner) with OSCSender, or over LSL with LSLSender for low-latency same-machine integration with PsychoPy, OpenViBE, BCI2000, and other LSL-aware apps.

CLI — launch full real-time M/EEG sessions with a single mne-rt run command, driven by a YAML config file. See CLI.

Quick install#

pip install mne-rt                 # core  (MNE, LSL, OSC included)
pip install "mne-rt[full]"         # + 3-D viz, dev tools, docs

See Installation for full instructions.

Quick start#

from mne_rt import RTStream

nf = RTStream(
    "sub01",
    session="01",
    subjects_dir="/data/subjects",
    montage="easycap-M1",
)
nf.connect_to_lsl(mock_lsl=True)          # or connect to a real amplifier
nf.record_main(
    duration=300,
    modality=["sensor_power", "erd_ers"],
    show_nf_signal=True,
)

Pipeline overview#

Stage Class / Function Notes
① Acquisition RTStream.connect_to_lsl() Hardware amplifier or mock replay via mne-lsl StreamInlet
② Baseline RTStream.record_baseline() Bad-channel detection · ICA · noise covariance · inverse operator
③ Quality control BadChannelDetector · RiemannianPotatoDetector Flags flat / noisy channels and artifactual covariance windows every epoch
④ Artifact correction ORICA · AdaptiveLMS · GEDAIDenoiser · ASRDenoiser · RTMaxwellFilter One or more methods selected per session; all operate sample-by-sample
⑤ Feature extraction record_main(modality=[…]) 20 feature modalities in sensor or source space; parallel thread-pool per window
⑥ Feedback protocol ThresholdProtocol · ZScoreProtocol · PercentileProtocol · LinearTrendProtocol · ShamProtocol · UpDownStaircaseProtocol · MultiBandProtocol · RLProtocol · OperantProtocol · TransferProtocol Maps feature value → output signal; all are stateful and adaptive
⑦ Visualisation NFPlot · RawPlot · EpochPlot · TopomapPlot · BrainPlot · TopoPlot · ButterflyPlot · CompareEvoked · TFRPlot Scrolling signal · epoch overlays · scalp topo · 3-D brain · scalp-layout ERP · butterfly overlay · per-channel comparison · TFR heatmaps
⑧ Feedback output OSCSender · LSLSender UDP/OSC to Max·MSP, SuperCollider, PD · LSL for PsychoPy, OpenViBE, BCI2000

Cite#

If you use MNE-RT, please cite [1].

Shabestari, P. S., Ribes, D., Défayes, L., Cai, D., Groves, E.,
Behjat, H. H., … & Neff, P. (2025). Advances on Real Time M/EEG
Neural Feature Extraction. IEEE CBMS 2025.
SNSF

Development was supported by the Swiss National Science Foundation (grant number — 208164).