Extract remaining events after epoching

Hello,

I am trying to extract the list of events that are present once I have epoched the data. I have toyed around with the reject/flat criteria which removes some epochs, but I can’t easily see what trials were removed or which remain. The drop_log() function shows which electrodes cause an epoch to be dropped, but not the events which pertain to that epoch.

I can visualize the remaining events through epochs.plot() when I pass the original event array, and only those events relevant to the remaining epochs are shown. The window title also shows the number of epochs for each condition which are available. So there is information present, but I’d like to know how to get this information out to a separate array, .e.g., events_epo, the array of events represented in the epoched data.

One idea that comes to mind is to somehow extract the events that appear when plotting the epoched data and then computing the difference between this subset events_epo and the original event array events to see which trials have been removed.

In the original experiment, every item had a unique trigger code, 30 to 119. It would be useful to see then:

  1. The trial order for that participant of all remaining trials after the various steps of exclusion (manual exclusion due to performance, or later rejection during epoching with rejection/flat criteria).
  2. The retained trials in order to easily see what has been removed (I assume by passing the array created above in 1 and applying sort()?).

Any insights would be much appreciated.

mne 1.9.0
macOS 15.2

As you say, epochs.drop_log contains the information about which channel(s) caused the epoch to be dropped. You can use this information to find out which epochs were dropped. Here is a quick example on the sample dataset:

import mne
raw = mne.io.read_raw_fif(mne.datasets.sample.data_path() / "MEG" / "sample" / "sample_audvis_raw.fif")
events = mne.find_events(raw)
reject = dict(eog=100e-6)  # this will cause some epochs to be dropped
epochs = mne.Epochs(raw, events, reject=reject, preload=True)

# To figure out which epochs were dropped and which were kept
epochs_dropped = [i for i, reason in enumerate(epochs.drop_log) if len(reason) > 0]
epochs_kept = [i for i, reason in enumerate(epochs.drop_log) if len(reason) == 0]

# Find the corresponding events
events_dropped = events[epochs_dropped]
events_kept = events[epochs_kept]

Hope that helps!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.