mne-tools / mne-python

MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
https://mne.tools
BSD 3-Clause "New" or "Revised" License
2.67k stars 1.31k forks source link

Get annotation descriptions from the stim name when reading snirf files #9571

Closed dsleiter closed 3 years ago

dsleiter commented 3 years ago

Describe the new feature or enhancement

When loading a SNIRF file via mne.io.read_raw_snirf, the descriptions for Annotations are currently extracted from the keys of the SNIRF stim indexed groups. According to the SNIRF file format spec, what is currently being extracted as the Annotation description is the index of the stim rather than a descriptive string.

group: a structure containing sub-fields (defined in the H5G object class). Arrays of groups, also known as the indexed-groups, are denoted with numbers at the end (e.g. /nirs/data1, /nirs/data2) starting with index 1. Array indices should be contiguious with no skipped values (an empty group with no sub-member is permitted).

A better field to get a description from is the stimulus group name field which is described as:

This is a string describing the jth stimulus condition.

The proposed change is to get Annotation descriptions from the stimulus name rather than the index.

Describe your proposed implementation

Update RawSNIRF.__init__ lines 362:369 to take the description field from the name field of the stim group rather than the stim group key.

Describe possible alternatives

The descriptions can be left as-is. Although the match between an Annotation description and a SNIRF stimulus name isn't perfect, it seems like an improvement over using the stimulus index as-is.

If the description is not changed, then tests for the MNE-NIRS SNIRF writer will need to be changed (see Additional comments below).

Additional comments

This is related to https://github.com/mne-tools/mne-nirs/pull/326, where the MNE-NIRS SNIRF writer is being updated to be more consistent with the SNIRF spec.

MNE-NIRS currently has tests which use the MNE-Python SNIRF reader to make a round trip write/read test. Resolving this issue will ensure that the annotation descriptions remain the same after a round trip.

welcome[bot] commented 3 years ago

Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴🏽‍♂️

dsleiter commented 3 years ago

I am willing to work on this issue.