Error Reading Epochs

Hey everyone. I have been running into an issue in my code.

I have a list of files that are formatted similarly to this.
‘IS_data/derivatives/sub-01/ses-01/sub-01_ses-01_eeg-epo.fif’
According to the api reference, the mne.read_epochs function reads epoch data that ends with ‘-epo.fif’ I formatted my code as below:
mne.read_epochs(‘IS_data/derivatives/sub-01/ses-01/sub-01_ses-01_eeg-epo.fif’)
I figured it would work perfectly with the data I have. Instead I keep getting this error:
File line 126, in fiff_open
return _fiff_open(fname, fid, preload)
File line 145, in _fiff_open
raise ValueError(f’{prefix} start with a file id tag’)
ValueError: file does not start with a file id tag

Does anyone have any ideas as to why this is happening? If so please let me know. I am very confused!

  • MNE version: e.g. 0.24.0
  • operating system: e.g. macOS 12 / Windows 10 / Ubuntu 18.04

it should work. I suspect your file is damaged.

Alex

How would I fix a damaged file?

Hello,

Could you share the file and the complete error traceback?
There is a chance that what is stored in this FIF file is not Epochs but something else (despite the ending "-epo" matching the convention), in which case a different reader should be used to open it.
Also, try to update your MNE version. 0.24 is a couple of years old, many bugs have been fixed and improvements added. A recent version might be able to load your file.
And finally, if the file is really damaged, there is little to be done.

Mathieu

This is the complete error traceback.

Traceback (most recent call last):
  File "/Users/sophieeisenberg/PycharmProjects/innerSpeech/main.py", line 18, in <module>
    epoch = mne.read_epochs(path)
  File "<decorator-gen-282>", line 12, in read_epochs
  File "/Users/sophieeisenberg/opt/anaconda3/lib/python3.9/site-packages/mne/epochs.py", line 3175, in read_epochs
    return EpochsFIF(fname, proj, preload, verbose)
  File "<decorator-gen-283>", line 12, in __init__
  File "/Users/sophieeisenberg/opt/anaconda3/lib/python3.9/site-packages/mne/epochs.py", line 3234, in __init__
    fid, tree, _ = fiff_open(fname, preload=preload)
  File "<decorator-gen-9>", line 12, in fiff_open
  File "/Users/sophieeisenberg/opt/anaconda3/lib/python3.9/site-packages/mne/io/open.py", line 126, in fiff_open
    return _fiff_open(fname, fid, preload)
  File "/Users/sophieeisenberg/opt/anaconda3/lib/python3.9/site-packages/mne/io/open.py", line 145, in _fiff_open
    raise ValueError(f'{prefix} start with a file id tag')
ValueError: file '/Users/sophieeisenberg/PycharmProjects/innerSpeech/IS_data/derivatives/sub-01/ses-01/sub-01_ses-01_eeg-epo.fif' does not start with a file id tag
Reading /Users/sophieeisenberg/PycharmProjects/innerSpeech/IS_data/derivatives/sub-01/ses-01/sub-01_ses-01_eeg-epo.fif ...

I am not sure how to upload the file, but this is the link to the dataset I am using: OpenNeuro
I am attempting to read the file: sub-01_ses-01_eeg-epo.fif
My MNE version is actually 1.3.1, I mistyped, and I am on a mac. Thank you so much for the help.

Hi @sophie1,

I can’t reproduce the error. I am on a linux machine though. Can you try to load the data using a different IDE or download the data again?

In [1]: from mne import read_epochs

In [2]: fname='/home/dip_linux/Downloads/derivatives sub-01 ses-01 sub-01_ses-01_eeg-epo.fif'

In [3]: epochs= read_epochs(fname)
Reading /home/dip_linux/Downloads/derivatives sub-01 ses-01 sub-01_ses-01_eeg-epo.fif ...
Isotrak not found
    Found the data of interest:
        t =    -500.00 ...    4000.00 ms
        0 CTF compensation matrices available
Not setting metadata
200 matching events found
No baseline correction applied
0 projection items activated

In [4]: epochs.info
Out[4]: 
<Info | 10 non-empty values
 bads: []
 ch_names: A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, ...
 chs: 128 EEG
 custom_ref_applied: True
 file_id: 4 items (dict)
 highpass: 0.5 Hz
 lowpass: 100.0 Hz
 meas_date: 2019-08-20 10:57:41 UTC
 meas_id: 4 items (dict)
 nchan: 128
 projs: [ ]
 sfreq: 256.0 Hz

In [5]: epochs.plot()
Using qt as 2D backend.
Out[5]: <mne_qt_browser._pg_figure.MNEQtBrowser at 0x7f7816e676d0>

Apparently, file id is also readable.

In [6]: epochs.info['file_id']
Out[6]: 
{'version': 65540,
 'machid': array([808661043, 808661043], dtype=int32),
 'secs': 0,
 'usecs': 2147483647}

best,
Dip

1 Like

Update: I redownloaded the dataset and it is working now. Thanks for the help!

1 Like

Ah an openneuro one; it happens often that the dataset is broken after download. Personally, I use openneuro-py to download openneuro datasets, I had less trouble with this download method.

3 Likes