mne_rt.tools.RTMaxwellFilter#
- class mne_rt.tools.RTMaxwellFilter(int_order: int = 8, ext_order: int = 3, origin: str | tuple = 'auto', st_duration: float | None = None, st_correlation: float = 0.98, st_update_interval: int = 1, calibration: str | None = None, cross_talk: str | None = None, coord_frame: str = 'head', regularize: str | None = 'in', mag_scale: float = 100.0)[source]#
Bases:
objectReal-time Maxwell filtering (SSS / tSSS) for streaming MEG data.
Pre-computes the Signal Space Separation (SSS) projection matrix [1] once from sensor geometry, then applies it as a single matrix multiply per incoming chunk — zero added latency, numerically equivalent to offline MNE. Temporal SSS (tSSS) [2] can optionally run on a rolling buffer to remove interference that leaks into the internal subspace.
See RTMaxwellFilter — Real-Time SSS / tSSS for the full mathematical background.
- Parameters:
- int_order
int, default 8 Internal spherical-harmonic expansion order. \(L_{\mathrm{in}} = 8\) → \((L+1)^2-1 = 80\) moments (MNE default, adequate for all standard MEG systems).
- ext_order
int, default 3 External expansion order (
3→ 16 external moments).- originarray_like
ofshape(3,) | “auto”, default “auto” SSS expansion origin in metres (head frame).
"auto"fits a sphere to the head digitisation; falls back to(0, 0, 0.04) mwhen digitisation is absent.- st_duration
float|None, defaultNone tSSS temporal buffer in seconds.
None→ spatial SSS only. Typical values: 10 s for persistent shielding leakage; 1–4 s for moving subjects.- st_correlation
float, default 0.98 Minimum inside–outside correlation for tSSS suppression. Lower values are more aggressive.
- st_update_interval
int, default 1 Apply tSSS every N incoming chunks. Increase to reduce CPU load when
winsizeis small; SSS is used between updates.- calibration
str|None, defaultNone Fine-calibration
.datfile (Elekta/MEGIN). Corrects sensor position and orientation errors; typically improves noise floor by 10–20 %.- cross_talk
str|None, defaultNone Cross-talk compensation
.fiffile. Compensates flux leakage between adjacent sensors.- coord_frame{“head”, “meg”}, default “head”
Coordinate frame for the spherical-harmonic expansion.
- regularize{“in”,
None}, default “in” Internal-moment Tikhonov regularisation passed to MNE.
- mag_scale
float, default 100.0 Magnetometer/gradiometer balance factor.
- int_order
- Raises:
ImportErrorIf MNE-Python is not installed.
ValueErrorIf no MEG channels are found in the supplied info.
RuntimeErrorIf
transform()is called beforefit().
See also
mne.preprocessing.compute_maxwell_basisUnderlying SSS basis function.
mne.preprocessing.maxwell_filterFull offline Maxwell filtering.
mne_rt.RTStream.fit_maxwellFit from a connected MEG session.
Notes
No baseline recording is required. The SSS operator depends only on sensor geometry, not on brain signal statistics. Simply call
connect_to_lsl()thenfit_maxwell().References
Examples
SSS-only (fastest, no latency):
>>> rt_mf = RTMaxwellFilter() >>> rt_mf.fit(raw.info) >>> clean = rt_mf.transform(meg_chunk)
tSSS with fine calibration and empty room:
>>> rt_mf = RTMaxwellFilter(st_duration=10.0, calibration="sss_cal.dat") >>> rt_mf.fit(raw.info, empty_room_raw=er_raw) >>> clean = rt_mf.transform(meg_chunk)
Added in version 1.0.0.
- __init__(int_order: int = 8, ext_order: int = 3, origin: str | tuple = 'auto', st_duration: float | None = None, st_correlation: float = 0.98, st_update_interval: int = 1, calibration: str | None = None, cross_talk: str | None = None, coord_frame: str = 'head', regularize: str | None = 'in', mag_scale: float = 100.0) None[source]#
Methods
__init__([int_order, ext_order, origin, ...])fit(info[, empty_room_raw])Pre-compute the SSS projection operator from MEG sensor geometry.
transform(data)Apply Maxwell filtering to a streaming MEG window.
Attributes
Operating mode:
"sss"or"tsss".Cached SSS matrix, shape (n_meg_all, n_meg_good).
- fit(info, empty_room_raw=None) RTMaxwellFilter[source]#
Pre-compute the SSS projection operator from MEG sensor geometry.
No data is required — the operator depends only on sensor positions. An optional empty-room recording adds noise-informed regularisation.
- Parameters:
- info
mne.Info MEG measurement info with sensor positions and the device-to-head transform (
dev_head_t).- empty_room_raw
mne.io.Raw|None, defaultNone Empty-room recording in the same coordinate frame. When given, the operator is extracted via system identification so that noise-informed regularisation is built into the cached matrix (see class docstring).
Noneuses geometric regularisation only viacompute_maxwell_basis().
- info
- Returns:
- self
RTMaxwellFilter
- self
- transform(data: ndarray) ndarray[source]#
Apply Maxwell filtering to a streaming MEG window.
- Parameters:
- data
ndarray,shape(n_channels,n_samples) Raw MEG window. Non-MEG channels are passed through unchanged.
- data
- Returns:
- clean
ndarray,shape(n_channels,n_samples) SSS- or tSSS-cleaned data.
- clean
- Raises:
RuntimeErrorIf
fit()has not been called.