question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improving EDF reading in line with specification

See original GitHub issue

Describe the new feature or enhancement

In https://github.com/mne-tools/mne-python/pull/9694#issuecomment-908135503, I realized that the EDF specification can “encode” the channel type. One can have a label string in EDF be:

EEG Fz, implying that it is the Fz channel of eeg type. However, it’s “optional”.

For exporting EDF data, I would like to augment the export to encode the channel type, such that if you have channels:

EOG1, ECG1, A1, A2, A3, Fz, Cz, then they would be written to EDF like:

EOG EOG1
ECG ECG1
sEEG A1
sEEG A2
sEEG A3
EEG Fz
EEG Cz

Describe your proposed implementation

First, I would modify these lines: https://github.com/mne-tools/mne-python/blob/22cd7747529db7895345917c4d3884a482ed8ab3/mne/io/edf/edf.py#L387-L416

to allow for backwards-compatible behavior that also then sees if there is the “channel type” encoded in the label string.

Additional comments

This addition would not “hurt” our codebase, since it really just adds backwards-compatible behavior to allow for additional parsing of the channel type upon reading the EDF file. In addition, it would add more robust exporting. Overall, it is an improvement in our roundtrip of compliant EDF files.

That way I can modify the string of PRs:

See:

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
adam2392commented, Aug 30, 2021

So if you have the following channels:

{
   A1 = 'eeg',
   A2 = 'eeg',
   ECG1 = 'ecg',
   EOG1 = 'eog',
   LMT1 = 'seeg'
}

Then a parameter would either let their labels be written as the following in the EDF file?

A1, A2, ECG1, EOG1, LMT1

or

EEG A1, EEG A2, ECG ECG1, EOG EOG1, SEEG LMT1

Is there any reason to want the labels be the first way, rather than the second? Mistakes by user?

1reaction
larsonercommented, Aug 30, 2021

Indeed I would make a list of all the channel names that had a type that we didn’t know and say we mapped them to EEG at the end, something like:

bad_map = dict()
for ci in range(channels):
    if this_ch_type not in ch_type_dict:
        bad_map[ch_name] = this_ch_type
        this_ch_type = 'eeg'
if len(bad_map):
    bad_map = '\n'.join(f'{ch_name}: {ch_type}' for ch_name, ch_type in bad_map.items()'
    warn(f'Found the following unknown channel type mapping(s), setting the channel type to EEG:\n{bad_map})
Read more comments on GitHub >

github_iconTop Results From Across the Web

EDF(+) programming guidelines - European Data Format
Carefully read the EDF and EDF+ format specification, including the page about standard texts. Even if you do not need to handle annotations...
Read more >
Getting Started with EDF files - Sleep Data - NSRR
The EDF Specification page maintains a list publicly available EDF tools which you might want to review. New EDF loader/reader seem to be...
Read more >
problem reading EDF+ · Issue #1167 · fieldtrip ... - GitHub
edf ') all data is read according to my expectations, but annotations are not parsed (also as expected). Can you share the problematic...
Read more >
EDF+D & annotations - Luna
Here, the time of each record is tracked as an EDF Annotations channel, and so each record ... First, on reading Luna will...
Read more >
EDFbrowser manual
File info / header / properties; Header editor; EDF(+)/BDF(+) to ASCII (CSV) format converter; Reduce signals, duration and/or samplerate; Export filtered ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found