braindecode.preprocessing.RemoveBadWindows#
- class braindecode.preprocessing.RemoveBadWindows(*, max_bad_channels=0.25, zthresholds=(-inf, 7), window_len=1.0, window_overlap=0.66, max_dropout_fraction=0.1, min_clean_fraction=0.25, truncate_quant=(0.022, 0.6), step_sizes=(0.01, 0.01), shape_range=array([1.7, 1.85, 2., 2.15, 2.3, 2.45, 2.6, 2.75, 2.9, 3.05, 3.2, 3.35, 3.5]))[source]#
 - Remove periods with abnormally high-power content from continuous data.
 Implemented as in [Kothe2013].
This function cuts segments from the data which contain high-power (or low-power) artifacts. Specifically, only time windows are retained which have less than a certain fraction of bad channels, where a channel is bad in a window if its RMS power is above or below some z-score threshold relative to a robust estimate of clean-EEG power in that channel.
Note
When your method is meant to produce predictions for all time points in your continuous data (or all epochs of interest), you may not want to use this preprocessor, and enabling it may give you rosy performance estimates that do not reflect how your method works when used on gap-free data. It can nevertheless be useful to apply this to training data only in such cases, however, to get an artifact-unencumbered model.
Preconditions:
One of
RemoveDriftsorbraindecode.preprocessing.Filter( configured as a highpass filter) must have been applied beforehand.
- Parameters:
 max_bad_channels (int | float) – Threshold for rejection of bad time windows based on fraction of simultaneously noisy channels. This is the main tuning parameter; lower is more aggressive. Typical values are 0.15 (quite aggressive) to 0.3 (quite lax). Can also be specified as an absolute number of channels. Default is 0.25 (25% of channels).
zthresholds (tuple(float, float)) – (min, max) z-score tolerance for identifying bad time window/channel pairs. This typically does not need to be changed (instead one may change the max bad channels that cross this threshold), but different implementations use different values here. The max value is the main parameter, where EEGLAB/EEGPrep uses 7 while the original pipeline [1] used 5.5, and NeuroPype uses 6. Lower values are more aggressive. The min value is only triggered if the EEG data has signal dropouts (very low amplitude, e.g. due to something becoming unplugged) which is rare; some choices are (-inf, EEGPrep; -3.5, BCILAB; -4, NeuroPype).
window_len (float) – The window length that is used to check the data for artifact content, in seconds. This is ideally as long as the expected time scale of the artifacts, but short enough for there to be enough windows to compute statistics over. Default is 1.0 sec, but this may be lowered to 0.5 sec to catch very brief artifacts.
window_overlap (float) – Fractional overlap between consecutive windows (0-1). Higher overlap finds more artefacts but is slower. Default is 0.66 (about 2/3 overlap).
max_dropout_fraction (float) – Maximum fraction of windows that may have arbitrarily low amplitude (e.g. sensor unplugged). Default is 0.1.
min_clean_fraction (float) – Minimum fraction of windows expected to be clean (essentially uncontaminated EEG). Default is 0.25.
truncate_quant (tuple(float, float)) – Quantile range of the truncated Gaussian to fit (default (0.022,0.6)).
step_sizes (tuple(float, float)) – Grid-search step sizes in quantiles for lower/upper edge. Default is (0.01,0.01)
shape_range (sequence(float)) – Range for the beta shape parameter in the generalised Gaussian used for distribution fitting. Default is np.arange(1.7, 3.6, 0.15).
References
[Kothe2013]Kothe, C.A. and Makeig, S., 2013. BCILAB: a platform for brain–computer interface development. Journal of Neural Engineering, 10(5), p.056014.
Methods