Skip to content

read_raw_snirf fails with TypeError when landmarkLabels is empty #13627

Description

@bruAristimunha

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions