Skip to content

BUG: SourceMorph spacing-attribute inconsistent #12101

Open

Description

@marsipu

Description of the problem

When src_to is supplied to compute_source_morph and is has a spacing other then "ico5", the spacing-attribute of the resulting SourceMorph doesn't seem to be consistent (see example below)

Steps to reproduce

import mne
from mne.datasets import sample

data_path = sample.data_path()
subjects_dir = data_path / "subjects"

# oct6 spacing
src_from = mne.read_source_spaces(subjects_dir / "sample" / "bem" / "sample-oct-6-src.fif")
subject_from = "sample"
# ico5 spacing
src_to = mne.read_source_spaces(subjects_dir / "fsaverage" / "bem" / "fsaverage-ico-5-src.fif")
subject_to = "fsaverage"
morph = mne.compute_source_morph(
    src_from,
    subject_from=subject_from,
    subject_to=subject_to,
    src_to=src_to,
    subjects_dir=subjects_dir,
)
assert morph.spacing == 5

# When you switch src_from and src_to, the spacing should be 6 since the target source-space has a spacing of oct6.
# But it is still 5.
morph = mne.compute_source_morph(
    src_to,
    subject_from=subject_to,
    subject_to=subject_from,
    src_to=src_from,
    subjects_dir=subjects_dir,
)
# This fails
assert morph.spacing == 6

Link to data

No response

Expected results

SourceMorph.spacing being consistent with spacing of src_to

Actual results

It's always 5 (or the value currently supplied to spacing, which should be ignored when src_to is supplied)

Additional information

Platform Windows-10-10.0.22621-SP0
Python 3.11.6 | packaged by conda-forge | (main, Oct 3 2023, 10:29:11) [MSC v.1935 64 bit (AMD64)]

Core
├☑ mne 1.6.0.dev24+g22ffe6f7a
├☑ numpy 1.24.4 (OpenBLAS 0.3.24 with 32 threads)
├☑ scipy 1.11.3
├☑ matplotlib 3.8.0 (backend=QtAgg)
├☑ pooch 1.7.0
└☑ jinja2 3.1.2

Numerical (optional)
├☑ sklearn 1.3.1
├☑ numba 0.57.1
├☑ nibabel 5.1.0
├☑ nilearn 0.10.2
├☑ dipy 1.7.0
├☑ openmeeg 2.5.6
├☑ pandas 2.1.1
└☐ unavailable cupy

Visualization (optional)
├☑ pyvista 0.42.3 (OpenGL 4.6.0 Compatibility Profile Context 23.9.3.230915 via AMD Radeon(TM) Graphics)
├☑ pyvistaqt 0.0.0
├☑ vtk 9.2.6
├☑ qtpy 2.4.0 (PyQt5=5.15.8)
├☑ ipympl 0.9.3
├☑ pyqtgraph 0.13.3
├☑ mne-qt-browser 0.6.0.dev13+g481264d
└☐ unavailable ipyvtklink

Ecosystem (optional)
├☑ mne-bids 0.14.dev0
├☑ mne-connectivity 0.6.0dev0
└☐ unavailable mne-nirs, mne-features, mne-icalabel, mne-bids-pipeline

Activity

  1. larsoner commented on Oct 11, 2023

    @larsoner
    Member

    Agreed this is a bug. To me spacing=None should be the default, which means "use spacing=5 if src_to is None, else leave as None". I don't think we can reliably/safely detect the spacing that was used in all cases so it's safer just to set it to None if using src_to. Then morph.spacing == 5 implies "using ico-5 with fsaverage". And we should probably raise an error if you use spacing=5 with non-fsaverage subjects since I think it's really meant to be a shorthand for that...

  2. Famous077 commented on Feb 25, 2026

    @Famous077
    Contributor

    Hi @larsoner @marsipu I'd like to work on this bug. I'll look into how spacing is set in
    compute_source_morph when src_to is provided and open a PR shortly.

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