Skip to content

Allow exporting STIM channels to EDF - #12332

Merged
larsoner merged 12 commits into
mne-tools:mainfrom
cbrnr:export-edf
Mar 18, 2024
Merged

larsoner merged 12 commits into
mne-tools:mainfrom
cbrnr:export-edf

Conversation

@cbrnr

@cbrnr cbrnr commented Jan 3, 2024

Copy link
Copy Markdown
Contributor

Fixes #9883.

@cbrnr

cbrnr commented Jan 4, 2024

Copy link
Copy Markdown
Contributor Author

@hofaflo currently the unit for exporting is hard-coded to "uV" (https://github.com/mne-tools/mne-python/blob/main/mne/export/_edf.py#L159). However, STIM channels should not be rescaled, but I'm not sure (1) which unit to use (maybe "V"?) and (2) which units EDF supports (probably any arbitrary string). Do you have a suggestion how to proceed?

@cbrnr cbrnr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready for review @larsoner @drammock.

Comment thread mne/export/tests/test_export.py Resolved
Comment thread mne/export/_edf.py Resolved
Comment thread mne/export/_edf.py
Comment on lines -43 to -62
# Add warning if any channel types are not voltage based.
# Users are expected to only export data that is voltage based,
# such as EEG, ECoG, sEEG, etc.
# Non-voltage channels are dropped by the export function.
# Note: we can write these other channels, such as 'misc'
# but these are simply a "catch all" for unknown or undesired
# channels.
voltage_types = list(units) + ["stim", "misc"]
non_voltage_ch = [ch not in voltage_types for ch in orig_ch_types]
if any(non_voltage_ch):
warn(
f"Non-voltage channels detected: {non_voltage_ch}. MNE-Python's "
"EDF exporter only supports voltage-based channels, because the "
"EDF format cannot accommodate much of the accompanying data "
"necessary for channel types like MEG and fNIRS (channel "
"orientations, coordinate frame transforms, etc). You can "
"override this restriction by setting those channel types to "
'"misc" but no guarantees are made of the fidelity of that '
"approach."
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, the goal is to write STIM channels. But I don't get why that entails removing this warning? As the edited test shows, now there is no warning when writing e.g. hbr channels. Can you explain the logic of why this is being removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because that warning doesn't make sense to me. I know it's not specific to STIM channels, but EDF can accommodate arbitrary signal types. Just because some domain-specific meta-information cannot be stored is not really an argument against non-voltage channels (especially since we don't store e.g. channel locations for EEG data either). Also, converting to "misc" was not necessary as the warning suggests, so it is misleading.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't store e.g. channel locations for EEG data either

oh wow, OK. I'd forgotten that. I just looked at the docstring of export_raw() and it does already have appropriate warnings in the Notes section (though they do say "stim channels will be dropped" --- you should change that in this PR).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@cbrnr

cbrnr commented Mar 18, 2024

Copy link
Copy Markdown
Contributor Author

@larsoner @drammock please feel free to merge if you're happy. I'd like to get this in before tackling #12493.

@larsoner

Copy link
Copy Markdown
Member

Looks like you've addressed the remaining comments and it's green, thanks @cbrnr !

@larsoner
larsoner merged commit 6eb4c3f into mne-tools:main Mar 18, 2024
@cbrnr
cbrnr deleted the export-edf branch March 18, 2024 15:34
snwnde pushed a commit to snwnde/mne-python that referenced this pull request Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support STIM channels in EDF export

3 participants