Skip to content

Brain GUI modernization (Phase 4) - #14102

Merged
wmvanvliet merged 7 commits into
mne-tools:mainfrom
payamsash:enh/brain-gui-phase4
Aug 7, 2026
Merged

Brain GUI modernization (Phase 4)#14102
wmvanvliet merged 7 commits into
mne-tools:mainfrom
payamsash:enh/brain-gui-phase4

Conversation

@payamsash

@payamsash payamsash commented Jul 26, 2026

Copy link
Copy Markdown
Member

Reference issue (if any)

Phase 4 of #14042 and following #14085

What does this implement/fix?

add surf and cortex options to GUI

Additional information

Claude reviewed the code and I understand what has been modified.

@payamsash payamsash changed the title add surf and cortex to gui Brain GUI modernization (Phase 4) Jul 26, 2026
assert brain._alpha == 0.5

brain.set_cortex_colormap("bone")
assert brain._cortex_preset == "bone"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't test whether the new colors are actually shown, like you do below with changing surf

Comment thread mne/viz/_3d_overlay.py
rng=rng,
opacity=opacity,
name=name,
smooth=smooth,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a new smooth parameter? We already had controls for the amount of smoothing, which you could set to 1 to turn it off.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smooth_mat lives on the whole mesh but the new smooth just tracks per-overlay.

@payamsash

payamsash commented Jul 30, 2026

Copy link
Copy Markdown
Member Author

ready to be reviewed @wmvanvliet , tnx in advance, phase 5 is almost ready ...

@wmvanvliet

Copy link
Copy Markdown
Contributor

When selecting some vertices, the spheres don't update when switching surfaces.

Have you tried this with a VectorSourceEstimate?

@payamsash

payamsash commented Aug 4, 2026

Copy link
Copy Markdown
Member Author

Sharp eyes! you can now test it with this small script:

import mne
from mne.datasets import sample
from mne.minimum_norm import apply_inverse, make_inverse_operator

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

fwd = mne.read_forward_solution(meg_path / "sample_audvis-meg-oct-6-fwd.fif")
fwd = mne.pick_types_forward(fwd, meg=True, eeg=False)
evoked = mne.read_evokeds(meg_path / "sample_audvis-ave.fif", baseline=(None, 0))[0]
noise_cov = mne.read_cov(meg_path / "sample_audvis-cov.fif")

inv = make_inverse_operator(evoked.info, fwd, noise_cov, loose=1.0)
stc = apply_inverse(evoked, inv, pick_ori="vector")

brain = stc.plot(
    subject="sample",
    hemi="lh",
    subjects_dir=subjects_dir,
    colormap="auto",
    show_traces=True,
    initial_time=0.1,
)

Comment thread mne/viz/_brain/_brain.py Outdated
for sphere in spheres:
mesh = sphere["mesh"]
mesh.points = mesh.points + (center - np.array(mesh.center))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be an entire separate method if it's only called once?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, if it was only one method, I would fold it into set_surf but now we have two (_reposition_vertex_glyphs + _reposition_vector_glyphs), just for better readability ...

@wmvanvliet wmvanvliet Aug 5, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but I disagree that splitting off that functionality in two private method, both of which are only called once, is more readable. _brain.py currently sits at 4859 lines with 65 helper functions. It's fair to say this thing has gotten a bit out of control, hasn't it? This is why I'm not a big fan of adding even more helper functions if not really necessary. In this case, the functions only encapsulate a few lines of code that I don't think hurt much if just left in brain.set_surf.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Done.
Maybe we can check and trim some helper functions later (in another PR).

@wmvanvliet

Copy link
Copy Markdown
Contributor

Looks like we just need a changelog entry and then it's good to go from my end.

@payamsash
payamsash requested a review from agramfort as a code owner August 6, 2026 15:26
@payamsash

Copy link
Copy Markdown
Member Author

Thanks @wmvanvliet

@wmvanvliet
wmvanvliet merged commit b3d23ee into mne-tools:main Aug 7, 2026
37 of 38 checks passed
@wmvanvliet

Copy link
Copy Markdown
Contributor

Thanks, @payamsash!

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.

2 participants