`read_forward_solution` loses subcortical source spaces
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 55/100
Direzione di ricerca
Start at mne/forward/forward.py lines 610-612, where read_forward_solution rebuilds fwd['src'], and compare it with the write path; the subcortical IDs (1018) suggest the source-space reading loses the extra surface entries. Trace how setup_subcortical_source_space (#14130) marks those spaces and how src.kind derives subcortical_surf/mixed. Done means the issue's round-trip script prints the expected kinds and IDs, and a forward write/read test is added alongside the existing subcortical tests.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description of the problem
A forward solution built from a subcortical surface source space (`setup_subcortical_source_space, added in #14130) doesn't survive a write/read round trip. The issue seems to be here:
https://github.com/mne-tools/mne-python/blob/main/mne/forward/forward.py#L610-L612
Steps to reproduce
# %% Imports
import tempfile
from pathlib import Path
import mne
from mne.datasets import sample
# %% Setup
data_path = sample.data_path()
subjects_dir = data_path / "subjects"
info = mne.io.read_info(data_path / "MEG" / "sample" / "sample_audvis_raw.fif")
trans = data_path / "MEG" / "sample" / "sample_audvis_raw-trans.fif"
bem = mne.read_bem_solution(subjects_dir / "sample" / "bem" / "sample-5120-bem-sol.fif")
tmp_dir = Path(tempfile.mkdtemp())
# %% Read cortex source space and create subcortical source space.
src_cortex = mne.read_source_spaces(
subjects_dir / "sample" / "bem" / "sample-oct-6-src.fif"
)
src_subcortical = mne.setup_subcortical_source_space(
"sample", label="Left-Amygdala", subjects_dir=subjects_dir
)
# %% Define helper function to create a forward solution, write it to disk, and read it back.
def meg_forward_round_trip(src, name):
fwd = mne.make_forward_solution(
info, trans, src, bem, meg=True, eeg=False, verbose=False
)
print(f"{name} in memory:", fwd["src"].kind, [s["id"] for s in fwd["src"]])
fname = tmp_dir / f"{name}-fwd.fif"
mne.write_forward_solution(fname, fwd, verbose=False)
fwd_read = mne.read_forward_solution(fname, verbose=False)
ids = [s["id"] for s in fwd_read["src"]]
try:
kind = fwd_read["src"].kind
except RuntimeError as err:
kind = f"RuntimeError: {err}"
print(f"{name} read back:", kind, ids)
# %% Subcortical only: expected subcortical_surf [1018], read back as mixed [101].
meg_forward_round_trip(src_subcortical, "subcortical")
# %% Cortex + subcortical: expected mixed [101, 102, 1018], src.kind raises.
meg_forward_round_trip(src_cortex + src_subcortical, "mixed")
Link to data
No response
Expected results
subcortical in memory: subcortical_surf [1018]
subcortical read back: subcortical_surf [1018]
mixed in memory: mixed [101, 102, 1018]
mixed read back: mixed [101, 102, 1018]
Actual results
subcortical in memory: subcortical_surf [1018]
subcortical read back: mixed [101]
mixed in memory: mixed [101, 102, 1018]
mixed read back: RuntimeError: Invalid source space with kinds ['surf', 'surf', 'surf'] [101, 102, 101]
Additional information
A forward I/O round trip should probably be added to the subcortical tests too. Related: #14097, #14130, #14450.
mne.sys_info() output:
Platform Linux-6.17.0-1033-oem-x86_64-with-glibc2.39 (Wayland)
Python 3.13.13 (main, Jun 2 2026, 22:27:49) [Clang 22.1.3 ]
Executable /m/home/home6/69/taivait1/unix/dippa/mne-python/.venv/bin/python
CPU 12th Gen Intel(R) Core(TM) i5-12600K (16 cores)
Memory 31.0 GiB
Core
├☑ mne 1.14.0.dev135+gc16370a2b.d20261027 (development, latest release is 1.13.2)
├☑ numpy 2.5.4 (OpenBLAS 0.3.31.dev with 16 threads via pthreads)
├☑ scipy 1.18.1
└☑ matplotlib 3.11.2 (backend=module://matplotlib_inline.backend_inline)
Numerical (optional)
├☑ scikit-learn 1.9.1
├☑ threadpoolctl 3.7.0
├☑ nibabel 5.4.2
├☑ dipy 1.12.1
├☑ pandas 3.1.0
├☑ h5py 3.16.0
└☐ unavailable numba, nilearn, openmeeg, python-picard, jamica, cupy, h5io
Visualization (optional)
├☑ pyvista 0.49.1 (OpenGL 4.5.0 NVIDIA 580.196.07 via NVIDIA RTX A2000 12GB/PCIe/SSE2)
├☑ pyvistaqt 0.13.1
├☑ vtk 9.7.1
├☑ qtpy 2.4.3 (PySide6=6.12.0)
└☐ unavailable ipympl, pyqtgraph, mne-qt-browser, ipywidgets, trame, trame_client, trame_server, trame_pyvista, trame_vtk, trame_vuetify
Ecosystem (optional)
├☑ mne-bids 0.20.0
├☑ mne-connectivity 0.9.0
├☑ neo 0.14.6
├☑ eeglabio 0.1.4
├☑ edfio 0.4.18
├☑ pybv 0.8.1
├☑ pymef 1.4.8
├☑ defusedxml 0.7.1
└☐ unavailable mne-nirs, mne-features, mne-icalabel, mne-bids-pipeline, autoreject, curryreader, mffpy, antio
- Lingua principale
- Python
- Stelle
- 3.6k
- Fork
- 1.6k
- Merge medio
- 1g 20h
- PR unite (30g)
- 73
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di mne-tools/mne-python
-
BUG
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
mne-tools/mne-python#14478 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
BUG
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
mne-tools/mne-python#14477 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
ENH: Add `description` filter parameter to `Raw.crop_by_annotations()`Forse già presa @aman-coder03 l’ha presa 210 giorni fa. ApertaENH
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
mne-tools/mne-python#13743 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Wrong exponent in the denominator of the transfer function in the filtering background tutorialForse già presa @qxzzxq l’ha presa oggi. ApertaDOC
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 20/100
mne-tools/mne-python#14486 ·
I maintainer di solito rispondono entro 1 giorno
-
cannot plot into matplotlib subfigureForse già presa @ishaaaan17 l’ha presa oggi. ApertaBUG
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
mne-tools/mne-python#14481 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di mne-tools/mne-python
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
earthtojake/text-to-cad#758 ·
I maintainer di solito rispondono entro 1 giorno
-
domain:upgrades enhancement needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
gke-labs/kube-agents#4634 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
agardnerIT/opamp-server-py#116 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
elviskahoro/sdk-python-attio#144 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno