NDCLab / pepper-pipeline

tool | Python Easy Pre-Processing EEG Reproducible Pipeline
GNU Affero General Public License v3.0
3 stars 3 forks source link

Ica_raw() rejects all epochs #370

Closed F-said closed 2 years ago

F-said commented 2 years ago

Describe the bug Function ica.fit(epochs_prep) on line 209 occasionally rejects all epochs, such that epochs.events is empty. Results in pipeline crash.

438 bad epochs dropped
Fitting ICA to data using 122 channels (please be patient, this may take a while)
Traceback (most recent call last):
  File "run.py", line 39, in <module>
    eeg_obj, outputs[idx] = getattr(pre, func)(eeg_obj, **params)
  File "/home/data/NDClab/tools/pepper-pipeline/scripts/preprocess/preprocess.py", line 211, in ica_raw
    ica.fit(epochs_prep)
  File "<decorator-gen-420>", line 24, in fit
  File "/usr/local/lib/python3.8/dist-packages/mne/preprocessing/ica.py", line 574, in fit
    self._fit_epochs(inst, picks, decim, verbose)
  File "/usr/local/lib/python3.8/dist-packages/mne/preprocessing/ica.py", line 621, in _fit_epochs
    raise RuntimeError('Tried to fit ICA with epochs, but none were '
RuntimeError: Tried to fit ICA with epochs, but none were found: epochs.events is "[]".

Expected behavior Either a skip or some resolution should be implemented.

F-said commented 2 years ago

Potential Solutions

georgebuzzell commented 2 years ago

Pasting in comments to @yanbin-niu made on slack (sorry, we should stop discussing on slack and keep our discussions on here!) :)

image image image image

@DMRoberts @F-said comments/thoughts welcome!!

georgebuzzell commented 2 years ago

Hey @yanbin-niu looking at this again... I wonder if there might actually be a dc offset that is accounting for this. I.e. for the period where the data is all at greater than -1000 the variation is still in the normal range.

Is it possible that the highpass filter has an issue? I.e. not actually filtering at the freqs we want. Or, perhaps the filter is being run across discontinuous segments, causing the issue? Is the highpass run for just a single continuous segment?

Lastly, I think if we remove the mean amplitude of each epoch prior to the threshold rejection, this should solve the issue.

@DMRoberts thoughts?

georgebuzzell commented 2 years ago

@yanbin-niu actually, I believe it is typically not recommended to remove the baseline prior to ica. So, we should really try to tackle this from the filter side. It seems to me that the issue may likely be in the filter somewhere. Either the highpass is not filtering at the proper pass/stob band, or, there is an issue of filtering over discontinuities. I think...

F-said commented 2 years ago

resolved