Description
When creating epochs from a subset of the given events (using the event_id argument), the epoch indexes correspond to the indexes from the original events array. Here's an example:
import numpy as np
from mne import Epochs, create_info
from mne.io import RawArray
from numpy.random import default_rng
n_channels = 3
duration = 25
sfreq = 250
data = default_rng(42).standard_normal(size=(n_channels, duration * sfreq)) * 5e-6
info = create_info(n_channels, sfreq, "eeg")
raw = RawArray(data, info)
n_events = 9
events = np.column_stack(
(
np.arange(1, n_events + 1) * sfreq,
np.zeros(n_events, dtype=int),
np.tile([1, 2, 3], n_events // 3),
)
)
epochs = Epochs(raw, events, event_id=2, tmin=-0.2, tmax=0.5)
epochs.plot()This results in three epochs with indexes [1, 4, 7], for example as shown in the x-axis labels of the epochs plot:
I think this behavior is not very intuitive, as users will probably expect epoch indexes to range from 0 to N - 1, i.e., [0, 1, 2] in this example.
My current workaround is to not use event_id at all, but pass a subset of the original events array. Although this works, it feels like there should be an easier option to achieve this behavior with event_id. For example, we could add a new parameter flatten_indexes=False (feel free to suggest a better name). WDYT?
Activity
larsoner commentedon Feb 11, 2026
I could see use cases where users might want what we currently do, and others might want them renumbered ascending.
Instead of a new constructor option (which already has too many options!) how about a
epochs.reset_indices()or similar? Maybe this will need to reset stuff likedrop_logetc., not sure...cbrnr commentedon Feb 11, 2026
Yes, this would work of course! I can take a stab and see what else needs to be changed.
cbrnr commentedon Feb 18, 2026
Could it be that
epochs.reset_drop_log_selection()already does what I want? When calling it at the end of the example,epochs.selectionchanges fromarray([1, 4, 7])toarray([0, 1, 2]).larsoner commentedon Feb 18, 2026
Could be. If so maybe we "just" need improved docs and discoverability
cbrnr commentedon Feb 18, 2026
The main problem I see is the name. I would have found what I needed if the method was called
reset_indexor similar, but the current name is a misnomer, at least in the context I was looking for (creating epochs has nothing to do, or should have nothing to do with dropping epochs). Therefore, I suggest we rename it, even if this means going through a deprecation cycle. "Just" changing the docs wouldn't help, because I would have never looked in this method.larsoner commentedon Feb 18, 2026
No need for deprecation cycle, keeping the old name around is close to zero maintenance cost so we should just
@legacydecorate it