cedalion.vis.anatomy.brain_and_scalp

Functions

camera_for_view(center, view[, distance])

Return camera parameters for a named orthogonal brain view.

get_vertex_colors_from_coord(brain_surface, ...)

Build a per-vertex color list from a named coordinate on the brain surface.

plot_brain_and_scalp(brain_mesh, scalp_mesh, ...)

Plots a 3D visualization of brain and scalp meshes.

plot_brain_in_axes(ts, geo3d, metric, ...[, ...])

Using pyvista render a brain, colored by a metric, and display it in MPL axes.

plot_brain_views_grid(brain_surface, ...[, ...])

Render the brain surface from five standard views in a grid layout.

cedalion.vis.anatomy.brain_and_scalp.plot_brain_and_scalp(
brain_mesh,
scalp_mesh,
geo3d,
timeseries,
poly_lines=[],
brain_scalars=None,
plotter=None,
)[source]

Plots a 3D visualization of brain and scalp meshes.

Parameters:
  • brain_mesh (TrimeshSurface) – The brain mesh as a TrimeshSurface object.

  • scalp_mesh (TrimeshSurface) – The scalp mesh as a TrimeshSurface object.

  • geo3d (xarray.Dataset) – Dataset containing 3-dimentional point centers.

  • timeseries – Time series data array.

  • poly_lines – List of lists of points to be plotted as polylines.

  • brain_scalars – Scalars to be used for coloring the brain mesh.

  • plotter (pv.Plotter, optional) – An existing PyVista plotter instance to use for plotting. If None, a new PyVista plotter instance is created. Default: None.

Initial Contributors:
cedalion.vis.anatomy.brain_and_scalp.plot_brain_in_axes(
ts: Annotated[DataArray, DataArraySchema(dims='time', coords='time', 'time', 'samples')],
geo3d: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')],
metric: DataArray | _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes],
brain_surface: TrimeshSurface,
ax: Axes,
title: str | None = None,
vmin: float | None = None,
vmax: float | None = None,
cmap: str | Colormap = 'RdBu_r',
bad_color: tuple[float, float, float] | str | tuple[float, float, float, float] | tuple[tuple[float, float, float] | str, float] | tuple[tuple[float, float, float, float], float] = [0.7, 0.7, 0.7],
cb_label: str = '',
camera_pos: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None,
**kwargs,
)[source]

Using pyvista render a brain, colored by a metric, and display it in MPL axes.

cedalion.vis.anatomy.brain_and_scalp.camera_for_view(center, view, distance=350)[source]

Return camera parameters for a named orthogonal brain view.

Parameters:
  • center – 3-element array-like with the focal point coordinates (e.g. brain centroid) in the same units as distance.

  • view – One of "superior", "left", "right", "anterior", "posterior".

  • distance – Distance from center to the camera position along the view axis. Defaults to 350.

Returns:

(position, focal_point, up) where each element is a numpy array suitable for assignment to pyvista.Camera attributes.

Return type:

tuple

cedalion.vis.anatomy.brain_and_scalp.plot_brain_views_grid(
brain_surface,
vertex_colors,
window_size=(1000, 600),
reset_camera=False,
)[source]

Render the brain surface from five standard views in a grid layout.

Displays superior, anterior, posterior, left, and right views arranged in a 2-row PyVista plotter window.

Parameters:
  • brain_surface – A surface object whose .vertices attribute is a pint-aware xarray with a "label" dimension.

  • vertex_colors – Per-vertex color array passed to vbx.plot_surface.

  • window_size(width, height) in pixels for the plotter window. Defaults to (1000, 600).

  • reset_camera – If True, call plt.reset_camera() after setting each view to fit the surface tightly. Defaults to False.

cedalion.vis.anatomy.brain_and_scalp.get_vertex_colors_from_coord(
brain_surface: TrimeshSurface,
label_coord: str,
color_mapping: dict,
default_color='w',
labels: list[str] | None = None,
)[source]

Build a per-vertex color list from a named coordinate on the brain surface.

Each vertex is colored according to the value of label_coord at that vertex, looked up in color_mapping. Vertices whose coordinate value is not present in the mapping (or whose label is filtered out) receive default_color.

Parameters:
  • brain_surface – Surface object whose .vertices attribute is an xarray DataArray with named coordinates.

  • label_coord – Name of the coordinate on brain_surface.vertices whose values are used as keys into color_mapping.

  • color_mapping – Controls how coordinate values map to colors: * None — generate a deterministic random color per unique label. * dict — map each label to a matplotlib-compatible color spec. * Any other single color spec assigns the same color to every label.

  • default_color – Matplotlib-compatible color used for vertices whose label is absent from the resolved mapping. Defaults to "w" (white).

  • labels – If provided, only labels in this list are kept in the mapping; all other vertices fall back to default_color.

Returns:

One RGB tuple per vertex, in the same order as brain_surface.vertices.

Return type:

list