In _read_edf_header returns AssertionError

  • MNE-Python version: 0.22
  • operating system: Windows

Hi, I am completely new to MNE. I tried to load data from an edf file using mne.io.read_raw_edf but it gave me an AssertionError. The code is simple as follows.

raw_data = mne.io.read_raw_edf("C:/Users/XXX/XXX/eeg79.edf")

And the error looks like this:

Traceback (most recent call last):
  File "D:/main.py", line 8, in <module>
    raw_data = mne.io.read_raw_edf("C:/Users/XXX/XXX/eeg79.edf")
  File "D:\Anaconda3\envs\mne\lib\site-packages\mne\io\edf\edf.py", line 1217, in read_raw_edf
    return RawEDF(input_fname=input_fname, eog=eog, misc=misc,
  File "<decorator-gen-182>", line 24, in __init__
  File "D:\Anaconda3\envs\mne\lib\site-packages\mne\io\edf\edf.py", line 114, in __init__
    info, edf_info, orig_units = _get_info(input_fname,
  File "D:\Anaconda3\envs\mne\lib\site-packages\mne\io\edf\edf.py", line 358, in _get_info
    edf_info, orig_units = _read_header(fname, exclude)
  File "D:\Anaconda3\envs\mne\lib\site-packages\mne\io\edf\edf.py", line 345, in _read_header
    return _read_edf_header(fname, exclude)
  File "D:\Anaconda3\envs\mne\lib\site-packages\mne\io\edf\edf.py", line 656, in _read_edf_header
    assert fid.tell() == header_nbytes
AssertionError

I’ve spent a whole day trying to solve this problem, please help me and let me know what should I do.

Hello, are you sure this file is a valid EDF file?

Yes! I am sure it is. It is neonatal EEG recordings in EDF format, the whole dataset can be found at https://zenodo.org/record/1280684#.YDj2qegzZEY.

1 Like

Thank you for sharing the dataset, I will try to have a look soon.

cc @cbrnr

The file has an invalid date set. MNE has been fixed to deal with this in version 0.22. Are you absolutely sure you’re using version 0.22? I just tried that version on my Mac, and reading the file works flawlessly. I only get the following message:

RuntimeWarning: Invalid date encountered (2000-00-00 00:00:00).

I got the same RuntimeWarning followed by the AssertionError. I’ve seen the invalid date issue has been fixed on Github, that’s why I am only posing this question.

I am sure that I am using version 0.22 because I set my conda environment using the environment file environment .yml provided on Github. I double-checked it is 0.22 indeed.

I got the following output in addition to the warning and error:

Extracting EDF parameters from C:\Users\XXX\XXX\eeg1.edf...
EDF file detected

Then the program stopped running… The RuntimeWarning should not stop the program, should it? Or conda didn’t create the environment properly. Can MNE runs with system Python rather than conda-managed Python?

Could you please post the output of the command

mne sys_info

(run in your terminal)? Thanks!

Ok, the following is the output of the command.

Platform:      Windows-10-10.0.19041-SP0
Python:        3.8.8 | packaged by conda-forge | (default, Feb 20 2021, 15:50:08) [MSC v.1916 64 bit (AMD64)]
Executable:    D:\Anaconda3\envs\mne\python.exe
CPU:           Intel64 Family 6 Model 158 Stepping 9, GenuineIntel: 8 cores
Memory:        7.9 GB

mne:           0.22.0
numpy:         1.20.1 {blas=NO_ATLAS_INFO, lapack=lapack}
scipy:         1.6.0
matplotlib:    3.3.4 {backend=Qt5Agg}

sklearn:       0.24.1
numba:         0.52.0
nibabel:       3.2.1
nilearn:       0.7.0
dipy:          1.3.0
cupy:          Not found
pandas:        1.2.2
mayavi:        4.7.2
pyvista:       0.28.1 {pyvistaqt=0.3.0, OpenGL 4.5.0 - Build 24.20.100.6344 via Intel(R) HD Graphics 630}
vtk:           9.0.1
PyQt5:         5.12.3

Would you suggest me to reinstall mne?

Honestly, I’m a little bit clueless as to where your problem might be coming from. The sys_info output looks good, and you shouldn’t see the error you’re seeing.

Could you maybe try re-installing MNE by running

pip install -U mne

and see if this helps?

cc @larsoner @cbrnr

Wait a second! In your initial posting, you tried to read eeg79.edf. In a later reply, you’re trying to read eeg1.edf

Reading eeg79.edf does work for me, while I can reproduce your problem when trying to read eeg1.edf

Can you try reading eeg79.edf again, please? It should work!

Meanwhile I will have a look at what’s up with reading eeg1.edf.

I tried reinstalling, both eeg79.edf and eeg1.edg did not work for me :sob:. This might not be the problem of MNE. Hopefully, I will work that out later. Anyway, thank you for the support with such fast responses, really appreciate it.

I just tried reading the files via PyEDFlib and it fails too with both files, stating that they’re not valid EDF files due to the measurement date.

What you can try is use EDFBrowser and either try to fix the header, or maybe re-save the files.

Ultimately you should probably drop the owners of the Zenodo dataset a message, asking them if they could kindly upload EDF-compliant files.

1 Like

Thank you again for the suggestions! Better to find another dataset to work with :sweat_smile:.