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

SNIRF loader not working with the official samples #9265

Closed HanBnrd closed 3 years ago

HanBnrd commented 3 years ago

Describe the bug

The function read_raw_snirf returns errors with the official samples from https://github.com/fNIRS/snirf-samples/.

Steps to reproduce

With Simple_Probe.snirf:

from mne.io import read_raw_snirf

snirf_intensity = read_raw_snirf('Simple_Probe.snirf')

With minimum_example.snirf:

from mne.io import read_raw_snirf

snirf_intensity = read_raw_snirf('minimum_example.snirf')

Expected results

Loading Simple_Probe.snirf

and

Loading minimum_example.snirf

respectively.

Actual results

Loading Simple_Probe.snirf
...\snirf.py:3: RuntimeWarning: Non uniform sampled data not supported.
  snirf_intensity = read_raw_snirf('Simple_Probe.snirf')
...\snirf.py:3: RuntimeWarning: Unable to extract sample rate from SNIRF file.
  snirf_intensity = read_raw_snirf('Simple_Probe.snirf')
Traceback (most recent call last):
  File "...\snirf.py", line 3, in <module>
    snirf_intensity = read_raw_snirf('Simple_Probe.snirf')
  File "...\mne-python\mne\io\snirf\_snirf.py", line 43, in read_raw_snirf
    return RawSNIRF(fname, preload, verbose)
  File "<decorator-gen-248>", line 24, in __init__
  File "...\mne-python\mne\io\snirf\_snirf.py", line 112, in __init__
    sources = [s.decode('UTF-8') for s in sources]
  File "...\mne-python\mne\io\snirf\_snirf.py", line 112, in <listcomp>
    sources = [s.decode('UTF-8') for s in sources]
AttributeError: 'numpy.ndarray' object has no attribute 'decode'

and

Loading minimum_example.snirf
...\snirf.py:3: RuntimeWarning: Non uniform sampled data not supported.
  snirf_intensity = read_raw_snirf('minimum_example.snirf')
...\snirf.py:3: RuntimeWarning: Unable to extract sample rate from SNIRF file.
  snirf_intensity = read_raw_snirf('minimum_example.snirf')
Traceback (most recent call last):
  File "...\snirf.py", line 3, in <module>
    snirf_intensity = read_raw_snirf('minimum_example.snirf')
  File "...\mne-python\mne\io\snirf\_snirf.py", line 43, in read_raw_snirf
    return RawSNIRF(fname, preload, verbose)
  File "<decorator-gen-248>", line 24, in __init__
  File "...\mne-python\mne\io\snirf\_snirf.py", line 112, in __init__
    sources = [s.decode('UTF-8') for s in sources]
TypeError: iteration over a 0-d array

respectively.

Additional information

This tutorial from MNE-NIRS works fine on my machine.

HanBnrd commented 3 years ago

Hi, just pinging @rob-luke. I will try to have a look at it ASAP.

HanBnrd commented 3 years ago

I created a separate issue for the sourcePos3D problem: #9308

rob-luke commented 3 years ago

We should ensure we follow the SNIRF standard. However, from memory not all files in the examples repo do. What specific part of our reader is diverging from the standard?

HanBnrd commented 3 years ago

Thanks @rob-luke, you are right, my bad. Both files do not pass the snirf_validator.py.

Some modifications of the samples are planned according to https://github.com/fNIRS/snirf/issues/44, so maybe better to close this issue. Sorry about that.

rob-luke commented 3 years ago

That's good to know. Thanks for checking this. I probably wouldn't trust that validator either. Just the spec is valid

rob-luke commented 3 years ago

I just received some SNIRF files from NIRx. So I will test and ensure these load in to our reader.