mne.io.read_raw_edf can't open files, ValueError from headers with missing data

Hi,

I’m a new user, so apologies if I’m missing something obvious. I have many EDF files that I can’t open with MNE. They are lacking a date/time in the header and I think this is the issue. Instead of the date and time, these headers have a string of spaces in those fields (i.e. " "), so I get the error “invalid literal for int() with base 10: ’ '”. I can open files that do have dates and times in the headers, and I can also open the files lacking dates/times in other programs, edit the header to include date/time, and then open them in MNE. However, I have many of these files and this isn’t a sustainable solution. Is there a way to get MNE to automatically interpret these strings simply as missing data rather than throwing an error and giving up on loading the file?

MNE version 0.24.1, also tried 0.22.0
Windows 10
Python 3.8.8, also tried 3.10.0
Error copied below.
Unfortunately, I can’t share the data, sorry :frowning:

Thanks!
AC


ValueError Traceback (most recent call last)
in
1 import mne
----> 2 fl = mne.io.read_raw_edf(“tst.edf”)

~\Anaconda3\lib\site-packages\mne\io\edf\edf.py in read_raw_edf(input_fname, eog, misc, stim_channel, exclude, preload, verbose)
1220 return RawEDF(input_fname=input_fname, eog=eog, misc=misc,
1221 stim_channel=stim_channel, exclude=exclude, preload=preload,
→ 1222 verbose=verbose)
1223
1224

in init(self, input_fname, eog, misc, stim_channel, exclude, preload, verbose)

~\Anaconda3\lib\site-packages\mne\io\edf\edf.py in init(self, input_fname, eog, misc, stim_channel, exclude, preload, verbose)
114 info, edf_info, orig_units = _get_info(input_fname,
115 stim_channel, eog, misc,
→ 116 exclude, preload)
117 logger.info(‘Creating raw.info structure…’)
118

~\Anaconda3\lib\site-packages\mne\io\edf\edf.py in _get_info(fname, stim_channel, eog, misc, exclude, preload)
356 misc = misc if misc is not None else []
357
→ 358 edf_info, orig_units = _read_header(fname, exclude)
359
360 # XXX: tal_ch_names to pass to _check_stim_channel should be computed

~\Anaconda3\lib\site-packages\mne\io\edf\edf.py in _read_header(fname, exclude)
343 logger.info(’%s file detected’ % ext.upper())
344 if ext in (‘bdf’, ‘edf’):
→ 345 return _read_edf_header(fname, exclude)
346 elif ext == ‘gdf’:
347 return _read_gdf_header(fname, exclude), None

~\Anaconda3\lib\site-packages\mne\io\edf\edf.py in _read_edf_header(fname, exclude)
569 else:
570 meas_date = fid.read(8).decode(‘latin-1’)
→ 571 day, month, year = [int(x) for x in meas_date.split(’.’)]
572 year = year + 2000 if year < 85 else year + 1900
573

~\Anaconda3\lib\site-packages\mne\io\edf\edf.py in (.0)
569 else:
570 meas_date = fid.read(8).decode(‘latin-1’)
→ 571 day, month, year = [int(x) for x in meas_date.split(’.’)]
572 year = year + 2000 if year < 85 else year + 1900
573

ValueError: invalid literal for int() with base 10: ’ ’

either we consider the file corrupted and you need to hack something locally
or we consider the pb legit and we can fix the reader by warning rather than crashing

in any case it’s hard to debug without the data.

Alex

Hello @pyAK and welcome to the forum! Like @agramfort said, the file might be corrupted … are you sure that’s not the case? Can you share the file with us so we can have a look?

Best wishes,
Richard

Hi, thanks for the responses. I’m fairly sure that the files are not corrupted, because I can open them in Matlab, edit the header to include a date/time, and then with those edits I am able to open the files with MNE. This is why I think the error is due to missing date/time info in the header. The error text also seems to clearly point to a date/time issue. However, I’m definitely not positive about this being the cause.

Here is one example file that gives me an error when I try to open it with MNE.

Thanks!

Opening the file with EDFbrowser gives an error:

But I tend to lean towards relaxing our reader to allow reading such files (with a proper warning of course).

Thank you for checking this for me! It’s looking like it might be an issue with default font encoding differences between computers, so the headers are incorrect by the time I get them and causing MNE to give an error.