Discrepancy with epochs numbering with plotting epochs with ICA sources

MNE 1.7.1

When I plot error with epochs.plot() epochs are numbered starting from 1, when plot ICA sources with ica.plot_sources(epochs) epochs numbering starts from 0.

This might be error prone, I spent last hour trying to debug some unexpected results because of this.

Also autoreject library is indexing epochs from 0 which add to the confusion

@danieltomasz Are you sure the first epoch wasn’t dropped when you plotted your epochs? We generally start indexing everything at zero, including epochs.

@richard thanks for a quickly reply, you are right that the first epoch was dropped.

I had set reject by annotation to reject_by_annotation=True when creating epochs and this was proabably reason of removing epoch nr 0.
is there a way to reset numbering of epochs after creating them?
This is confusing, like my orginal case with ICA or with autoreject as well.
as a step, I am running autoreject to find bad epochs

auto_reject_pre_ica = autoreject.AutoReject(**auto_reject_params).fit(epochs[:20])
epochs_ar, reject_log = auto_reject_pre_ica.transform(epochs, return_log=True)
reject_plot = reject_log.plot("vertical")

And it gives me among other things this line

Dropped 11 epochs: 6, 18, 29, 36, 37, 50, 51, 60, 64, 65, 66

but when I plot them

scalings = dict(eeg=40e-6)
epochs[reject_log.bad_epochs].plot

in plot bad epochs are starting from 7, 19 …. (because now the 0 indexed epoch in Epochs has number 1)

I my pipeline I manually check the bad epochs from autoreject and sometimes remove more bad epochs before ica, having this double numbering may lead me into confusion/errors (however I can understand why this is happening)

1 Like

I was creating epochs from resting state via

events = mne.make_fixed_length_events(
    raw=raw,
    start=0,
    stop=None,
    duration=5,
    overlap=1.5,
    first_samp=True,
)

The culprit was first_samp=`False’ causing first epoch to be dropped.

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