# Index Error while reading data

**URL:** <https://mne.discourse.group/t/index-error-while-reading-data/5535>\
**Category:** Support & Discussions\
**Tags:** eeg\
**Created:** [September 5, 2022, 2:26pm UTC](https://mne.discourse.group/t/index-error-while-reading-data/5535 "2022-09-05T14:26:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![trevidiann](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/trevidiann/32/1542_2.png) [@trevidiann](https://mne.discourse.group/u/trevidiann)\
**Post date:** [September 5, 2022, 2:26pm UTC](https://mne.discourse.group/t/index-error-while-reading-data/5535/1 "2022-09-05T14:26:19Z")

</div>

- MNE version: 1.1
- operating system: Windows 11

Hello everyone, I’ve been having trouble reading some of my data. For 3 particular subjects in my dataset I am occasionally getting this error.

I am using .mff data from NetStation, which is produced by egi. The function read\_raw\_egi usually works perfectly and I can read the data.

Here is the code:

```python
import os
import mne
import mne_bids

root_path = os.path.join("C:/Users/trevo/OneDrive/Desktop/Lab_Files/VWM_LAB/EGI_RAW/07/WM3/isi50.mff")

raw = mne.io.read_raw_egi(root_path)
raw.load_data() 

```

And It produces this error:

> * * *
> 
> IndexError Traceback (most recent call last)  
> Input In [21], in \<cell line: 1\>()  
> ----\> 1 raw = mne.io.read\_raw\_egi(root\_path)  
> 2 raw.load\_data()
> 
> File :12, in read\_raw\_egi(input\_fname, eog, misc, include, exclude, preload, channel\_naming, verbose)
> 
> File ~\anaconda3\envs\mne\lib\site-packages\mne\io\egi\egi.py:156, in read\_raw\_egi(input\_fname, eog, misc, include, exclude, preload, channel\_naming, verbose)  
> 154 input\_fname = str(input\_fname)  
> 155 if input\_fname.rstrip(‘/\’).endswith(‘.mff’): # allows .mff or .mff/  
> → 156 return \_read\_raw\_egi\_mff(input\_fname, eog, misc, include,  
> 157 exclude, preload, channel\_naming, verbose)  
> 158 return RawEGI(input\_fname, eog, misc, include, exclude, preload,  
> 159 channel\_naming, verbose)
> 
> File :12, in \_read\_raw\_egi\_mff(input\_fname, eog, misc, include, exclude, preload, channel\_naming, verbose)
> 
> File ~\anaconda3\envs\mne\lib\site-packages\mne\io\egi\egimff.py:389, in \_read\_raw\_egi\_mff(input\_fname, eog, misc, include, exclude, preload, channel\_naming, verbose)  
> 328 @verbose  
> 329 def \_read\_raw\_egi\_mff(input\_fname, eog=None, misc=None,  
> 330 include=None, exclude=None, preload=False,  
> 331 channel\_naming=‘E%d’, verbose=None):  
> 332 “”“Read EGI mff binary as raw object.  
> 333  
> 334 … note:: This function attempts to create a synthetic trigger channel.  
> (…)  
> 387 … versionadded:: 0.15.0  
> 388 “””  
> → 389 return RawMff(input\_fname, eog, misc, include, exclude,  
> 390 preload, channel\_naming, verbose)
> 
> File :12, in **init** (self, input\_fname, eog, misc, include, exclude, preload, channel\_naming, verbose)
> 
> File ~\anaconda3\envs\mne\lib\site-packages\mne\io\egi\egimff.py:412, in RawMff. **init** (self, input\_fname, eog, misc, include, exclude, preload, channel\_naming, verbose)  
> 408 misc = np.where(np.array(  
> 409 egi\_info[‘chan\_type’]) != ‘eeg’)[0].tolist()  
> 411 logger.info(’ Reading events …‘)  
> → 412 egi\_events, egi\_info = \_read\_events(input\_fname, egi\_info)  
> 413 cals = \_get\_eeg\_calibration\_info(input\_fname, egi\_info)  
> 414 logger.info(’ Assembling measurement info …')
> 
> File ~\anaconda3\envs\mne\lib\site-packages\mne\io\egi\events.py:32, in \_read\_events(input\_fname, info)  
> 30 for n, event in enumerate(event\_codes):  
> 31 for i in mff\_events[event]:  
> —\> 32 events[n][i] = n + 1  
> 33 return events, info
> 
> IndexError: index -585184 is out of bounds for axis 0 with size 373418

From what I’ve seen [this](https://mne.discourse.group/t/index-error-when-trying-to-read-data/2823) post, it has something to do with reading in events. Though the solution implemented has not been working for my code.

I’ve been able to read this raw data with other software (NetStation Review) so I don’t believe that the data is corrupted, though I could be wrong.

I’ll include an example of a different scan which is successfully read by read\_raw\_egi, if that helps:

```python
import os
import mne
import mne_bids

root_path = os.path.join("C:/Users/trevo/OneDrive/Desktop/Lab_Files/VWM_LAB/EGI_RAW/07/WM3/isi0.mff")

raw = mne.io.read_raw_egi(root_path)
raw.load_data() 

```

> Reading EGI MFF Header from C:\Users\trevo\OneDrive\Desktop\Lab\_Files\VWM\_LAB\EGI\_RAW\07\WM3\isi0.mff…  
> Reading events …  
> Assembling measurement info …  
> Synthesizing trigger channel “STI 014” …  
> Excluding events {SESS} …  
> Reading 0 … 362911 = 0.000 … 362.911 secs…
> 
> | Measurement date | August 19, 2020 16:27:06 GMT |
> | --- | --- |
> | Experimenter | Unknown |
> | Participant | Unknown |
> | Digitized points | 132 points |
> | Good channels | 129 EEG, 8 Stimulus |
> | Bad channels | None |
> | EOG channels | Not available |
> | ECG channels | Not available |
> | Sampling frequency | 1000.00 Hz |
> | Highpass | 0.00 Hz |
> | Lowpass | 500.00 Hz |
> | Filenames | signal1.bin |
> | Duration | 00:06:02 (HH:MM:SS) |

---

<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 5, 2022, 2:59pm UTC](https://mne.discourse.group/t/index-error-while-reading-data/5535/2 "2022-09-05T14:59:57Z")

</div>

to debug this we will need access to one of the files that fails to load. Are you allowed to share publicly? If not, maybe you can post a (restricted) google drive link and grant us access individually as we request it?

cc @scott-huberty in case you’ve seen this before and know what the fix should be.

---

<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:** [September 5, 2022, 3:00pm UTC](https://mne.discourse.group/t/index-error-while-reading-data/5535/3 "2022-09-05T15:00:22Z")

</div>

do you also have the problem when using this package [https://pypi.org/project/mffpy/](https://pypi.org/project/mffpy/) ?

Alex

---

<div class="post-metadata">

**Author:** ![trevidiann](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/trevidiann/32/1542_2.png) [@trevidiann](https://mne.discourse.group/u/trevidiann)\
**Post date:** [September 5, 2022, 10:32pm UTC](https://mne.discourse.group/t/index-error-while-reading-data/5535/4 "2022-09-05T22:32:12Z")

</div>

Hello Dan,

You can find a restricted google drive link [here](https://drive.google.com/drive/folders/1-K9IDR-1gLLYCAjxyeCw174qOCOKeEvz?usp=sharing) to an .mff file that has the issue, it isn’t the exact file from my post and has been renamed to raw.mff.

I’ve added your email to the list of approved emails. I’ll be happy to add anyone else who would like to assist. Thank you, I appreciate the help!

Trevor

---

<div class="post-metadata">

**Author:** ![scott-huberty](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/scott-huberty/32/2715_2.png) [@scott-huberty](https://mne.discourse.group/u/scott-huberty)\
**Post date:** [September 6, 2022, 3:34pm UTC](https://mne.discourse.group/t/index-error-while-reading-data/5535/5 "2022-09-06T15:34:55Z")

</div>

I tried loading the file you shared and am getting the same error (with mne v1.1), but haven’t had the time to look more into it.

A couple questions -

Is there _any_ chance that, between the time of acquisition and the time you tried reading the file, that the MFF file was uploaded to or from a server (gdrive/onedrive etc), without being zipped? I noticed that your paths includes OneDrive and I am not sure whether these files are then automatically uploaded and downloaded between a OneDrive server. Only reason I ask is that since .MFF files are essentially directories, a lot of problems are caused by files in the .mff directory being corrupted during data transfer. If so, can you try grabbing the file from the acquisition machine again? This might not be the issue, but It would be nice to double check.

As was suggested before can you try using the mffPy package to read in the file giving you trouble? This package is maintained by Don Tucker’s lab (founder of EGI), and it would be useful to know if your file breaks their code as well.

Thanks!

---

<div class="post-metadata">

**Author:** ![scott-huberty](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/scott-huberty/32/2715_2.png) [@scott-huberty](https://mne.discourse.group/u/scott-huberty)\
**Post date:** [September 19, 2022, 6:46pm UTC](https://mne.discourse.group/t/index-error-while-reading-data/5535/6 "2022-09-19T18:46:31Z")

</div>

Hi @trevidiann - just checking in. Have you made any progress in troubleshooting this problem? Is there any thing you are stuck on?

Scott

---

<div class="post-metadata">

**Author:** ![axel](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@axel](https://mne.discourse.group/u/axel)\
**Post date:** [April 7, 2023, 4:44pm UTC](https://mne.discourse.group/t/index-error-while-reading-data/5535/8 "2023-04-07T16:44:12Z")

</div>

Has anyone solved this problem? I’m running into the same issue and reading the .mff file using mffpy works just fine.

---

<div class="post-metadata">

**Author:** ![scott-huberty](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/scott-huberty/32/2715_2.png) [@scott-huberty](https://mne.discourse.group/u/scott-huberty)\
**Post date:** [April 7, 2023, 5:03pm UTC](https://mne.discourse.group/t/index-error-while-reading-data/5535/9 "2023-04-07T17:03:37Z")

</div>

Hi @axel - not that i’m aware of, no.

I think there is a desire to use `mffpy` under the hood when reading MFF files into MNE (see [here](https://github.com/mne-tools/mne-python/issues/11380#issuecomment-1367608965) and [here](https://github.com/mne-tools/mne-python/issues/6937) ) - which I think would solve this issue (since it seems that `mffpy` works well for you)

But I’m not sure how much work it will entail. I’d be willing to help on that but I likely wouldn’t have the time for it until mid-may.

---

<div class="post-metadata">

**Author:** ![axel](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@axel](https://mne.discourse.group/u/axel)\
**Post date:** [April 9, 2023, 3:20pm UTC](https://mne.discourse.group/t/index-error-while-reading-data/5535/10 "2023-04-09T15:20:43Z")

</div>

Thanks for your response! I realized that read\_raw\_egi requires the events to be mutually exclusive, so I did some testing and found that I can read the file in when there are no overlapping triggers. However, when events are very close in time (but not overlapping), read\_raw\_egi throws an error. This is mainly an issue when I call for EGI and the testing computer to resync, so I can work around that.

I am concerned this will be an issue in the future though if participant responses are too close in time to event onsets. Not yet sure if anything else triggers the error.

---

<div class="post-metadata">

**Author:** ![axel](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@axel](https://mne.discourse.group/u/axel)\
**Post date:** [April 10, 2023, 12:53am UTC](https://mne.discourse.group/t/index-error-while-reading-data/5535/11 "2023-04-10T00:53:34Z")

</div>

Actually, scratch some of what I said earlier. I seem to have issues with other files when all trigger events are farther apart in time.  
It seems like it’d be great if mffpy was reading files under the hood. Thanks for offering to help! Would really appreciate it.
