Choosing epochs between start and end index

Hello everyone!

Is there a way to choose all the epochs betwen two specific events? I have an ERP experiment where each new series of the task starts with different triggers (e.g. “start1”, “start2”, “start3”), but all the events have the same name of the triggers in all series.

Are there a way two choose all the events between “Start1” and “Start2” triggers?

Thanks!

Hi Ilya, welcome to the MNE forum!

yes, this is possible. are you working with Annotations or an events array? And does each task only happen once, or does e.g. “start1” occur a few times throughout the recording?

Hi!

“Start1”, “Start2” , “Start3” triggers appears only once, but other triggers, for the trials within series, are repeated several times. I can work with both Annotations (comes with an EEG file) and events (from mne.events_from_annotations).

OK, assuming you have events and events_id (the return values of mne.events_from_annotations) then you can do:

block_start_indices = dict()
for block in ('Start1', 'Start2', 'Start3'):
    block_start_indices[block] = np.searchsorted(events[:, 2], event_id[block])
# now you have a dictionary mapping block start identifiers to event array row numbers
# so e.g., you can create epochs for just the first block, like this:

block1_events = events[(block_start_indices['Start1'] + 1):block_start_indices['Start2']]
block1_epochs = Epochs(raw, events=block1_events, event_id=event_id, ...)
1 Like

Thanks a lot, everything worked!