Preprocessing#

The preprocessing module covers the full EEG pipeline, epoch preparation, rigid-body motion kinematics, and a set of lower-level signal-processing utilities that the pipeline calls internally but which are also usable standalone.


EEG pipeline#

EEGPreprocessor orchestrates the full pipeline: ZapLine → bad-channel detection → bandpass filter → ASR → ICA/AMICA → ICLabel classification → dipole fitting → average re-reference → bad-channel interpolation. All steps are recorded in a provenance descriptor stored on the mne.io.Raw object.

EEGPreprocessor(loader, *[, channel_types, ...])

Preprocess EEG.


Reporting#

Builds an mne.Report summarising a single EEGPreprocessor run (bad channels, ICA, dipoles, and full-length stream traces for drop-out inspection). Called automatically by EEGPreprocessor.run_raw() when make_report=True (the default); can also be called directly on saved pipeline outputs.

make_report(raw_minimal, raw_clean, ica, ...)

Build and return an mne.Report for EEGPreprocessor outputs.


Bad channel detection#

Standalone bad-channel detector that combines PyPREP, FASTER, per-channel flatline detection, and a line-noise z-score criterion. Called automatically by EEGPreprocessor but can also be run on any mne.io.Raw object directly.

get_bad_chs(raw[, pyprep_kwargs, ...])

Detect bad EEG channels using PyPREP, FASTER, flatline, and line noise.


Signal cleaning#

Individual signal-processing steps that EEGPreprocessor calls internally. Useful when building a custom pipeline or applying a single step in isolation.

compute_zapline(raw, noise_freqs[, method, ...])

Remove spectral line noise from EEG using ZapLine (DSS-based).

compute_asr(raw[, cutoff, estimator])

Apply ASR to the EEG channels of raw.

compute_ica(raw[, filter_bands_ica, ...])

Fit ICA on a filtered copy of raw and label components with ICLabel.

detect_bad_by_line_noise(raw, noise_freqs[, ...])

Detect channels with abnormally high line noise power.

compute_mi_reduction(raw_before, raw_after)

Total pairwise MI reduction under the Gaussian approximation.

get_raw_subset(raw[, subset_chs])

Return a copy of raw containing only the requested subset of channels.


Dipole fitting#

fit_dipoles_on_ica(ica, info[, trans, ...])

Fit one or two dipoles to each ICA component topography.

compute_dipolarity(components, info[, ...])

Fraction of ICA topographies with dipole residual variance below rv_thresh.

auto_coreg_fsaverage(info, subjects_dir[, ...])

Automatically coregister head to fsaverage MRI and return the transform.


Epoching#

Helpers for converting continuous preprocessed data into epochs, including stimulus-label renaming utilities for common BPN paradigms.

EpochPreparer(remaps, *[, epoch_tlimes, ...])

Prepare condition-specific epochs from a cleaned raw recording.

get_stimulus_rename_map(descriptions)

Build an event rename map from trialStart annotation descriptions.


Motion capture#

Rigid-body kinematics from XDF motion streams. Works on the motion data returned by XDFLoader in motion.

find_rigid_bodies(raw)

Detect rigid body names from channel naming conventions.

process_rigid_body(raw[, rb_names, ...])

Process rigid body motion capture streams.

split_by_rigid_body(raw[, rb_names])

Return a dict of per-rigid-body Raw sub-objects.


Provenance#

Lightweight provenance tracking: each pipeline step appends a JSON-serialisable descriptor to mne.Info.description so that any saved file carries a record of exactly how it was processed.

init_descriptor([source, pipeline])

Initialise a provenance descriptor dict for a processing run.

set_descriptor(raw, descriptor)

Serialise descriptor and store it in raw.info['description'].

get_descriptor(raw)

Return the provenance descriptor stored in raw, or None.

append_desc(raw, name, **kwargs)

Append a named processing step to the provenance descriptor.

sig_params(func, **kwargs)

Return only the kwargs that match func's signature.


Utilities#

StepTimer([logger])

Record and log wall-clock durations of named pipeline steps.

format_duration(seconds)

Format a duration in seconds as a compact human-readable string.

build_sys_info([source_data])

Return a string with full environment and version information.