cedalion.vis.anatomy package

Submodules

cedalion.vis.anatomy.brain_and_scalp module

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,
)[source]

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

cedalion.vis.anatomy.image_recon module

Functions to plot image reconstruction results.

cedalion.vis.anatomy.image_recon.image_recon(
X: Annotated[DataArray, DataArraySchema(dims='time', coords='time', 'time', 'samples')],
head: TwoSurfaceHeadModel,
cmap: str | Colormap = 'seismic',
clim=None,
view_type: str = 'hbo_brain',
view_position: str = 'superior',
p0=None,
title_str: str = None,
off_screen: bool = False,
plotshape=(1, 1),
iax=(0, 0),
show_scalar_bar: bool = False,
wdw_size: tuple = (1024, 768),
)[source]

Render a single frame of brain or scalp activity on a specified view.

This function creates (or reuses) a PyVista plotter, applies a custom colormap, sets the camera view according to the given view_position, adds the surface mesh with the scalar data (extracted from X), and returns the plotter, the mesh, and a text label.

Parameters:
  • X – cdt.NDTimeSeries (or similar) Scalar data for the current frame. Expected to have a boolean attribute is_brain indicating brain vs. non-brain vertices, and HbO / HbR chromophore dimension

  • head – TwoSurfaceHeadModel A head model containing attributes such as head.brain and head.scalp.

  • cmap – str or matplotlib.colors.Colormap, default ‘seismic’ The colormap to use.

  • clim – tuple, optional Color limits. If None, they are computed from the data.

  • view_type – str, default ‘hbo_brain’ Indicates whether to plot brain (‘hbo_brain’ or ‘hbr_brain’) or scalp (‘hbo_scalp’ or ‘hbr_scalp’) data.

  • view_position – str, default ‘superior’ The view direction. Options are: ‘superior’, ‘anterior’, ‘posterior’,’left’, ‘right’, and ‘scale_bar’.

  • p0 – PyVista Plotter instance, optional If provided the mesh is added to this plotter; else a new plotter is created

  • title_str – str, optional Title to use on the scalar bar.

  • off_screen – bool, default False Whether to use off-screen rendering.

  • plotshape – tuple, default (1, 1) The subplot grid shape.

  • iax – tuple, default (0, 0) The target subplot index (row, col).

  • show_scalar_bar – bool, optional Flag to control scalar bar visibility

  • wdw_size – tuple, default (1024, 768) The window size for the plotter (the plot resolution)

Returns:

  • p0: the PyVista Plotter instance.

  • surf: the wrapped surface mesh (a pyvista mesh).

  • surf_label: a text actor (e.g., the scalar bar label).

Return type:

A tuple (p0, surf, surf_label) where

Initial Contributors: - David Boas | dboas@bu.edu | 2025 - Laura Carlton | lcarlton@bu.edu | 2025 - Alexander von Lühmann | vonluehmann@tu-berlin.de | 2025

cedalion.vis.anatomy.image_recon.image_recon_view(
X_ts: Annotated[DataArray, DataArraySchema(dims='time', coords='time', 'time', 'samples')],
head: TwoSurfaceHeadModel,
cmap: str | Colormap = 'seismic',
clim=None,
view_type: str = 'hbo_brain',
view_position: str = 'superior',
title_str: str = None,
filename: str = None,
SAVE: bool = False,
time_range: tuple = None,
fps: int = 6,
geo3d_plot: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')] | None = None,
wdw_size: tuple = (1024, 768),
)[source]

Generate a single-view visualization of head activity.

For static data (2D: vertex × channel) the function can display (or save) a single frame. For time series data (3D: vertex × channel × time) the function can create an animated GIF by looping over the specified frame indices.

Parameters:
  • X_ts – xarray.DataArray or NDTimeSeries Activity data. If 2D, a single static frame is plotted; if 3D, a time series is used. Expected to have a boolean attribute is_brain indicating brain vs. non-brain vertices, and HbO / HbR chromophore dimension

  • head – TwoSurfaceHeadModel The head mesh data to plot activity on.

  • cmap – str or matplotlib.colors.Colormap, default ‘seismic’ The colormap to use.

  • view_position – str, default ‘superior’ The view to render.

  • clim – tuple, optional Color limits. If None, they are computed from the data.

  • view_type – str, default ‘hbo_brain’ Indicates whether to plot brain (‘hbo_brain’ or ‘hbr_brain’) or scalp (‘hbo_scalp’ or ‘hbr_scalp’) data.

  • view_position – str, default ‘superior’ The view direction. Options are: ‘superior’, ‘anterior’, ‘posterior’,’left’, ‘right’, and ‘scale_bar’.

  • title_str – str, optional Title to use on the scalar bar.

  • filename – str, optional The output filename (without extension) for saving the image/GIF.

  • SAVE – bool, default False If True, the resulting still image is saved, otherwise only shown. Rendered gifs are always saved.

  • time_range – tuple, optional Provides (start_time, stop_time, step_time) in quantity ‘s’ for generating animation.

  • fps – int, default 6 Frames per second for the GIF.

  • geo3d_plot – cdt.LabeledPoints, optional For plotting labeled points (e.g. optodes) on the mesh.

  • wdw_size – tuple, default (1024, 768) The window size for the plotter (the plot resolution)

Returns: Nothing

Initial Contributors: - David Boas | dboas@bu.edu | 2025 - Laura Carlton | lcarlton@bu.edu | 2025 - Alexander von Lühmann | vonluehmann@tu-berlin.de | 2025

cedalion.vis.anatomy.image_recon.image_recon_multi_view(
X_ts: Annotated[DataArray, DataArraySchema(dims='time', coords='time', 'time', 'samples')],
head: TwoSurfaceHeadModel,
cmap: str | Colormap = 'seismic',
clim=None,
view_type: str = 'hbo_brain',
title_str: str = None,
filename: str = None,
SAVE: bool = True,
time_range: tuple = None,
fps: int = 6,
geo3d_plot: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')] | None = None,
wdw_size: tuple = (1024, 768),
)[source]

Generate a multi-view (2×3 grid) vis. of head activity across different views.

For static data (2D: vertex × channel) the function can display (or save) a single frame. For time series data (3D: vertex × channel × time) the function creates an animated GIF where each frame updates all views.

Parameters:
  • X_ts – xarray.DataArray or NDTimeSeries Activity data. If 2D, a single static frame is plotted; if 3D, a time series is used. Expected to have a boolean attribute is_brain indicating brain vs. non-brain vertices, and HbO / HbR chromophore dimension

  • head – TwoSurfaceHeadModel The head mesh data to plot activity on.

  • cmap – str or matplotlib.colors.Colormap, default ‘seismic’ The colormap to use.

  • view_position – str, default ‘superior’ The view to render.

  • clim – tuple, optional Color limits. If None, they are computed from the data.

  • view_type – str, default ‘hbo_brain’ Indicates whether to plot brain (‘hbo_brain’ or ‘hbr_brain’) or scalp (‘hbo_scalp’ or ‘hbr_scalp’) data.

  • title_str – str, optional Title to use on the scalar bar.

  • filename – str, optional The output filename (without extension) for saving the image/GIF.

  • SAVE – bool, default False If True, the resulting still image is saved, otherwise only shown. Rendered gifs are always saved.

  • time_range – tuple, optional Provides (start_time, stop_time, step_time) in quantity ‘s’ for generating animation.

  • fps – int, default 6 Frames per second for the GIF.

  • geo3d_plot – cdt.LabeledPoints, optional For plotting labeled points (e.g. optodes) on the mesh.

  • wdw_size – tuple, default (1024, 768) The window size for the plotter (the plot resolution)

Returns: Nothing

Initial Contributors: - David Boas | dboas@bu.edu | 2025 - Laura Carlton | lcarlton@bu.edu | 2025 - Alexander von Lühmann | vonluehmann@tu-berlin.de | 2025

cedalion.vis.anatomy.montage module

cedalion.vis.anatomy.montage.plot_montage3D(
amp: Annotated[DataArray, DataArraySchema(dims='time', coords='time', 'time', 'samples')],
geo3d: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')],
)[source]

Plots a 3D visualization of a montage.

Parameters:
  • amp – Time series data array.

  • geo3d – Landmark coordinates.

cedalion.vis.anatomy.optode_selector module

class cedalion.vis.anatomy.optode_selector.OptodeSelector(surface, points, normals=None, plotter=None, labels=None)[source]

Bases: object

A class for visualizing point clouds with interactive features in PyVista.

This class provides functionality to visualize and interact with labeled point clouds using a PyVista plotter. It allows points to be dynamically added or removed by picking them directly from the plot interface.

surface[source]

The surface of a head for normals.

Type:

cdc.Surface

points[source]

The point cloud data containing point coordinates.

Type:

cdt.LabeledPoints

normals[source]

Normal vectors to the points.

Type:

xr.DataArray

plotter[source]

A PyVista plotter instance for rendering the point cloud.

Type:

pv.Plotter

labels[source]

Labels corresponding to the points, displayed if provided.

Type:

list of str, optional

actors[source]

List of PyVista actor objects representing the points in the visualization.

Type:

list

color[source]

Default color for points if not specified by point type.

Type:

str or tuple, optional

plot()[source]

Renders the point cloud using the current settings.

on_pick(picked_point)[source]

Callback function for picking points in the visualization

update_visualization()[source]

Clears the existing plot and re-renders the point cloud.

enable_picking()[source]

Enables interactive picking of points on the plot.

Initial Contributors:
plot()[source]
on_pick(picked_point)[source]
update_visualization()[source]
enable_picking()[source]
find_surface_normal(picked_point, radius=6)[source]
update_normals(normal_at_picked_point, label)[source]

cedalion.vis.anatomy.scalp_plot module

Static and animated 2D plots of metrics projected on the scalp.

cedalion.vis.anatomy.scalp_plot.scalp_plot(
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],
ax,
title: str | None = None,
y_title: float = None,
vmin: float | None = None,
vmax: float | None = None,
center: float | None = None,
cmap: str | Colormap = 'bwr',
norm: Normalize | None = None,
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],
min_dist: Quantity | None = None,
min_metric: float | None = None,
channel_lw: float = 2.0,
optode_size: float = 36.0,
optode_labels: bool = False,
cb_label: str | None = None,
cb_ticks_labels: list[float, str] | None = None,
add_colorbar: bool = True,
zorder: str | None = None,
)[source]

Creates a 2D plot of the head with channels coloured according to a given metric.

Parameters:
  • ts – a NDTimeSeries to provide channel definitions

  • geo3d – a LabeledPoints to provide the probe geometry

  • metric ((DataArray, (channel,) | ArrayLike)) – the scalar metric to be plotted for each channel. If provided as a DataArray it needs a channel dimension. If provided as a plain array or list it must have the same length as ts.channel and the matching is done by position.

  • ax – the matplotlib.Axes object into which to draw

  • title – the axes title

  • y_title – the y position of the title in axes coordinates

  • vmin – the minimum value of the metric

  • vmax – the maximum value of the metric

  • center – when calculating vmin and vmax, center the value range at this value.

  • cmap – the name of the colormap

  • norm – normalization for color map

  • bad_color – the color to use when the metric contains NaNs

  • min_dist – if provided channels below this distance threshold are not drawn

  • min_metric – if provided channels below this metric threshold are toned down

  • channel_lw – channel line width

  • optode_size – optode marker size

  • optode_labels – if True draw optode labels instead of markers

  • cb_label – colorbar label

  • cb_ticks_labels – ticks and labels for colorbar

  • add_colorbar – if true a colorbar is added to the plot

  • zorder – ‘ascending’ or ‘descending’ or None. Controls whether channels with high or low metric values are plotted on top.

Initial Contributors:
cedalion.vis.anatomy.scalp_plot.scalp_plot_gif(
data_ts: Annotated[DataArray, DataArraySchema(dims='time', coords='time', 'time', 'samples')],
geo3d: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')],
filename: str,
time_range: tuple = None,
cmap: str | Colormap = 'seismic',
scl=None,
fps: int = 10,
optode_size: float = 6,
optode_labels: bool = False,
str_title: str = '',
)[source]

Generate a GIF of scalp topographies over time from time-series data.

Parameters:
  • data_ts – xarray.DataArray A 2D DataArray with dimensions (channel, time). Must include coordinate labels for ‘source’ and ‘detector’ in the ‘channel’ dimension.

  • geo3d – 3D geometry defining optode locations for projecting onto the scalp surface.

  • filename – str Full path to the output GIF file without file extension.

  • time_range – tuple, optional Provides (start_time, stop_time, step_time) in quantity ‘s’ for generating animation.

  • cmap – string, optional A matplotlib colormap name or a Colormap object. Default is ‘seismic’.

  • scl – tuple of (float, float), optional Tuple defining the (vmin, vmax) for the color scale. If None, the color scale is set to ± the maximum absolute value of the data.

  • fps – int, optional Frames per second for the output GIF. Default is 10.

  • optode_size – float, optional Size of optode markers on the plot. Default is 6.

  • optode_labels – bool, optional Whether to show text labels for optodes instead of markers. Default: False.

  • str_title – str, optional Extra string to append to the title of each frame.

Returns:

None. The function saves a GIF file to the specified location.

Initial Contributors:

cedalion.vis.anatomy.sensitivity_matrix module

Plots an fNIRS probe’s sensitivity profile on a 3D brain surface.

Args: sensitivity: brain_surface: head_surface: labeled_points: wavelength: The wavelength of the light source in nm.

Initial Contributors: - Shakiba Moradi | shakiba.moradi@tu-berlin.de | 2024

class cedalion.vis.anatomy.sensitivity_matrix.Main(sensitivity, brain_surface, head_surface=None, labeled_points=None, wavelength=760)[source]

Bases: object

plot(low_th=-3, high_th=0)[source]

Module contents

Tools for visualizing data on brain and scalp surface representations.

cedalion.vis.anatomy.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,
)[source]

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

cedalion.vis.anatomy.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.image_recon(
X: Annotated[DataArray, DataArraySchema(dims='time', coords='time', 'time', 'samples')],
head: TwoSurfaceHeadModel,
cmap: str | Colormap = 'seismic',
clim=None,
view_type: str = 'hbo_brain',
view_position: str = 'superior',
p0=None,
title_str: str = None,
off_screen: bool = False,
plotshape=(1, 1),
iax=(0, 0),
show_scalar_bar: bool = False,
wdw_size: tuple = (1024, 768),
)[source]

Render a single frame of brain or scalp activity on a specified view.

This function creates (or reuses) a PyVista plotter, applies a custom colormap, sets the camera view according to the given view_position, adds the surface mesh with the scalar data (extracted from X), and returns the plotter, the mesh, and a text label.

Parameters:
  • X – cdt.NDTimeSeries (or similar) Scalar data for the current frame. Expected to have a boolean attribute is_brain indicating brain vs. non-brain vertices, and HbO / HbR chromophore dimension

  • head – TwoSurfaceHeadModel A head model containing attributes such as head.brain and head.scalp.

  • cmap – str or matplotlib.colors.Colormap, default ‘seismic’ The colormap to use.

  • clim – tuple, optional Color limits. If None, they are computed from the data.

  • view_type – str, default ‘hbo_brain’ Indicates whether to plot brain (‘hbo_brain’ or ‘hbr_brain’) or scalp (‘hbo_scalp’ or ‘hbr_scalp’) data.

  • view_position – str, default ‘superior’ The view direction. Options are: ‘superior’, ‘anterior’, ‘posterior’,’left’, ‘right’, and ‘scale_bar’.

  • p0 – PyVista Plotter instance, optional If provided the mesh is added to this plotter; else a new plotter is created

  • title_str – str, optional Title to use on the scalar bar.

  • off_screen – bool, default False Whether to use off-screen rendering.

  • plotshape – tuple, default (1, 1) The subplot grid shape.

  • iax – tuple, default (0, 0) The target subplot index (row, col).

  • show_scalar_bar – bool, optional Flag to control scalar bar visibility

  • wdw_size – tuple, default (1024, 768) The window size for the plotter (the plot resolution)

Returns:

  • p0: the PyVista Plotter instance.

  • surf: the wrapped surface mesh (a pyvista mesh).

  • surf_label: a text actor (e.g., the scalar bar label).

Return type:

A tuple (p0, surf, surf_label) where

Initial Contributors: - David Boas | dboas@bu.edu | 2025 - Laura Carlton | lcarlton@bu.edu | 2025 - Alexander von Lühmann | vonluehmann@tu-berlin.de | 2025

cedalion.vis.anatomy.image_recon_multi_view(
X_ts: Annotated[DataArray, DataArraySchema(dims='time', coords='time', 'time', 'samples')],
head: TwoSurfaceHeadModel,
cmap: str | Colormap = 'seismic',
clim=None,
view_type: str = 'hbo_brain',
title_str: str = None,
filename: str = None,
SAVE: bool = True,
time_range: tuple = None,
fps: int = 6,
geo3d_plot: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')] | None = None,
wdw_size: tuple = (1024, 768),
)[source]

Generate a multi-view (2×3 grid) vis. of head activity across different views.

For static data (2D: vertex × channel) the function can display (or save) a single frame. For time series data (3D: vertex × channel × time) the function creates an animated GIF where each frame updates all views.

Parameters:
  • X_ts – xarray.DataArray or NDTimeSeries Activity data. If 2D, a single static frame is plotted; if 3D, a time series is used. Expected to have a boolean attribute is_brain indicating brain vs. non-brain vertices, and HbO / HbR chromophore dimension

  • head – TwoSurfaceHeadModel The head mesh data to plot activity on.

  • cmap – str or matplotlib.colors.Colormap, default ‘seismic’ The colormap to use.

  • view_position – str, default ‘superior’ The view to render.

  • clim – tuple, optional Color limits. If None, they are computed from the data.

  • view_type – str, default ‘hbo_brain’ Indicates whether to plot brain (‘hbo_brain’ or ‘hbr_brain’) or scalp (‘hbo_scalp’ or ‘hbr_scalp’) data.

  • title_str – str, optional Title to use on the scalar bar.

  • filename – str, optional The output filename (without extension) for saving the image/GIF.

  • SAVE – bool, default False If True, the resulting still image is saved, otherwise only shown. Rendered gifs are always saved.

  • time_range – tuple, optional Provides (start_time, stop_time, step_time) in quantity ‘s’ for generating animation.

  • fps – int, default 6 Frames per second for the GIF.

  • geo3d_plot – cdt.LabeledPoints, optional For plotting labeled points (e.g. optodes) on the mesh.

  • wdw_size – tuple, default (1024, 768) The window size for the plotter (the plot resolution)

Returns: Nothing

Initial Contributors: - David Boas | dboas@bu.edu | 2025 - Laura Carlton | lcarlton@bu.edu | 2025 - Alexander von Lühmann | vonluehmann@tu-berlin.de | 2025

cedalion.vis.anatomy.image_recon_view(
X_ts: Annotated[DataArray, DataArraySchema(dims='time', coords='time', 'time', 'samples')],
head: TwoSurfaceHeadModel,
cmap: str | Colormap = 'seismic',
clim=None,
view_type: str = 'hbo_brain',
view_position: str = 'superior',
title_str: str = None,
filename: str = None,
SAVE: bool = False,
time_range: tuple = None,
fps: int = 6,
geo3d_plot: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')] | None = None,
wdw_size: tuple = (1024, 768),
)[source]

Generate a single-view visualization of head activity.

For static data (2D: vertex × channel) the function can display (or save) a single frame. For time series data (3D: vertex × channel × time) the function can create an animated GIF by looping over the specified frame indices.

Parameters:
  • X_ts – xarray.DataArray or NDTimeSeries Activity data. If 2D, a single static frame is plotted; if 3D, a time series is used. Expected to have a boolean attribute is_brain indicating brain vs. non-brain vertices, and HbO / HbR chromophore dimension

  • head – TwoSurfaceHeadModel The head mesh data to plot activity on.

  • cmap – str or matplotlib.colors.Colormap, default ‘seismic’ The colormap to use.

  • view_position – str, default ‘superior’ The view to render.

  • clim – tuple, optional Color limits. If None, they are computed from the data.

  • view_type – str, default ‘hbo_brain’ Indicates whether to plot brain (‘hbo_brain’ or ‘hbr_brain’) or scalp (‘hbo_scalp’ or ‘hbr_scalp’) data.

  • view_position – str, default ‘superior’ The view direction. Options are: ‘superior’, ‘anterior’, ‘posterior’,’left’, ‘right’, and ‘scale_bar’.

  • title_str – str, optional Title to use on the scalar bar.

  • filename – str, optional The output filename (without extension) for saving the image/GIF.

  • SAVE – bool, default False If True, the resulting still image is saved, otherwise only shown. Rendered gifs are always saved.

  • time_range – tuple, optional Provides (start_time, stop_time, step_time) in quantity ‘s’ for generating animation.

  • fps – int, default 6 Frames per second for the GIF.

  • geo3d_plot – cdt.LabeledPoints, optional For plotting labeled points (e.g. optodes) on the mesh.

  • wdw_size – tuple, default (1024, 768) The window size for the plotter (the plot resolution)

Returns: Nothing

Initial Contributors: - David Boas | dboas@bu.edu | 2025 - Laura Carlton | lcarlton@bu.edu | 2025 - Alexander von Lühmann | vonluehmann@tu-berlin.de | 2025

cedalion.vis.anatomy.plot_montage3D(
amp: Annotated[DataArray, DataArraySchema(dims='time', coords='time', 'time', 'samples')],
geo3d: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')],
)[source]

Plots a 3D visualization of a montage.

Parameters:
  • amp – Time series data array.

  • geo3d – Landmark coordinates.

class cedalion.vis.anatomy.OptodeSelector(surface, points, normals=None, plotter=None, labels=None)[source]

Bases: object

A class for visualizing point clouds with interactive features in PyVista.

This class provides functionality to visualize and interact with labeled point clouds using a PyVista plotter. It allows points to be dynamically added or removed by picking them directly from the plot interface.

surface[source]

The surface of a head for normals.

Type:

cdc.Surface

points[source]

The point cloud data containing point coordinates.

Type:

cdt.LabeledPoints

normals[source]

Normal vectors to the points.

Type:

xr.DataArray

plotter[source]

A PyVista plotter instance for rendering the point cloud.

Type:

pv.Plotter

labels[source]

Labels corresponding to the points, displayed if provided.

Type:

list of str, optional

actors[source]

List of PyVista actor objects representing the points in the visualization.

Type:

list

color[source]

Default color for points if not specified by point type.

Type:

str or tuple, optional

plot()[source]

Renders the point cloud using the current settings.

on_pick(picked_point)[source]

Callback function for picking points in the visualization

update_visualization()[source]

Clears the existing plot and re-renders the point cloud.

enable_picking()[source]

Enables interactive picking of points on the plot.

Initial Contributors:
enable_picking()[source]
find_surface_normal(picked_point, radius=6)[source]
on_pick(picked_point)[source]
plot()[source]
update_normals(normal_at_picked_point, label)[source]
update_visualization()[source]
cedalion.vis.anatomy.scalp_plot(
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],
ax,
title: str | None = None,
y_title: float = None,
vmin: float | None = None,
vmax: float | None = None,
center: float | None = None,
cmap: str | Colormap = 'bwr',
norm: Normalize | None = None,
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],
min_dist: Quantity | None = None,
min_metric: float | None = None,
channel_lw: float = 2.0,
optode_size: float = 36.0,
optode_labels: bool = False,
cb_label: str | None = None,
cb_ticks_labels: list[float, str] | None = None,
add_colorbar: bool = True,
zorder: str | None = None,
)[source]

Creates a 2D plot of the head with channels coloured according to a given metric.

Parameters:
  • ts – a NDTimeSeries to provide channel definitions

  • geo3d – a LabeledPoints to provide the probe geometry

  • metric ((DataArray, (channel,) | ArrayLike)) – the scalar metric to be plotted for each channel. If provided as a DataArray it needs a channel dimension. If provided as a plain array or list it must have the same length as ts.channel and the matching is done by position.

  • ax – the matplotlib.Axes object into which to draw

  • title – the axes title

  • y_title – the y position of the title in axes coordinates

  • vmin – the minimum value of the metric

  • vmax – the maximum value of the metric

  • center – when calculating vmin and vmax, center the value range at this value.

  • cmap – the name of the colormap

  • norm – normalization for color map

  • bad_color – the color to use when the metric contains NaNs

  • min_dist – if provided channels below this distance threshold are not drawn

  • min_metric – if provided channels below this metric threshold are toned down

  • channel_lw – channel line width

  • optode_size – optode marker size

  • optode_labels – if True draw optode labels instead of markers

  • cb_label – colorbar label

  • cb_ticks_labels – ticks and labels for colorbar

  • add_colorbar – if true a colorbar is added to the plot

  • zorder – ‘ascending’ or ‘descending’ or None. Controls whether channels with high or low metric values are plotted on top.

Initial Contributors:
cedalion.vis.anatomy.scalp_plot_gif(
data_ts: Annotated[DataArray, DataArraySchema(dims='time', coords='time', 'time', 'samples')],
geo3d: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')],
filename: str,
time_range: tuple = None,
cmap: str | Colormap = 'seismic',
scl=None,
fps: int = 10,
optode_size: float = 6,
optode_labels: bool = False,
str_title: str = '',
)[source]

Generate a GIF of scalp topographies over time from time-series data.

Parameters:
  • data_ts – xarray.DataArray A 2D DataArray with dimensions (channel, time). Must include coordinate labels for ‘source’ and ‘detector’ in the ‘channel’ dimension.

  • geo3d – 3D geometry defining optode locations for projecting onto the scalp surface.

  • filename – str Full path to the output GIF file without file extension.

  • time_range – tuple, optional Provides (start_time, stop_time, step_time) in quantity ‘s’ for generating animation.

  • cmap – string, optional A matplotlib colormap name or a Colormap object. Default is ‘seismic’.

  • scl – tuple of (float, float), optional Tuple defining the (vmin, vmax) for the color scale. If None, the color scale is set to ± the maximum absolute value of the data.

  • fps – int, optional Frames per second for the output GIF. Default is 10.

  • optode_size – float, optional Size of optode markers on the plot. Default is 6.

  • optode_labels – bool, optional Whether to show text labels for optodes instead of markers. Default: False.

  • str_title – str, optional Extra string to append to the title of each frame.

Returns:

None. The function saves a GIF file to the specified location.

Initial Contributors: