# error when applying mne.Epochs function to rawEDF

**URL:** <https://mne.discourse.group/t/error-when-applying-mne-epochs-function-to-rawedf/7471>\
**Category:** Support & Discussions\
**Tags:** preprocessing, epochs\
**Created:** [August 31, 2023, 5:55pm UTC](https://mne.discourse.group/t/error-when-applying-mne-epochs-function-to-rawedf/7471 "2023-08-31T17:55:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jianyang](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/jianyang/32/4061_2.png) [@Jianyang](https://mne.discourse.group/u/Jianyang)\
**Post date:** [August 31, 2023, 5:55pm UTC](https://mne.discourse.group/t/error-when-applying-mne-epochs-function-to-rawedf/7471/1 "2023-08-31T17:55:42Z")

</div>

**❓ If you have a question or issue with MNE-Python, please include the following info:**

- MNE version: e.g. 1.4.0
- operating system: e.g. macOS 11.7.3 (2

I have a 1000s .bdf file, when I do

1. raw=mne.io.read\_raw\_edf() to read it,
2. event = mne.make\_fixed\_length\_events(raw, start=0, stop=None, duration=10,first\_samp=False) to get events
3. mne.Epochs(raw, events, tmin=0,event\_id=1, tmax=10, baseline=None, preload=True) to epoch  
Problem:  
1.1: i can only get 30s’ epoch, which has 3 events.  
1.2: while I export it as ‘.vhdr’ and use mne.io.read\_raw\_brainvision to import it and do epoch again, I can get 100 events that are right.  
1.3: when I do mne.Epochs(raw, events, tmin=0,event\_id=1, tmax=10, baseline=None) which preload=False, I can get 100 events that are right.  
I wonder what the inner problem is.
4. Can I transfer rawEDF to rawBrainVision without export?
5. what’s the problem applying mne.Epoch fucntion to rawEDF?

---

<div class="post-metadata">

**Author:** ![jstout211](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/jstout211/32/180_2.png) [@jstout211](https://mne.discourse.group/u/jstout211)\
**Post date:** [August 31, 2023, 6:39pm UTC](https://mne.discourse.group/t/error-when-applying-mne-epochs-function-to-rawedf/7471/2 "2023-08-31T18:39:04Z")

</div>

I don’t think this answers your questions, but may be helpful. Can you try the function `mne.make_fixed_length_epochs(raw, duration=10.0)`. This way, you don’t have to deal with the events.

Regarding your question - check your dataset `raw.times` just to confirm that your times in your raw file are what you expect. And also check your events variable includes events that extend out as far as you are expecting.

–Jeff

---

<div class="post-metadata">

**Author:** ![Jianyang](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/jianyang/32/4061_2.png) [@Jianyang](https://mne.discourse.group/u/Jianyang)\
**Post date:** [September 1, 2023, 7:17am UTC](https://mne.discourse.group/t/error-when-applying-mne-epochs-function-to-rawedf/7471/3 "2023-09-01T07:17:09Z")

</div>

I fixed it one day and failed, Now I have used your method, and it works, just like magic. Thank you very much!

I checked the `raw.times`, it has something wrong. Although numerical value is right when I did `raw.times[-1] - raw.times[-2]` it gets 0.009999999999763531, but not 0.01 (sample rate is 100).

and when i modify the raw.times, but get error: AttributeError: can’t set attribute.

Hence, I get new problem: how do I modify the raw.times?

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [September 1, 2023, 2:54pm UTC](https://mne.discourse.group/t/error-when-applying-mne-epochs-function-to-rawedf/7471/4 "2023-09-01T14:54:56Z")

</div>

> [@Jianyang](#):
>
> it gets 0.009999999999763531, but not 0.01 (sample rate is 100).

This is probably OK / not a problem. The “error” in sampling period is about 0.000000002 % and the error in sample rate is the same. This will not make a meaningful difference to any calculations. It might even reflect the _actual_ sampling rate/times; hardware devices don’t always achieve the _exact_ sampling frequencies they advertise.

---

<div class="post-metadata">

**Author:** ![Jianyang](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/jianyang/32/4061_2.png) [@Jianyang](https://mne.discourse.group/u/Jianyang)\
**Post date:** [September 1, 2023, 5:31pm UTC](https://mne.discourse.group/t/error-when-applying-mne-epochs-function-to-rawedf/7471/5 "2023-09-01T17:31:57Z")

</div>

Got it! Thank you very much!
