Saving Epoch error: No EEG channel found

Hey all!
I want to save my epochs on a disk, which worked fine.
However, when I try to reload the epochs I get the following error: ‘No EEG channel found. Cannot reject based on EEG.’

This is my code:

#define epoch
epochs = mne.Epochs(raw_filtered_notch_two, events_final, tmin=-0.1, tmax=1,
                    reject=reject_criteria_rough, decim = decim, baseline = None, preload=True, event_id = event_dict) #event_id = event_dict)

#apply ICA
ica = mne.preprocessing.ICA(n_components=0.99, max_iter='auto', method = 'infomax', random_state=97).fit(epochs)

ica.apply(epochs, exclude = eog_indices)

#Baseline correct epoch
inteval = (-0.1, 0)
epochs_bc = epochs.apply_baseline(inteval)

#convert Current Density
epochs_bc_csd = mne.preprocessing.compute_current_source_density(epochs_bc)

#save all epochs
epochs_bc_csd.save('epoch_' + participant_id + '_' + condition + '-epo.fif', overwrite= True)

When I try to load the epochs, I use:

epochs_from_file = mne.read_epochs('epoch_' + participant_id + '_' + condition + '-epo.fif', preload = True)

The error I get:

Reading /home/c12169374/EEG DATA/jpdoy/epoch/object/epoch_jpdoy_object-epo.fif.gz ...
    Found the data of interest:
        t =     -99.61 ...    1000.00 ms
        0 CTF compensation matrices available
0 bad epochs dropped
Not setting metadata
181 matching events found
No baseline correction applied
Traceback (most recent call last):

  File "/home/c12169374/EEG script/Preprocessing_script", line 317, in <module>
    epochs_from_file = mne.read_epochs('epoch_' + participant_id + '_' + condition + '-epo.fif.gz', preload = True)

  File "<decorator-gen-259>", line 12, in read_epochs

  File "/home/c12169374/anaconda3/lib/python3.9/site-packages/mne/epochs.py", line 3187, in read_epochs
    return EpochsFIF(fname, proj, preload, verbose)

  File "<decorator-gen-260>", line 12, in __init__

  File "/home/c12169374/anaconda3/lib/python3.9/site-packages/mne/epochs.py", line 3305, in __init__
    super(EpochsFIF, self).__init__(

  File "<decorator-gen-242>", line 12, in __init__

  File "/home/c12169374/anaconda3/lib/python3.9/site-packages/mne/epochs.py", line 569, in __init__
    self._reject_setup(reject, flat)

  File "/home/c12169374/anaconda3/lib/python3.9/site-packages/mne/epochs.py", line 773, in _reject_setup
    raise ValueError("No %s channel found. Cannot reject based on "

ValueError: No EEG channel found. Cannot reject based on EEG.

Any advice?

Hello and welcome to the forum!

What’s the output of:

print(epochs_bc_csd.reject)

just before saving?

Thanks,
Richard

PS: For better readability of code, simply select the code blocks / snippets with your mouse, and click on the “preformatted text” button in the toolbar (looks something like this: </>)

print(epochs_bc_csd.reject)
{‘eeg’: 0.00015}

1 Like

Thank you, this looks like a bug in MNE to me. I’ll try to look into this and get back to you in a few hours.

Thanks a lot Richard! Also thanks for the feedback on the readability of my code

1 Like

Hello, I’ve started working on a fix:

Until this is finished and has made it into a new release, I suggest you do the following to work around the issue for now:

either directly before calculating the CSD, or before saving the CSD epochs to disk, do:

del epochs_bc.reject['eeg']  # or epochs_bc_csd

The CSD function changes the eeg channel type to csd, causing a mismatch between the rejection thresholds in reject and the actual data, and this is what’s causing re-loading of the data to fail.

I hope this helps!

Richard

1 Like

@Evelyne_Fraats This has now been fixed in MNE-Python 1.0.3. Please see the changelog:

https://mne.tools/stable/whats_new.html#version-1-0-3-2022-05-12

1 Like