Skip to content

Commit 144a58c

Browse files
authored
[MRG, ENH] Get annotation description from snirf stim name (mne-tools#9575)
* Get annotation description from snirf stim name * Update changelog
1 parent 08b4b0e commit 144a58c

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

doc/changes/latest.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ Current (0.24.dev0)
3131

3232
.. |Pierre-Antoine Bannier| replace:: **Pierre-Antoine Bannier**
3333

34+
.. |Darin Erat Sleiter| replace:: **Darin Erat Sleiter**
35+
3436
Enhancements
3537
~~~~~~~~~~~~
3638
.. - Add something cool (:gh:`9192` **by new contributor** |New Contributor|_)
3739

40+
- Get annotation descriptions from the name field of SNIRF stimulus groups when reading SNIRF files via `mne.io.read_raw_snirf` (:gh:`9575` **by new contributor** |Darin Erat Sleiter|_)
41+
3842
- Add support for NIRSport and NIRSport2 devices to `mne.io.read_raw_nirx` (:gh:`9348` and :gh:`9401` **by new contributor** |David Julien|_, **new contributor** |Romain Derollepot|_, `Robert Luke`_, and `Eric Larson`_)
3943

4044
- New function :func:`mne.label.find_pos_in_annot` to get atlas label for MRI coordinates. (:gh:`9376` by **by new contributor** |Marian Dovgialo|_)

doc/changes/names.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,5 @@
401401
.. _Marian Dovgialo: https://github.com/mdovgialo
402402
403403
.. _Pierre-Antoine Bannier: https://github.com/PABannier
404+
405+
.. _Darin Erat Sleiter: https://github.com/dsleiter

mne/io/snirf/_snirf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ def natural_keys(text):
365365
data = np.atleast_2d(np.array(
366366
dat.get('/nirs/' + key + '/data')))
367367
if data.size > 0:
368-
annot.append(data[:, 0], 1.0, key[4:])
368+
desc = dat.get('/nirs/' + key + '/name')[0]
369+
annot.append(data[:, 0], 1.0, desc.decode('UTF-8'))
369370
self.set_annotations(annot)
370371

371372
# Reorder channels to match expected ordering in MNE

mne/io/snirf/tests/test_snirf.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# simplified BSD-3 license
44

55
import os.path as op
6-
from numpy.testing import assert_allclose, assert_almost_equal
6+
from numpy.testing import assert_allclose, assert_almost_equal, assert_equal
77
import shutil
88
import pytest
99

@@ -288,3 +288,12 @@ def test_snirf_standard():
288288
"""Test standard operations."""
289289
_test_raw_reader(read_raw_snirf, fname=sfnirs_homer_103_wShort,
290290
boundary_decimal=0) # low fs
291+
292+
293+
@requires_testing_data
294+
@requires_h5py
295+
def test_annotation_description_from_stim_groups():
296+
"""Test annotation descriptions parsed from stim group names."""
297+
raw = read_raw_snirf(nirx_nirsport2_103_2, preload=True)
298+
expected_descriptions = ['1', '2', '6']
299+
assert_equal(expected_descriptions, raw.annotations.description)

0 commit comments

Comments
 (0)