Skip to content

FIX: Preserve subcortical source space IDs in forward and inverse solutions (#14460) - #14586

Open
ADITYASINGH1206 wants to merge 1 commit into
mne-tools:mainfrom
ADITYASINGH1206:fix/fwd-subcortical-id
Open

ADITYASINGH1206 wants to merge 1 commit into
mne-tools:mainfrom
ADITYASINGH1206:fix/fwd-subcortical-id

Conversation

@ADITYASINGH1206

Copy link
Copy Markdown

Reference issue (if any)

Fixes #14460.

What does this implement/fix?

When loading forward solutions or inverse operators with subcortical surface source spaces, read_forward_solution and read_inverse_operator unconditionally overwrote each source space's id with find_source_space_hemi(s). Because find_source_space_hemi assigns hemisphere IDs (101 or 102), this wiped out subcortical surface IDs (>= FIFFV_MNE_SURF_SUBCORTICAL_OFFSET, 1000+) and caused fwd["src"].kind to fail with RuntimeError: Invalid source space with kinds ['surf', 'surf', 'surf'].

This PR preserves existing source space IDs read from the FIF tags, and only falls back to find_source_space_hemi(s) if the surface ID is unknown (FIFFV_MNE_SURF_UNKNOWN), keeping compatibility with legacy files lacking FIFF_MNE_SOURCE_SPACE_ID.

  • Added fallback guard in mne/forward/forward.py and mne/minimum_norm/inverse.py
  • Added regression test test_forward_subcortical_io in mne/forward/tests/test_forward.py for mixed, subcortical-only, and legacy forward solutions
  • Added changelog entry in doc/changes/dev/14460.bugfix.rst

Additional information

All local checks (pytest mne/forward/tests/ and ruff) pass.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

read_forward_solution loses subcortical source spaces

1 participant