Skip to content

clean_channels / clean_channels_nolocs / clean_windows: return the measured criteria, not only the result #535

Closed

Description

@neuromechanist

A pipeline that annotates data (rather than deleting it) needs to say why a channel or a window was flagged.
Today (eegprep 0.5.0):

import copy, numpy as np
from eegprep import clean_channels, clean_channels_nolocs, clean_windows, eeg_checkset, eeg_emptyset
rng = np.random.default_rng(0)
eeg = eeg_emptyset()
data = rng.standard_normal((1, 250 * 90)) + 0.3 * rng.standard_normal((8, 250 * 90))   # shared signal plus noise
eeg.update(data=data, nbchan=8, pnts=data.shape[1], trials=1, srate=250.0, xmin=0.0, xmax=(data.shape[1] - 1) / 250.0,
           chanlocs=[{"labels": f"Ch{i + 1}", "X": float(np.cos(i)), "Y": float(np.sin(i)), "Z": 0.5 + 0.05 * i} for i in range(8)])
eeg = eeg_checkset(eeg)
print(type(clean_channels(copy.deepcopy(eeg))).__name__)                    # dict
print(type(clean_channels_nolocs(copy.deepcopy(eeg))).__name__)             # tuple (EEG, removed mask)
print([type(x).__name__ for x in clean_windows(copy.deepcopy(eeg))])        # ['dict', 'ndarray'] (EEG, sample mask)
  • clean_channels returns only the dataset; the caller cannot tell which channels were removed except by comparing
    labels or reading EEG["etc"]["clean_channel_mask"], and cannot tell which criterion (correlation or noise) fired.
  • clean_channels_nolocs returns (EEG, removed) while clean_channels returns EEG only.
  • clean_windows returns the sample mask but not the per-window z-scores, the window offsets or how many channels
    exceeded the threshold in each window.

Expected: the same return shape for the two channel functions, and the measured quantities available (for example in
EEG["etc"]["clean_channels"] and EEG["etc"]["clean_windows"], or as an optional second return value): per-channel
correlation to the RANSAC estimate (or best pairwise correlation), per-channel noise z-score, number of flagged windows
per channel, and per-window z-scores with their start samples. Defaults unchanged.

Activity

  1. neuromechanist commented on Nov 5, 2026

    @neuromechanist
    MemberAuthor

    One more case for the same request, in clean_flatlines.
    When every channel has a flat-line portion it removes nothing, says so only through the logger, and returns the dataset unchanged with no mask in etc.
    A caller that annotates cannot tell "nothing was flat" from "everything was flat".

    import logging
    import numpy as np
    from eegprep import clean_flatlines, eeg_checkset, eeg_emptyset
    
    logging.basicConfig(level=logging.WARNING, format="%(name)s: %(message)s")
    logging.getLogger("eegprep.functions.adminfunc.eeg_checkset").setLevel(logging.ERROR)
    eeg = eeg_emptyset()
    data = np.full((4, 250 * 70), 5.0)                 # four channels, all constant
    eeg.update(data=data, nbchan=4, pnts=data.shape[1], trials=1, srate=250.0, xmin=0.0, xmax=(data.shape[1] - 1) / 250.0,
               chanlocs=[{"labels": f"Ch{i + 1}"} for i in range(4)])
    eeg = eeg_checkset(eeg)
    eeg["etc"] = {}
    out = clean_flatlines(eeg)
    print(out["nbchan"], sorted(out["etc"]))           # 4 []

    Observed on eegprep 0.5.0:

    WARNING (eegprep.plugins.clean_rawdata.clean_flatlines) All channels have a flat-line portion; not removing anything.
    4 []
    

    Expected: the flagged channels are available to the caller whether or not any is removed, for example EEG["etc"]["clean_channel_mask"] written on every call, or the mask returned as a second value like clean_windows does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions