Skip to content

Improving EDF reading in line with specification #9704

@adam2392

Description

@adam2392

Describe the new feature or enhancement

In #9694 (comment), 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:

for idx, ch_name in enumerate(ch_names):
chan_info = {}
chan_info['cal'] = 1.
chan_info['logno'] = idx + 1
chan_info['scanno'] = idx + 1
chan_info['range'] = 1.
chan_info['unit_mul'] = FIFF.FIFF_UNITM_NONE
chan_info['ch_name'] = ch_name
chan_info['unit'] = FIFF.FIFF_UNIT_V
chan_info['coord_frame'] = FIFF.FIFFV_COORD_HEAD
chan_info['coil_type'] = FIFF.FIFFV_COIL_EEG
chan_info['kind'] = FIFF.FIFFV_EEG_CH
chan_info['loc'] = np.zeros(12)
if ch_name in eog or idx in eog or idx - nchan in eog:
chan_info['coil_type'] = FIFF.FIFFV_COIL_NONE
chan_info['kind'] = FIFF.FIFFV_EOG_CH
pick_mask[idx] = False
elif ch_name in misc or idx in misc or idx - nchan in misc:
chan_info['coil_type'] = FIFF.FIFFV_COIL_NONE
chan_info['kind'] = FIFF.FIFFV_MISC_CH
pick_mask[idx] = False
elif idx in stim_channel_idxs:
chan_info['coil_type'] = FIFF.FIFFV_COIL_NONE
chan_info['unit'] = FIFF.FIFF_UNIT_NONE
chan_info['kind'] = FIFF.FIFFV_STIM_CH
pick_mask[idx] = False
chan_info['ch_name'] = ch_name
ch_names[idx] = chan_info['ch_name']
edf_info['units'][idx] = 1
chs.append(chan_info)

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions