mne_rt.viz.BrainPlot#
- class mne_rt.viz.BrainPlot(subjects_fs_dir: str | Path, clim: tuple[float, float] = (0.0, 0.6), hemi_distance: float = 20.0, surf: str = 'inflated', cmap: str = 'hot', opacity: float = 0.6, window_size: tuple[int, int] = (1600, 1000), display_smoothing: float = 0.3, verbose: bool | str | None = None)[source]#
Bases:
objectInteractive real-time 3D brain activation display.
Renders bilateral
fsaveragecortical surfaces with a colour-mapped activity overlay and a Qt control panel docked on the right. Designed to run alongsideNFPlotinside a shared Qt event loop — callupdate_from_arrays()orupdate()from the acquisition thread’s pump timer.- Parameters:
- subjects_fs_dir
str|Path FreeSurfer subjects directory. The MNE-bundled
fsaveragetemplate is used automatically (auto-downloaded on first use); this path is accepted for API compatibility.- clim
tupleoffloat, default (0.0, 0.6) Initial
(min, max)colour-map range for the activity overlay.- hemi_distance
float, default 20.0 Gap in mm between the medial walls of the two hemispheres.
- surf{“inflated”, “pial”, “white”, “sphere”}, default “inflated”
Initial cortical surface geometry to display.
- cmap
str, default “hot” Initial colour map name. Must be one of
["hot", "plasma", "viridis", "Reds", "YlOrRd", "RdBu_r"].- opacity
float, default 0.6 Initial opacity of the activity overlay (0 = transparent, 1 = opaque).
- window_size
tupleofint, default (1600, 1000) Width × height of the render window in pixels.
- display_smoothing
float, default 0.3 EMA factor applied to the per-vertex activation arrays before each render.
1.0disables smoothing; lower values blend consecutive frames so the cortical map transitions smoothly instead of jumping between analysis windows.- verbosebool |
str|None, defaultNone Verbosity level.
- subjects_fs_dir
See also
mne_rt.viz.NFPlotScrolling real-time NF signal plot.
mne_rt.RTStream.record_mainMain NF loop that drives both plots.
Notes
Activity values are spread from the 10 242 ico-5 source vertices to all 163 842 fsaverage surface vertices via nearest-neighbour interpolation, giving a smooth spatial appearance.
Added in version 1.0.0.
- __init__(subjects_fs_dir: str | Path, clim: tuple[float, float] = (0.0, 0.6), hemi_distance: float = 20.0, surf: str = 'inflated', cmap: str = 'hot', opacity: float = 0.6, window_size: tuple[int, int] = (1600, 1000), display_smoothing: float = 0.3, verbose: bool | str | None = None) None[source]#
Methods
__init__(subjects_fs_dir[, clim, ...])record_video([path])Start recording the brain display to an MP4 video file.
Zero out all activity scalars and refresh the display.
screenshot([path])Save a PNG screenshot of the current brain view.
set_display_mode(mode)Switch the display mode label and reset clim to sensible defaults.
set_surface(surf)Switch the cortical surface geometry.
Stop recording and finalise the video file.
update(stc[, mode, interval])Animate the brain from a source time-course estimate.
update_from_arrays(lh_scalars, rh_scalars[, ...])Update the brain display from pre-computed per-source-vertex scalars.
Capture a video frame if recording is active (no-op otherwise).
Attributes
Current display mode string (e.g.
"Alpha Power (8–13 Hz)").The underlying
pyvistaqt.BackgroundPlotterinstance.Currently displayed surface geometry name.
- property custom_band: tuple[float, float] | None#
Active custom frequency band
(lo, hi)in Hz, orNone.Read this in the acquisition loop alongside
display_modeto decide which frequency range to pass toupdate_from_arrays(). When notNoneit overrides the built-in band labels.
- set_surface(surf: str) None[source]#
Switch the cortical surface geometry.
- Parameters:
- surf{“inflated”, “pial”, “white”, “sphere”}
Target surface geometry.
- update_from_arrays(lh_scalars: ndarray, rh_scalars: ndarray, mode: str = 'power', deferred: bool = False) None[source]#
Update the brain display from pre-computed per-source-vertex scalars.
Source values (10 242 per hemisphere) are spread to all 163 842 surface vertices via nearest-neighbour interpolation.
- Parameters:
- lh_scalars
ndarray,shape(10242,) Activity values for left-hemisphere source vertices.
- rh_scalars
ndarray,shape(10242,) Activity values for right-hemisphere source vertices.
- mode
str, default “power” Kept for API symmetry; unused internally.
- deferredbool, default
False If
True, skip the immediaterender()call.
- lh_scalars
- update(stc, mode: str = 'power', interval: float = 0.05) None[source]#
Animate the brain from a source time-course estimate.
- Parameters:
- stc
mne.SourceEstimate Source estimate returned by
apply_inverse_rawor similar.- mode{“power”, “activation”}, default “power”
"power"displays mean squared amplitude;"activation"displays the time-averaged amplitude.- interval
float, default 0.05 Seconds to pause between frame updates.
- stc
- set_display_mode(mode: str) None[source]#
Switch the display mode label and reset clim to sensible defaults.
The display mode is a label only — it tells both the operator and the visualisation what kind of values are being streamed in. Configure
record_main()with the matchingmodalityto pass the correct data.- Parameters:
- mode
str One of
_DISPLAY_MODES. Choosing a band-power mode will also set the colour-range (clim) to a typical power scale; choosing “Source Activation” restores the activation scale.
- mode
Notes
For band power modes pass per-source-vertex spectral power (e.g., from
modality="source_power") toupdate_from_arrays(). For activation mode pass eLORETA / dSPM amplitude values fromupdate()(stcfrom MNE inverse operator).
- property display_mode: str#
Current display mode string (e.g.
"Alpha Power (8–13 Hz)").Read this in the acquisition loop to decide which modality to compute and pass to
update_from_arrays().
- record_video(path: str | Path | None = None) Path[source]#
Start recording the brain display to an MP4 video file.
- stop_recording() Path | None[source]#
Stop recording and finalise the video file.
- Returns:
- path
Path|None
- path
- write_frame_if_recording() None[source]#
Capture a video frame if recording is active (no-op otherwise).
- screenshot(path: str | Path | None = None) Path[source]#
Save a PNG screenshot of the current brain view.
- property plotter: <MagicMock name='mock.BackgroundPlotter' id='4861751520'>#
The underlying
pyvistaqt.BackgroundPlotterinstance.