sappelhoff / pyprep

PyPREP: A Python implementation of the Preprocessing Pipeline (PREP) for EEG data
https://pyprep.readthedocs.io/en/latest/
MIT License
136 stars 33 forks source link

Add a "reject_by_annotation" parameter for finding bad channels #108

Open sappelhoff opened 2 years ago

sappelhoff commented 2 years ago

I think the functions to find noisy channels could benefit from a reject_by_annotation parameter, as used in MNE-Python.

It would mean that before working on the continuous raw data, raw.annotations are checked for any annotations starting with BAD, and cutting out these segments from the raw data.

This would be helpful for cases where you have raw data with long block breaks in which the participant moved etc. --> such "break" segments are not diagnostic for how noisy channels are, and could potentially even screw up the overall stats.

WDYT @a-hurst @yjmantilla ?

EDIT: The reject_by_annotation code in MNE happens at the raw.get_data level, see: https://github.com/mne-tools/mne-python/blob/c3ff05c05c7bfcf765249f27a517803f27f48b4e/mne/io/base.py#L918-L941

yjmantilla commented 2 years ago

@sappelhoff Sorry for the delay, as always and as everyone I have been extremely busy. I still have that worked example of pyprep's ransac vs autoreject's on the drawer.

Hmmm, If I remember correctly prep specifically mentions to not run this stuff on segmented data with discontinuities.

PREP is meant to work on data obtained from a continuous recording session. However, sometimes researchers record multiple sessions in the same file (such as by temporarily suspending and resuming recording). EEGLAB uses boundary events to mark these discontinuities. Some (but not all) EEGLAB functions respect these boundary markers. By default, the PREP pipeline will not process data sets with boundary markers. Because some researchers use these boundary markers for other purposes than for marking discontinuities, PREP allows the option of temporarily removing boundary markers before processing and then reinserting afterwards. You should not disregard boundary markers unless you are absolutely sure that these markers to not represent discontinuities.

Source: https://vislab.github.io/EEG-Clean-Tools/ , notice the bold section which is the same as bold in the source too.

Supposing we have a good argument to bypass this check, the idea is ok by me. Or implement this and also have the warning that this shouldnt be done for discontinuities in the documentation.