Skip to content

streaming-safe scalar updates for mne.viz.Brain #13949

@payamsash

Description

@payamsash

Describe the new feature or enhancement

making mne.viz.Brain usable for real-time streaming applications (neurofeedback, BCI, live source imaging), as suggested in discussion with @larsoner.

Describe your proposed implementation

mne.viz.Brain uses pyvistaqt.BackgroundPlotter under the hood, but the
public API is not designed for repeated scalar updates from a background
thread:

brain.add_data() is designed to be called once, calling it repeatedly (once per analysis window) is not thread-safe because it recreates actors and scalar bars also brain.set_time() does not accept new data only works when the data was preloaded.

MNE-RT uses pyvistaqt.BackgroundPlotter directly, keep a single PolyData mesh, and update mesh["activity"] scalars in-place plus call p.render(), which BackgroundPlotter handles safely from a
non-Qt thread. see link:

Describe possible alternatives

Add a lightweight streaming update API to mne.viz.Brain, for example:

# One-time setup
brain = mne.viz.Brain("fsaverage", hemi="split", surf="inflated")
handle = brain.add_data(stc_empty, colormap="hot", clim=(0, 1))

# Called from any thread
handle.set_scalars(new_vertex_values)   # thread-safe scalar swap + render

Or expose the existing PolyData mesh directly so users can update scalars themselves:

brain.lh_mesh["activity"] = new_lh_values
brain.render()   # non-blocking

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions