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/JAMICA → ICLabel classification → dipole fitting → bad-channel interpolation → average re-reference. All steps are recorded in a provenance descriptor stored on the mne.io.Raw object.

Outputs are named after BIDS: get_derivative_paths() lists the derivative files written for a given fname_out, and the untouched input is written to the raw part of the BIDS dataset.

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

Preprocess EEG.

get_derivative_paths(fname_out)

Return the paths of all derivatives EEGPreprocessor writes.


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_pre_ica, raw_clean, ica, ...)

Build and return an mne.Report for EEGPreprocessor outputs.


Bad channel detection#

Standalone bad-channel detector that combines PyPREP (NaN/flat, deviation, high-frequency noise, correlation and RANSAC), FASTER’s correlation and variance criteria, and an optional line-noise z-score criterion. It works on a 1 Hz high-passed, average-referenced copy (flat channels are found before referencing) and warns when more than a fifth of the channels is flagged. 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 and optionally 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.

remove_line(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.


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.

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

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 motion capture channels in a Raw object, e.g. motion streams that XDFLoader merged into MultimodalRecording.raw as special streams. Channel names follow the <body>_quat_[xyzw], <body>_eul_[xyz] and <body>_pos_[xyz] convention.

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.