# Resampling RuntimeError - please report to developers

**URL:** <https://mne.discourse.group/t/resampling-runtimeerror-please-report-to-developers/4929>\
**Category:** Support & Discussions\
**Tags:** preprocessing, eeg\
**Created:** [May 24, 2022, 7:30am UTC](https://mne.discourse.group/t/resampling-runtimeerror-please-report-to-developers/4929 "2022-05-24T07:30:19Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![LeLoewenherz](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/leloewenherz/32/1465_2.png) [@LeLoewenherz](https://mne.discourse.group/u/LeLoewenherz)\
**Post date:** [May 24, 2022, 7:30am UTC](https://mne.discourse.group/t/resampling-runtimeerror-please-report-to-developers/4929/1 "2022-05-24T07:30:19Z")

</div>

Hi all,  
some of my data was recorded with a samplingrate of 20,000 Hz, so now I want to bring that down to 1,000 Hz like the rest of the measurements I was provided with.

When trying to do so with the .resample() method I get the following error :

> RuntimeError: Incorrect number of samples (24998912 != 24999876), please report this error to MNE-Python developers

So here I am. 😬

This is the Traceback:

> File “C:\Users\Audiometrie\Desktop\MA Leoni\Python\resampling.py”, line 42, in   
> raw\_resampled.resample(samplefrequency)
> 
> File “”, line 24, in resample
> 
> File “C:\ProgramData\Anaconda3\lib\site-packages\mne\io\base.py”, line 1238, in resample  
> data\_chunk = self.get\_data(
> 
> File “”, line 22, in get\_data
> 
> File “C:\ProgramData\Anaconda3\lib\site-packages\mne\io\base.py”, line 908, in get\_data  
> getitem = self.\_getitem(
> 
> File “C:\ProgramData\Anaconda3\lib\site-packages\mne\io\base.py”, line 814, in \_getitem  
> data = self.\_read\_segment(start=start, stop=stop, sel=sel,
> 
> File “”, line 24, in \_read\_segment
> 
> File “C:\ProgramData\Anaconda3\lib\site-packages\mne\io\base.py”, line 453, in \_read\_segment  
> \_ReadSegmentFileProtector(self).\_read\_segment\_file(
> 
> File “C:\ProgramData\Anaconda3\lib\site-packages\mne\io\base.py”, line 2121, in \_read\_segment\_file  
> return self.\_\_raw. **class**.\_read\_segment\_file(
> 
> File “C:\ProgramData\Anaconda3\lib\site-packages\mne\io\curry\curry.py”, line 540, in \_read\_segment\_file  
> \_read\_segments\_file(
> 
> File “C:\ProgramData\Anaconda3\lib\site-packages\mne\io\utils.py”, line 222, in \_read\_segments\_file  
> raise RuntimeError('Incorrect number of samples (%s != %s),

Is there anything I can do to resolve this?  
Best wishes!

I’m working with MNE 0.24.1, Windows 10

---

<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:** [May 24, 2022, 7:55am UTC](https://mne.discourse.group/t/resampling-runtimeerror-please-report-to-developers/4929/2 "2022-05-24T07:55:07Z")

</div>

Hello @LeLoewenherz, thanks for reporting! Is there any chance you could share the data that’s causing this problem?

cc @larsoner

---

<div class="post-metadata">

**Author:** ![LeLoewenherz](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/leloewenherz/32/1465_2.png) [@LeLoewenherz](https://mne.discourse.group/u/LeLoewenherz)\
**Post date:** [May 24, 2022, 9:18am UTC](https://mne.discourse.group/t/resampling-runtimeerror-please-report-to-developers/4929/3 "2022-05-24T09:18:03Z")

</div>

Hello @richard and @larsoner ,

I hope it works like this?  
[https://drive.google.com/drive/folders/1DOPJlGZmDf\_jfmze58FFSlJRURZBTkW2?usp=sharing](https://drive.google.com/drive/folders/1DOPJlGZmDf_jfmze58FFSlJRURZBTkW2?usp=sharing)

I use the read\_raw\_curry() method and I can also provide the info, that it works fine when only using 60s of the cropped data.

---

<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:** [May 24, 2022, 9:39am UTC](https://mne.discourse.group/t/resampling-runtimeerror-please-report-to-developers/4929/4 "2022-05-24T09:39:01Z")

</div>

Can you provide the cropped data then instead, please? So we don’t have to download this huge file 🙂

---

<div class="post-metadata">

**Author:** ![LeLoewenherz](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/leloewenherz/32/1465_2.png) [@LeLoewenherz](https://mne.discourse.group/u/LeLoewenherz)\
**Post date:** [May 24, 2022, 9:57am UTC](https://mne.discourse.group/t/resampling-runtimeerror-please-report-to-developers/4929/5 "2022-05-24T09:57:44Z")

</div>

I added it to the folder 🙂

---

<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:** [May 30, 2022, 6:58am UTC](https://mne.discourse.group/t/resampling-runtimeerror-please-report-to-developers/4929/6 "2022-05-30T06:58:37Z")

</div>

Hello @LeLoewenherz,

I cannot reproduce the problem on my system (using the original, un-cropped data). I tested:

- with preloading & multiple jobs: `raw.copy().load_data().resample(1000, n_jobs=8)`
- without preloading: `raw.copy().resample(1000)`

on MNE-Python 1.0.3 as well as on the latest development version.

The only thing I observed was that without preloading, resampling was taking **ages** (several minutes), while with the preloaded data, the process finished after about 1 minute (2021 MacBook Pro 13" with an M1 chip).

Did you monitor memory usage during the procedure? I’m wondering if you were simply running out of memory and therefore the reading operation failed… Data with such a high sampling frequency is quite tough on memory usage – be sure to use a machine with lots of RAM.

Best wishes,  
Richard

---

<div class="post-metadata">

**Author:** ![LeLoewenherz](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/leloewenherz/32/1465_2.png) [@LeLoewenherz](https://mne.discourse.group/u/LeLoewenherz)\
**Post date:** [May 30, 2022, 9:34am UTC](https://mne.discourse.group/t/resampling-runtimeerror-please-report-to-developers/4929/7 "2022-05-30T09:34:36Z")

</div>

Hi @richard ,  
thanks a lot for your time!

In my definition “ages” was about 1h for the cropped data to be resampled and the original was an overnight job… 😄

The preloading seems to solve both: the time issue (it still takes about 10 mins, but that’s fine) and the original error.

Best wishes!

---

<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:** [May 30, 2022, 9:48am UTC](https://mne.discourse.group/t/resampling-runtimeerror-please-report-to-developers/4929/8 "2022-05-30T09:48:09Z")

</div>

Be sure to pass n\_jobs so you can make use of all (?) of your CPU cores.

---

<div class="post-metadata">

**Author:** ![LeLoewenherz](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/leloewenherz/32/1465_2.png) [@LeLoewenherz](https://mne.discourse.group/u/LeLoewenherz)\
**Post date:** [May 30, 2022, 12:04pm UTC](https://mne.discourse.group/t/resampling-runtimeerror-please-report-to-developers/4929/9 "2022-05-30T12:04:25Z")

</div>

Using all 4 cores does speed up the resampling but what is still taking 10min here is the preloading of the data.

Is that RAM related? (I don’t really know a lot about the technical things in programming)

---

<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:** [May 30, 2022, 2:36pm UTC](https://mne.discourse.group/t/resampling-runtimeerror-please-report-to-developers/4929/10 "2022-05-30T14:36:33Z")

</div>

It’s probably your hard drive. My computer has an excessively fast SSD, like all MacBook Pros.

---

<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:** [May 30, 2022, 2:41pm UTC](https://mne.discourse.group/t/resampling-runtimeerror-please-report-to-developers/4929/11 "2022-05-30T14:41:53Z")

</div>

I just ran a timing test, out of curiosity:

 ![Screen Shot 2022-05-30 at 16.40.29](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/e/ea7eddbc94416a734dfa837440efaaf341e8ae62.png)

People often complain about how “expensive” Macs are, but when it comes to performance like disk I/O, they deliver an extremely high value for the money.

Mind you this is the cheapest, entry-level MacBook Pro from last year I’m using here.
