TopologyGraph#

class braintools.visualize.morphology.TopologyGraph(node_ids, edges, root_id, level='node', values=None, value_label=None, highlight_fractions=None, times=None)[source]#

A rooted graph with optional per-node values or highlight fractions.

The input of plot_topology_graph(). Nodes are integer identifiers (for example branch indices, control-volume IDs or solver-node IDs).

Parameters:
  • node_ids (tuple[int, ...]) – Node identifiers; values is aligned with this order.

  • edges (tuple[tuple[int, int], ...]) – (parent_id, child_id) pairs.

  • root_id (int) – Identifier of the root node.

  • level (str) – What a node represents, "node" (default), "cv" or "branch". "branch" graphs are topology-only: plot_topology_graph() rejects colour-map arguments for them.

  • values (Any) – Per-node values, shape (N,) or (T, N) for T frames. NaN marks nodes without a value.

  • value_label (str | None) – Default colour-bar label.

  • highlight_fractions (Mapping[int, float] | None) – Node identifier to highlight intensity in [0, 1]. Mutually exclusive with values.

  • times (Any) – Frame times, shape (T,); only with two-dimensional values.

Raises:

ValueError – If node identifiers repeat, an edge or the root names an unknown node, values does not match len(node_ids), values and highlight_fractions are both given, or times does not match the frame count.

Examples

>>> import numpy as np
>>> from braintools.visualize.morphology import TopologyGraph
>>> graph = TopologyGraph(
...     node_ids=(0, 1, 2), edges=((0, 1), (0, 2)), root_id=0,
...     values=np.array([[1.0, 2.0, 3.0], [2.0, 3.0, 4.0]]),
... )
>>> graph.n_frames
2
>>> graph.frame(1)
array([2., 3., 4.])
frame(index=None)[source]#

Return the (N,) values of one frame.

Parameters:

index (int | None) – Frame index; must be given when values is two-dimensional.

Raises:

ValueError – If values is two-dimensional and index is None.

Return type:

Any

property n_frames: int#

0 without values, 1 for (N,) values.

Type:

Number of value frames