Description of the problem
mne.io.read_raw_snirf raises TypeError: iteration over a 0-d array when reading SNIRF files where /nirs/probe/landmarkLabels exists but is empty or scalar.
Steps to reproduce
import mne # Download test file from OpenNeuro ds005929
# File: sub-6016_ses-1_task-MA_run-01_nirs.snirf raw = mne.io.read_raw_snirf("sub-6016_ses-1_task-MA_run-01_nirs.snirf")
Link to data
aws s3 sync --no-sign-request s3://openneuro.org/ds005929/sub-6016 ./ds005929/sub-6016
Expected results
File loads successfully, treating empty landmark labels as no landmarks.
Actual results
Actual Behavior
TypeError: iteration over a 0-d array
Full traceback:
File "mne/io/snirf/_snirf.py", line 393,
in __init__ for idx, dign in enumerate(digname):
TypeError: iteration over a 0-d array
Root Cause
In _snirf.py line 390, landmarkLabels is converted to a numpy array without checking dimensions:
digname = np.array(dat.get("/nirs/probe/landmarkLabels"))
When landmarkLabels is empty or scalar, this creates a 0-d array that cannot be iterated.
Suggested Fix
Apply _correct_shape() (already defined in the file) to digname, or add a dimension check:
digname = np.array(dat.get("/nirs/probe/landmarkLabels"))
if digname.ndim == 0:
digname = digname.reshape(-1) if digname.size > 0 else []
Additional information
Platform
- MNE: 1.12.0.dev (bug also present in
main branch) - Python: 3.12 - OS: macOS
Description of the problem
mne.io.read_raw_snirfraisesTypeError: iteration over a 0-d arraywhen reading SNIRF files where/nirs/probe/landmarkLabelsexists but is empty or scalar.Steps to reproduce
Link to data
Expected results
File loads successfully, treating empty landmark labels as no landmarks.
Actual results
Actual Behavior
TypeError: iteration over a 0-d arrayFull traceback:
Root Cause
In
_snirf.pyline 390,landmarkLabelsis converted to a numpy array without checking dimensions:When
landmarkLabelsis empty or scalar, this creates a 0-d array that cannot be iterated.Suggested Fix
Apply
_correct_shape()(already defined in the file) todigname, or add a dimension check:Additional information
Platform
mainbranch) - Python: 3.12 - OS: macOS