eelbrain.ChannelModel.find_bad_windows

ChannelModel.find_bad_windows(data, threshold=5e-05, max_exclude=0.25, window=1.0, hop=0.5, min_duration=0.1, merge_gap=None)[source]

Find the time windows in which each sensor is bad.

Like score(), but time-resolved: instead of flagging a channel for a whole epoch, the channel is scored within sliding time windows so that a bad channel is only flagged over the interval in which it is actually bad.

Parameters:
  • data (NDVar | str | list) – EEG data with the same sensors used for fitting; typically a list (or Datalist) of long, variable-length epochs (each sensor x time). A single continuous NDVar (sensor x time) or epoched NDVar (case x sensor x time) is also accepted.

  • threshold (float) – A channel is bad in a window when its error exceeds this absolute value (default 50 µV; see score()).

  • max_exclude (float) – Maximum number of channels to exclude per window (see score()).

  • window (float) – Length of the sliding scoring window in seconds (default 1.0).

  • hop (float) – Step between successive windows in seconds (default 0.5).

  • min_duration (float) – Discard bad windows shorter than this many seconds (default 0.1).

  • merge_gap (float | None) – Merge two bad windows of the same channel separated by less than this many seconds (default: window).

Returns:

windows – One list of BadChannelWindow per epoch (per case for an epoched NDVar; a single list for a continuous NDVar).

Return type:

Datalist | list

Notes

The data are scanned with a window of length window seconds, stepped by hop seconds. Within each window the step-down scoring of score() is applied, so every channel gets an error and hence a good/bad classification (bad when the error exceeds threshold) for that window, with at most max_exclude channels flagged per window. A time point is then considered bad for a channel if it is covered by any window in which that channel was classified bad; since each window’s verdict applies to the window’s full width and successive windows overlap (when hop < window), the bad time points form contiguous runs. Each run is returned as a BadChannelWindow, after discarding runs shorter than min_duration and merging runs of the same channel separated by less than merge_gap.

Because a window’s verdict spans its whole width, a localized artifact is bracketed by up to roughly one window length of margin on each side. window therefore effectively sets the amount of padding around detected artifacts, while hop controls how precisely the window edges are placed.