Repository navigation
Description
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:
Lines 387 to 416 in 22cd774
| 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:
- [MRG, BUG] Fixed bug with EDF channel types and minor bug where other types of channels were not written and bug where annotations were not written to correct scale #9694
- [MRG] Enable export of EDF files #9643
See:
- https://edfplus.info/specs/edftexts.html#signals for description of string channel types in EDF
- https://edfplus.info/specs/edftexts.html#label for the specification of the channel label in EDF
Activity
adam2392 commentedon Aug 30, 2021
If core-devs agree this is desired behavior, then I can add a PR.
larsoner commentedon Aug 30, 2021
Has anyone ever encountered such files in the wild? If not, then I wouldn't add support for it until we hit a use case where it's actually needed
adam2392 commentedon Aug 30, 2021
All my files actually have the
EEG(i.e. channel type) prefix in the channel label. I can add a dummy file to misc/testing, but I think maybe one of the EDF files have it too. I can double check.larsoner commentedon Aug 30, 2021
Okay sounds justified enough to me! Bonus points if some testing data are aleady formatted that way but even if not I'm happy with you having some files.
For my edification, what system/conversion routine produced those files with the channel type encoded?
adam2392 commentedon Aug 30, 2021
I believe the recording system at this center used Nihon Kohden. However, it might've done the conversion through Persyst instead.
My suspicion is that not "all files" have this behavior as the "string channel label" in EDF is not strictly required to have the channel type. It's just a pattern in the string that is available if need be. I.e. I've seen some files from Nihon Kohden (or Natus) converted that don't have it. :(
Therefore, I don't think the change will be that bad since it's really just adding an if/else clause capturing the "space" in the string label if it detects there are.
adam2392 commentedon Aug 30, 2021
Added PR to mne-testing-data: mne-tools/mne-testing-data#88
larsoner commentedon Aug 30, 2021
+1 for adding a
ch_typemapping for this during reading (and exporting) in MNE-Python from me then. Hopefully we support all channel types EDF does, but any that we don't we should probably map to EEG (?) and issue a warning.adam2392 commentedon Aug 30, 2021
Yeah it seems like they map to EEG by default currently, so I'm okay with just leaving that as is.
Do you think a warning is necessary if that's current behavior? I suppose for a newbie to MNE, having channel "DC01" map to EEG because it doesn't have a channel type wouldn't be expected.
larsoner commentedon 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:
cbrnr commentedon Aug 30, 2021
I have never used EDF files with this naming convention. Can you check the names in https://physionet.org/content/eegmmidb/1.0.0/? I'm OK with deducing the channel type if the names follow this scheme, but I'm -1 on modifying existing labels on export.
adam2392 commentedon Aug 30, 2021
Re reading it in: Not all files will have it. I showed a screenshot of a file that does. Many files though may just have the channel name. This is just a consequence of different manufacturing systems exporting EDF files differently.
Re exporting: The standard has this built in, so it wouldn't hurt to have it export if the channel type information is there. One would lose roundtrip ability with 'misc', and 'bio' channels perhaps, but everything else is preserved as intended i.e. the Voltage channels EEG, ECOG, SEEG, etc.
We wouldn't break anything because by our construction, the EDF file will still be EDF-compliant, and so any downstream software can still read the file.
wdyt?
cbrnr commentedon Aug 30, 2021
Then at least let's have a parameter that controls this behavior.
adam2392 commentedon Aug 30, 2021
So if you have the following channels:
Then a parameter would either let their labels be written as the following in the EDF file?
or
Is there any reason to want the labels be the first way, rather than the second? Mistakes by user?
adam2392 commentedon Aug 30, 2021
Well I suppose one would want to toggle it yes when exporting from a FIFF file where the original names are:
One wouldn't want to accidentally add an extra channel type string in front of each of those.