Concatenate epochs based on epoch number

If you have a question or issue with MNE-Python, please include the following info:

  • MNE-Python version: 0.23
  • operating system: Win 10

Greetings,

Is it possible to concatenate epochs based on the epoch number?

I have extracted a subset of epochs based on event id to perform some preprocessing tasks and now I want to put them back in the same order. When I used mne.concatenate_epochs(), I couldn’t sort them based on the epoch number.

Regards,

Hello,

this is not trivial. When you subset epochs e.g. via epochs_subset = epochs['foo'], all epochs in epochs_subset that don’t match the specified criterion will be marked as IGNORED in epochs_subset.drop_log. You can use this information to find out the original indices:

# %%
from pathlib import Path
import mne


sample_dir = Path(mne.datasets.sample.data_path())
sample_fname = sample_dir / 'MEG' / 'sample' / 'sample_audvis_raw.fif'

raw = mne.io.read_raw_fif(sample_fname)
raw.crop(tmax=60)

events = mne.find_events(raw, stim_channel='STI 014')
event_id = {'auditory/left': 1, 'auditory/right': 2, 'visual/left': 3,
            'visual/right': 4, 'face': 5, 'buttonpress': 32}

epochs = mne.Epochs(raw, events=events, event_id=event_id,
                    tmin=-0.2, tmax=0.5, baseline=(None, 0),
                    preload=True)

# %%
e1 = epochs['auditory']
e2 = epochs['visual']

# %%
orig_idx_e1 = []
for idx, drop_reasons in enumerate(e1.drop_log):
    if 'IGNORED' not in drop_reasons:
        orig_idx_e1.append(idx)

orig_idx_e2 = []
for idx, drop_reasons in enumerate(e2.drop_log):
    if 'IGNORED' not in drop_reasons:
        orig_idx_e2.append(idx)

print(orig_idx_e1)
print(orig_idx_e2)

You can then probably use this info to fiddle the epochs back together in the desired order somehow. But this entire procedure is no fun…

Hello @richard,

Thank you for the help.

The goal of this step is to implement Autoreject() on multiple subset epochs based on events. I’m doing this to see if it would improve the results of a multi-class classification task.

I truly appreciate the time and effort you and the other developers put into helping all the users.

1 Like

Tagging @mainakjas, creator of autoreject

1 Like

Conversation happened on autoreject github :slight_smile: Thanks for tagging!

Mainak

1 Like