Skip to content

Deep source modeling (phase 2) - #14450

Open
payamsash wants to merge 8 commits into
mne-tools:mainfrom
payamsash:enh/subcortical-plotting
Open

payamsash wants to merge 8 commits into
mne-tools:mainfrom
payamsash:enh/subcortical-plotting

Conversation

@payamsash

Copy link
Copy Markdown
Member

Reference issue (if any)

Following #14130

What does this implement/fix?

Now subcortical meshes are drawn as surfaces next to the cortex, and their colors follow the time slider and the colormap limits.

Additional information

Opus 5.5 helped implementing, I reviewed, did some modification and added an example.

@larsoner

Copy link
Copy Markdown
Member

@ttaiv do you want to look?

@ttaiv

ttaiv commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

@larsoner yes I do! I tried plotting data on the cerebellar mesh produced with CMB. Using the Brain class like in the new example worked nicely like this:

src = mne.setup_subcortical_source_space(
    subject="sample",
    surface=cerebellum_mesh_file,
    subjects_dir=subjects_dir,
    keep_largest_component=False,
)
data = np.random.rand(len(src[0]["vertno"]))

brain = mne.viz.Brain(
    "sample", subjects_dir=subjects_dir, hemi="both", surf="white", **brain_kwargs
)
brain.add_data(
    data,
    hemi="vol",
    vertices=src[0]["vertno"],
    src=src,
    fmin=0,
    fmax=1,
    colormap="viridis",
)
brain.show_view(azimuth=150, elevation=90, distance=400, focalpoint=(0, -10, 10))
image

But when I tried running the CMB example script and plot the source estimate like this

# Plotting MixedSourceEstimate
estimate.plot(
    subject=subject,
    subjects_dir=subjects_dir,
    src=fwd["src"],
    surface="white",
    hemi="lh",
)

the result looks weird:
image

@payamsash

payamsash commented Oct 27, 2026 •

Copy link
Copy Markdown
Member Author

My guess is that the brain is in MRI coordinate, but the cerebellum is in head coordinate ... becasue you put fwd["src"] ???

@ttaiv

ttaiv commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

You were correct. Adding coordinate transformation before plotting fixed the location:

# Plotting MixedSourceEstimate
src_plot = fwd["src"].copy()
mri_head_t = mne.read_trans(trans)
for s in src_plot:
    mne.transform_surface_to(s, "mri", mri_head_t)

estimate.plot(
    subject=subject,
    subjects_dir=subjects_dir,
    src=src_plot,
    surface="white",
    hemi="both",
)

But the estimate still floats in the air because the cerebellar surface is invisible. I think this is because the subcortical mesh has no opaque base layer, so its color comes only from the data layer. Wherever the data is transparent, the mesh disappears. Passing transparent=False and colormap="coolwarm" fixed this for me, because together they give a colormap with no transparent values.

@larsoner

Copy link
Copy Markdown
Member

You were correct. Adding coordinate transformation before plotting fixed the location:

Good to know. This is a bug in the code.... you shouldn't have to do that transformation yourself, our plotting function should checking and converting to the destination coordinate frame if needed

the cerebellar surface is invisible. I think this is because the subcortical mesh has no opaque base layer, so its color comes only from the data layer.

We should fix this, too. Our cortical ones have a base gray layer that sits underneath everything. I think all surfaces (cortical and subcortical) should behave like this. (This actually has an alpha of its own that you can set separately.)

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.

3 participants