Skip to content

Brain GUI modernization (Phase 7) - #14270

Open
payamsash wants to merge 4 commits into
mne-tools:mainfrom
payamsash:brain_gui_7
Open

Brain GUI modernization (Phase 7)#14270
payamsash wants to merge 4 commits into
mne-tools:mainfrom
payamsash:brain_gui_7

Conversation

@payamsash

Copy link
Copy Markdown
Member

Reference issue (if any)

Phase 7 of #14042 and following #14222

What does this implement/fix?

Adds possibility to see brain activations in brain labels with different possible modes (e.g. mean-flip)

Additional information

following script is helpful for testing:

import numpy as np
import mne
from mne.datasets import sample

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

# without src, only mean/max are valid
src = mne.setup_source_space(
    "sample", spacing="oct6", subjects_dir=subjects_dir, add_dist=False
)
src_vertices = src[0]["vertno"]

brain = mne.viz.Brain(
    "sample", subjects_dir=subjects_dir, hemi="lh", background="black", show=False
)
coords = brain.geo["lh"].coords


def gaussian_patch(coords, center, sigma=15.0):
    d = np.linalg.norm(coords - center, axis=1)
    return np.exp(-(d**2) / (2 * sigma**2))


times = np.linspace(0, 1, 20)
temporal = gaussian_patch(coords, center=np.array([-52.0, -18.0, -8.0]))[src_vertices]
temporal_t = temporal[:, np.newaxis] * np.exp(3 * times)[np.newaxis, :]
brain.add_data(
    temporal_t,
    hemi="lh",
    vertices=src_vertices,
    src=src,
    fmin=0.1,
    fmax=1.0,
    colormap="hot",
    key="temporal",
    smoothing_steps=5,
    time=times,
    transparent=True,
)

frontal = gaussian_patch(coords, center=np.array([-38.0, 28.0, 46.0]))[src_vertices]
frontal_t = frontal[:, np.newaxis] * (1 - np.exp(-3 * times))[np.newaxis, :]
brain.add_data(
    frontal_t,
    hemi="lh",
    vertices=src_vertices,
    src=src,
    fmin=0.1,
    fmax=0.6,
    colormap="Blues",
    alpha=0.5,
    key="frontal",
    remove_existing=False,
    smoothing_steps=5,
    time=times,
    transparent=True,
)
brain.setup_time_viewer(show_traces=True)
brain.show()


@payamsash
payamsash requested a review from agramfort as a code owner September 4, 2026 05:20
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.

1 participant