# Is mne.make\_fixed\_length\_events working properly?

**URL:** <https://mne.discourse.group/t/is-mne-make-fixed-length-events-working-properly/6172>\
**Category:** Support & Discussions\
**Created:** [January 9, 2023, 5:29pm UTC](https://mne.discourse.group/t/is-mne-make-fixed-length-events-working-properly/6172 "2023-01-09T17:29:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![BaggioMarco](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/baggiomarco/32/190_2.png) [@BaggioMarco](https://mne.discourse.group/u/BaggioMarco)\
**Post date:** [January 9, 2023, 5:29pm UTC](https://mne.discourse.group/t/is-mne-make-fixed-length-events-working-properly/6172/1 "2023-01-09T17:29:03Z")

</div>

- 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.**

```python

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

```

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/a/ae974117a745798a5db487a0dc76cb239bd8ffeb.png)

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.

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/6/64e321fc32909d40a95c3ad666127aacc9af3d92.png)

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](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/d/dff2e5a5afe6baeb075ba95e75ab04f66df7d123.png)

What do you think about it? Thanks in advance

---

<div class="post-metadata">

**Author:** ![agramfort](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@agramfort](https://mne.discourse.group/u/agramfort)\
**Post date:** [January 9, 2023, 7:44pm UTC](https://mne.discourse.group/t/is-mne-make-fixed-length-events-working-properly/6172/2 "2023-01-09T19:44:01Z")

</div>

does [https://mne.tools/stable/glossary.html#term-first\_samp](https://mne.tools/stable/glossary.html#term-first_samp) help?

Alex

---

<div class="post-metadata">

**Author:** ![BaggioMarco](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/baggiomarco/32/190_2.png) [@BaggioMarco](https://mne.discourse.group/u/BaggioMarco)\
**Post date:** [January 10, 2023, 9:48am UTC](https://mne.discourse.group/t/is-mne-make-fixed-length-events-working-properly/6172/3 "2023-01-10T09:48:51Z")

</div>

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:

```python
"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:

```python
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

```

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/c/cce0b7e30b31b06c3f03f9f754fe9dc5c3d31b80.png)

So, at the moment, I’m not able to set epochs.  
I’ve also read this [post](https://github.com/mne-tools/mne-python/issues/9759) 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

---

<div class="post-metadata">

**Author:** ![BaggioMarco](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/baggiomarco/32/190_2.png) [@BaggioMarco](https://mne.discourse.group/u/BaggioMarco)\
**Post date:** [January 10, 2023, 10:10am UTC](https://mne.discourse.group/t/is-mne-make-fixed-length-events-working-properly/6172/4 "2023-01-10T10:10:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [January 10, 2023, 2:32pm UTC](https://mne.discourse.group/t/is-mne-make-fixed-length-events-working-properly/6172/5 "2023-01-10T14:32:51Z")

</div>

> [@BaggioMarco](#):
>
> ```python
> epochs = mne.Epochs(eventsTest_raw, new_events, event_id, tmin=0, tmax=1,baseline=(0, 0), preload=True)  
> 
> ```

After running this line, could you please run:

```python
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:

```python
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()

```

---

<div class="post-metadata">

**Author:** ![BaggioMarco](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/baggiomarco/32/190_2.png) [@BaggioMarco](https://mne.discourse.group/u/BaggioMarco)\
**Post date:** [January 10, 2023, 4:45pm UTC](https://mne.discourse.group/t/is-mne-make-fixed-length-events-working-properly/6172/6 "2023-01-10T16:45:52Z")

</div>

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
