Is mne.make_fixed_length_events working properly?

  • MNE version: e.g. 0.24.0
  • operating system: Windows 10

Dear all,

I was testing “mne.make_fixed_length_events” on the database “sample_audvis_filt-0-40_raw.fif”.

“eventsTest_raw” is the object that I’ve reduced to only EEG data, and cropped from second 4 to second 14.


new_events = mne.make_fixed_length_events(eventsTest_raw, start=1, stop=9, duration=1., overlap=0.5)  
mne.viz.plot_events(new_events, sfreq=eventsTest_raw.info['sfreq']) # plot events

Looking at the plot represented above in figure something weird happened.
First because, as anticipated and showed by the below figure, data have been cropped, and should have a total duration of 10 seconds.

I do not understand why the events do not start from second 1, but around second 48.
In addition, it is not clear because now I have only 10 seconds of recording, it does not even reach such a long duration.
I understand that the issue is in “new_events”, as shown below (sample rate was around 150Hz)

image

What do you think about it? Thanks in advance

does https://mne.tools/stable/glossary.html#term-first_samp help?

Alex

1 Like

Thank you, setting “first_samp=False”, the positions of the events is now fine, as you can see in the upper part of the screenshot.
Neverthelss, while plotting the epochs I get a blank figure (bottom part of the screenshot) and the following error:

"Not setting metadata
Not setting metadata
10 matching events found
Applying baseline correction (mode: mean)
0 projection items activated
Loading data for 10 events and 151 original time points ...
10 bad epochs dropped"
....
....
    xlim = epoch_times[-1] + len(orig_epoch_times)
IndexError: index -1 is out of bounds for axis 0 with size 0

Here the code:

eventsTest_raw = raw_filtered.copy()
event_id = {'My Event': 1}
new_events = mne.make_fixed_length_events(eventsTest_raw, start=0, duration=1., overlap=0., first_samp=False) # overlap=0.5
mne.viz.plot_events(new_events, sfreq=eventsTest_raw.info['sfreq']) # plot events
epochs = mne.Epochs(eventsTest_raw, new_events, event_id, tmin=0, tmax=1,baseline=(0, 0), preload=True)  
mne.viz.plot_epochs(epochs) # plot epochs

So, at the moment, I’m not able to set epochs.
I’ve also read this post where you @agramfort answered on a similar topic because I was searching for a way to reset the “first samp” that maybe would have fixed the issue on the epochs creation, but I did not understand how to use " RawArray" for this…
What should I do? Thanks in advance

Just to summarize, I’d simply need to:

  • Work on 10 seconds interval of the sample EEG recording (I did it using “crop”)
  • Create the following epochs: (0-1 s | 1-2 s | 2-3 s … 9-10 s)
    thanks

After running this line, could you please run:

epochs.plot_drop_log()

This should indicate why the epochs where actually dropped.

Thanks!

Edit

I believe you shouldn’t pass first_samp=False when creating the events. Instead, you should only pass this parameter during plotting.

For creating and visualizing the epochs, you would do:

new_events = mne.make_fixed_length_events(eventsTest_raw, start=0, duration=1., overlap=0.) # overlap=0.5
epochs = mne.Epochs(eventsTest_raw, new_events, event_id, tmin=0, tmax=1,baseline=(0, 0), preload=True)
epochs.plot()
1 Like

Thanks @richard and @agramfort .

I’m agree that “first_samp=False” generates the error. I was a bit confused while plotting the events using

mne.viz.plot_events(new_events, sfreq=eventsTest_raw.info['sfreq'])

because the event plot showed a timeline outside the cropped data.
However, when plotting the epochs everything is fine. Thanks