How to divide Epochs object into multiple smaller ones based on the number of the epoch?

MNE version: e.g. 1.3.1
operating system: Windows 11

Hello,
I have an Epoched object from a learning task. I would like to divide it so that the first 30 epochs (with the same event_id) go into one object, the second 30 into another one, and so on. I want to do this because I am interested in comparing the ERPs from different timepoints of the experiment.

Is there a way how to do this?

Thank you so much for your help.

Best wishes, Iva

Hello,

You can index on epochs, on both IDx and condition.

from mne import Epochs, find_events
from mne.datasets import sample
from mne.io import read_raw_fif


directory = sample.data_path() / "MEG" / "sample"
raw = read_raw_fif(directory / "sample_audvis_raw.fif", preload=False)
raw.pick_types(eeg=True, stim=True)
raw.load_data()

event_id = dict(left=1, right=2)
events = find_events(raw, stim_channel="STI 014")
epochs = Epochs(
    raw,
    events,
    event_id=event_id,
    tmin=-0.2,
    tmax=0.5,
    reject=None,
    preload=True,
)

There are 72 left epochs and 73 right epochs.

>>> epochs
<Epochs |  145 events (all good), -0.199795 - 0.499488 sec, baseline -0.199795 – 0 sec, ~34.6 MB, data loaded,
 'left': 72
 'right': 73>

To select the 30 first left epochs: epochs["left"][:30].

>>> epochs["left"][:30]
<Epochs |  30 events (all good), -0.199795 - 0.499488 sec, baseline -0.199795 – 0 sec, ~9.5 MB, data loaded,
 'left': 30>

To select the 30 first epochs, left or right: epochs[:30].

>>> epochs[:30]
<Epochs |  30 events (all good), -0.199795 - 0.499488 sec, baseline -0.199795 – 0 sec, ~9.5 MB, data loaded,
 'left': 15
 'right': 15>

And so on.

Mathieu

3 Likes

Thank you so much for your reply, Mathieu!