Skip to content

ENH: Let vertexSelect event to carry the estimated source id - #14126

Open
Gnefil wants to merge 7 commits into
mne-tools:mainfrom
Gnefil:vertexselect-source-index
Open

ENH: Let vertexSelect event to carry the estimated source id#14126
Gnefil wants to merge 7 commits into
mne-tools:mainfrom
Gnefil:vertexselect-source-index

Conversation

@Gnefil

@Gnefil Gnefil commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Reference issue (if any)

Solves #14094.

What does this implement/fix?

Adds source id to the vertexSelect event. Carrying the source point when publishing the vertex select event makes interaction possible with other plots not aware of the source space.

Additional information

@larsoner

larsoner commented Aug 3, 2026

Copy link
Copy Markdown
Member

@wmvanvliet probably most relevant to you, being an event-related thing?

Comment thread mne/viz/_brain/_brain.py
Comment thread mne/viz/_brain/_brain.py
# shift = np.array(grid.GetOrigin()) + spacing / 2.
# ijk = np.round((pos - shift) / spacing).astype(int)
# vertex_id = np.ravel_multi_index(ijk, shape, order='F')
source_id = idx

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 rename idx -> source_id here and not starting from line 1446?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My intention here is to unify the variable name, is it worth it?

Comment thread mne/viz/ui_events.py Outdated
Comment thread mne/viz/ui_events.py Outdated
@Gnefil
Gnefil marked this pull request as ready for review August 7, 2026 19:04
Copilot AI lite review requested due to automatic review settings August 7, 2026 19:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances MNE-Python’s 3D Brain visualization UI event system by extending the VertexSelect event to include a source_id, enabling downstream callbacks to interact with other source-estimate-aware plots without re-computing vertex→source mappings.

Changes:

  • Extend mne.viz.ui_events.VertexSelect with a new source_id field.
  • Populate source_id when publishing vertex_select events from Brain (initial selection and picking).
  • Add a Towncrier changelog fragment documenting the new feature.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
mne/viz/ui_events.py Adds the source_id field to VertexSelect and documents it.
mne/viz/_brain/_brain.py Includes source_id in published VertexSelect events and maps mesh vertex selections to source indices.
doc/changes/dev/14126.newfeature.rst Changelog entry announcing the new source_id parameter.
Suppressed comments (2)

mne/viz/ui_events.py:189

  • source_id is optional (defaulting to None), but the type annotation is currently int = None, which is inconsistent and can break static type checking. Annotate it as int | None to match how other optional UI event fields are typed in this module.
    hemi: str
    vertex_id: int
    source_id: int = None

mne/viz/ui_events.py:184

  • The Attributes section should match the actual type/semantics of source_id (it can be None and is an index into the source estimate for the given hemisphere).
    vertex_id : int
        The vertex number (in the high resolution mesh) that was selected.
    source_id : int
        The index number of the closest source point to the vertex.
        Only set if the publishing figure contains a source estimate.

Comment thread mne/viz/ui_events.py
Comment thread mne/viz/_brain/_brain.py
Comment thread mne/viz/_brain/_brain.py
row = smooth_mat[vertex_id]
source_id = smooth_mat[vertex_id].argmax() if row.nnz else None

publish(self, VertexSelect(hemi=hemi, vertex_id=vertex_id, source_id=source_id))
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.

4 participants