Skip to content

Channel cleaning and referencing

Detection and interpolation of bad EEG channels and re-referencing of electrophysiological data.

almkanal.almkanal_steps.channel_utils.EEGRANSAC

Bases: AlmKanalStep

Detect and interpolate bad EEG channels using RANSAC.

EEGRANSAC uses :class:autoreject.Ransac to identify EEG channels whose signals are poorly predicted from other EEG sensors. Continuous data are first split into fixed-length epochs for RANSAC fitting. Channels identified as bad are then marked in the original recording and interpolated using MNE.

Only EEG channels participate in RANSAC detection and interpolation. Existing bad channels of other channel types are preserved and excluded from the interpolation step.

Parameters:

Name Type Description Default
ransac_epoch_duration int | float

Duration, in seconds, of the fixed-length epochs created from the continuous recording for RANSAC fitting.

4
n_resample int

Number of random sensor subsets used by RANSAC to estimate channel predictability.

50
min_channels float

Fraction of available EEG channels used for robust reconstruction during each RANSAC resampling iteration.

0.25
min_corr float

Minimum correlation between the measured and RANSAC-predicted signal for a channel to be considered sufficiently predictable.

0.75
unbroken_time float

Fraction of time for which a channel may fall below min_corr before it is classified as bad.

0.4
n_jobs int

Number of parallel jobs used by :class:autoreject.Ransac.

1
verbose bool

Whether RANSAC should emit progress and diagnostic output.

False
Notes

The continuous recording is segmented into fixed-length epochs solely for RANSAC fitting. These temporary epochs are not returned and do not replace the continuous pipeline data.

Only EEG channels are retained in the temporary RANSAC epochs. ECG, EOG, MEG, and other channel types therefore do not contribute to the bad-channel detection procedure.

Previously marked bad channels are preserved when the newly detected EEG bad channels are added. During interpolation, previously bad non-EEG channels are explicitly excluded so that this step only repairs EEG channels.

Interpolation is performed on the supplied raw object using :meth:mne.io.Raw.interpolate_bads.

The processing metadata returned by :meth:run is stored under 'ransac_info' and contains the RANSAC epoch duration and effective RANSAC configuration.

EEGRANSAC may occur multiple times in a pipeline and is intended to run before ICA, forward modelling, spatial filtering, and source reconstruction.

See Also

autoreject.Ransac RANSAC implementation used for bad-channel detection. mne.make_fixed_length_epochs Create the temporary epochs used for RANSAC fitting. mne.io.Raw.interpolate_bads Interpolate channels marked as bad.

almkanal.almkanal_steps.channel_utils.ReReference

Bases: AlmKanalStep

Re-reference EEG, ECoG, sEEG, or DBS channels.

ReReference changes the reference of electrophysiological channels using :meth:mne.io.Raw.set_eeg_reference. It supports references based on one or more existing channels, average referencing, REST referencing, and explicit per-channel reference mappings.

Parameters:

Name Type Description Default
ref_channels str | list of str | dict

Reference specification passed to :meth:mne.io.Raw.set_eeg_reference.

Supported forms include:

  • 'average' to use the average of the selected channel type.
  • 'REST' to apply the Reference Electrode Standardization Technique.
  • A channel name or list of channel names defining the reference.
  • A dictionary mapping data-channel names to one or more reference channels, allowing different references for individual channels.
  • An empty list to leave the data unchanged.
'average'
projection bool

Whether an average reference should be added as a projection rather than applied directly to the data. When True with ref_channels='average', the projection is added but is not immediately applied. Other reference schemes require direct re-referencing.

False
ch_type str | list of str

Channel type or types to re-reference. Supported types include 'eeg', 'ecog', 'seeg', and 'dbs'. With 'auto', MNE selects the first supported channel type present in the recording.

'auto'
forward Forward | None

Forward solution used for REST referencing. Only relevant when ref_channels='REST'.

None
joint bool

Whether multiple channel types specified by ch_type should share a common reference. If False, referencing is handled separately for each channel type.

False
verbose bool | str | int | None

Verbosity setting passed to :meth:mne.io.Raw.set_eeg_reference.

False
Notes

Re-referencing is performed in place on the supplied raw object. The modified object is returned under 'data'.

Except when adding an average-reference projection, the data must be preloaded before the reference can be applied.

For average referencing, channels marked as bad in data.info['bads'] are excluded from the reference calculation by MNE.

REST referencing requires a suitable forward solution supplied through forward.

The processing metadata returned by :meth:run is stored under 'ref_info' and contains the reference channels, projection setting, channel types, forward solution, joint-reference setting, and verbosity configuration.

ReReference may occur multiple times in a pipeline and is intended to run before forward modelling, spatial filtering, and source reconstruction.

See Also

mne.io.Raw.set_eeg_reference Change the reference of channels in a raw recording. mne.set_eeg_reference General MNE function for re-referencing Raw, Epochs, or Evoked data.