You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Read EDF files with dummy zero year/month/day #8281
EDF file that has dummy year/month/day of 0's cannot be read by mne.io.read_raw_edf() and exits with error "month must be in 1..12"
Expected results
I except the code still be able to read the data in the .edf file, and I would suggest that another dummy date is used instead of the 0's in the file, i propose using 1900-01-01.
Current code in mne/io/edf/edf.py:
# Recording ID
meas_id = {}
meas_id['recording_id'] = fid.read(80).decode('latin-1').strip(' \x00')
day, month, year = [int(x) for x in
re.findall(r'(\d+)', fid.read(8).decode())]
hour, minute, sec = [int(x) for x in
re.findall(r'(\d+)', fid.read(8).decode())]
century = 2000 if year < 50 else 1900
Proposal (same as above, only an additional if clause):
# Recording ID
meas_id = {}
meas_id['recording_id'] = fid.read(80).decode('latin-1').strip(' \x00')
day, month, year = [int(x) for x in
re.findall(r'(\d+)', fid.read(8).decode())]
hour, minute, sec = [int(x) for x in
re.findall(r'(\d+)', fid.read(8).decode())]
century = 2000 if year < 50 else 1900
if any([day == 0, month == 0, year == 0]):
year = 1900
month = 1
day = 1
If you think this is a solution you'd accept, I can also do a Pull request, although I am happy to hand it over to someone else too, as it is just a simple if clause add-on.
I'm fine with this change - @wolfgang-ganglberger it would be great if you submitted a PR. I suggest to also issue a warning if a date component is zero, e.g.
ifany([day==0, month==0, year==0]):
warn('Invalid date encountered ({:04d}-{:02d}-{:02d}), setting it ''to 1900-01-01.'.format(year, month, day))
year, month, day=1900, 1, 1
Agreed, but this just means checking if the values are within valid ranges, because we already convert to int after reading from the header. So I guess checking 1 <= day <= 31, 1 <= month <= 12, and year >= 1900 (or some other year) would be sufficient, or do you want a true check for a valid date (e.g. is February 29 2017 valid)?
Activity
cbrnr commentedon Sep 21, 2020
I'm fine with this change - @wolfgang-ganglberger it would be great if you submitted a PR. I suggest to also issue a warning if a date component is zero, e.g.
cbrnr commentedon Sep 21, 2020
Since MNE 0.21 now requires Python >= 3.6, you could also use an f-string:
agramfort commentedon Sep 21, 2020
cbrnr commentedon Sep 21, 2020
Agreed, but this just means checking if the values are within valid ranges, because we already convert to int after reading from the header. So I guess checking
1 <= day <= 31,1 <= month <= 12, andyear >= 1900(or some other year) would be sufficient, or do you want a true check for a valid date (e.g. is February 29 2017 valid)?agramfort commentedon Sep 21, 2020
wolfgang-ganglberger commentedon Sep 21, 2020
Thanks @agramfort and @cbrnr! Super awesome!