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, in
(0, 1].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
The cortex is drawn at the resolution of an ico-5 source space: the 10 242 vertices per hemisphere the activity is estimated on, which are the first 10 242 of fsaverage’s. Values are interpolated across each triangle. The full 163 842-vertex surface made every update upload sixteen times more data to the GPU for no extra information, about 0.2 s per frame.
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, ...])Go back to the display mode's own band.
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_band(band)Show activation (
None) or source power inband, in Hz.set_custom_band(lo, hi)Show source power in
lo–hiHz, from the next window on.set_display_mode(mode)Choose what the display shows, from the next window on.
set_surface(surf)Switch the cortical surface geometry.
Stop recording and finalise the video file.
update(stc[, mode])Show one frame of a surface source estimate on fsaverage.
update_from_arrays(lh_scalars, rh_scalars[, ...])Update the brain display from per-source-vertex values.
Capture a video frame if recording is active (no-op otherwise).
Attributes
What to compute for the display: a band in Hz, or
Nonefor activation.Active custom frequency band
(lo, hi)in Hz, orNone.Current display mode string (e.g.
"Alpha Power (8–13 Hz)").The underlying
pyvistaqt.BackgroundPlotterinstance.Currently displayed surface geometry name.
- set_custom_band(lo: float, hi: float) None[source]#
Show source power in
lo–hiHz, from the next window on.- Parameters:
- lo, hi
float Band edges in Hz,
lo < hi.
- lo, hi
- set_band(band: tuple[float, float] | None) None[source]#
Show activation (
None) or source power inband, in Hz.A band that one of the display modes covers selects that mode; any other becomes a custom band.
- property custom_band: tuple[float, float] | None#
Active custom frequency band
(lo, hi)in Hz, orNone.
- property band: tuple[float, float] | None#
What to compute for the display: a band in Hz, or
Nonefor activation.The custom band when one is set, else the display mode’s.
record_main()reads it for every window, so the controls change what is computed, not just the label.
- 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 per-source-vertex values.
- update(stc, mode: str = 'power') None[source]#
Show one frame of a surface source estimate on fsaverage.
- Parameters:
- stc
mne.SourceEstimate On an fsaverage ico-5 (or coarser) surface source space.
- mode{“power”, “activation”}, default “power”
"power"displays mean squared amplitude;"activation"displays the time-averaged amplitude.
- stc
- property display_mode: str#
Current display mode string (e.g.
"Alpha Power (8–13 Hz)")."Custom lo–hi Hz"while a custom band is set. What is computed isband.
- 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='140324714477712'>#
The underlying
pyvistaqt.BackgroundPlotterinstance.