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

read_snirf_aux_data() / _decode_name() fails when name of aux channel is string scalar #557

Open
kdarti opened this issue Jun 5, 2024 · 1 comment

Comments

@kdarti
Copy link

kdarti commented Jun 5, 2024

Describe the bug

According to the snirf spec strings should be stored as as scalars, not as 1x1 arrays.

image

The example aux dataset used in the aux tutorial has strings in 1x1 array.

image

The read_snirf_aux_data() function works fine with this dataset that has strings in 1x1 array, but when the name of aux channel is scalar the _decode_name() function fails.

def _decode_name(key):
return np.array(key)[0].decode()

image

To properly retrieve the scalar string,

Steps to reproduce

Can use this file (ignore other possible issues with the file):
04_single.zip

import mne
import mne_nirs

snirf_file = r"04_single.snirf"
raw = mne.io.read_raw_snirf(snirf_file)
raw_od = mne.preprocessing.nirs.optical_density(raw)
raw_haemo = mne.preprocessing.nirs.beer_lambert_law(raw_od, ppf=0.1)
aux_df = mne_nirs.io.snirf.read_snirf_aux_data(snirf_file,raw_haemo)

Expected results

Should work since strings are stored as scalar, in accordance with snirf spec.

Actual results

Fail since _decode_name() only works on arrays

Additional information

Could add conditional to check if it's a scalar, and in that case handle it as such, e.g.:

def _decode_name(key):
if key.shape == ():
return key[()].decode()
else:
return np.array(key)[0].decode()

@kdarti
Copy link
Author

kdarti commented Jun 5, 2024

I got a little confused during testing becuase the official snirf samples are also incorrect, in their own way, c..f. fNIRS/snirf-samples#9

Given I'm reading the snirf spec correctly the example file I provided should have the correct string format.

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

No branches or pull requests

1 participant