Skip to content

Warn if event sample number is out of bound for raw when creating Epochs #12989

Description

@skjerns

Description of the problem

When creating Epochs by providing an events array that contains sample numbers outside of the data, the respective epochs are dropped, but no warning is given that sample numbers are actually out of bounds.

This can happen e.g. if events is in another sampling frequency as raw or if events contains sample numbers before first_sample.

related: https://mne.discourse.group/t/dropped-epochs-when-preload-true/2503

Steps to reproduce

import numpy as np
import mne

# Generate random data
data = np.random.randn(5, 1000)

# Create MNE info structure
ch_names = [f'EEG {i+1}' for i in range(5)]  # Channel names
info = mne.create_info(ch_names=ch_names, sfreq=100)

# Create RawArray
raw = mne.io.RawArray(data, info, first_samp=150)


events = np.array([[50, 0, 1],  # before first_samp
                   [500, 0, 2],  # works
                   [1100, 0, 3]])  # outside of data

epochs = mne.Epochs(raw, events=events, preload=True)

Expected results

I would expect that MNE warns me that the events array contains sample numbers that are out of bounds, instead of marking them as bad epochs.

Actual results

Out of bounds epochs are dropped.

3 matching events found
Setting baseline interval to [-0.2, 0.0] s
Applying baseline correction (mode: mean)
0 projection items activated
Using data from preloaded Raw for 3 events and 71 original time points ...
2 bad epochs dropped

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions