Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow exporting STIM channels to EDF #12332

Merged
merged 12 commits into from
Mar 18, 2024
Merged

Allow exporting STIM channels to EDF #12332

merged 12 commits into from
Mar 18, 2024

Conversation

cbrnr
Copy link
Contributor

@cbrnr cbrnr commented Jan 3, 2024

Fixes #9883.

@cbrnr
Copy link
Contributor Author

cbrnr commented Jan 4, 2024

@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?

Copy link
Contributor Author

@cbrnr cbrnr left a comment

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.

mne/export/_edf.py Outdated Show resolved Hide resolved
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
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
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
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
Contributor Author

Choose a reason for hiding this comment

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

Done!

@cbrnr
Copy link
Contributor Author

cbrnr commented Mar 18, 2024

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

@larsoner
Copy link
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
30 checks passed
@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