paroto.viz.utils#

Utility functions for visualization module.

Functions#

get_simple_label(full_name)

Extract simplified label from dotted variable name.

get_subsystem_name(full_name)

Extract subsystem name from dotted variable name.

serialize_value(value)

Convert value to string, handling arrays.

deduplicate_nodes_by_label(nodes, levels[, max_level])

Deduplicate nodes with same label, preferring primary params.

deduplicate_edges(edges, node_to_canonical, ...)

Deduplicate edges using canonical node mapping.

Module Contents#

paroto.viz.utils.get_simple_label(full_name)#

Extract simplified label from dotted variable name.

Parameters:

full_name (str) – Full variable name (e.g., “vedef.breakdown.voltage”)

Returns:

Simplified label (e.g., “voltage”)

Return type:

str

Examples

>>> get_simple_label("vedef.breakdown.voltage")
'voltage'
>>> get_simple_label("simple_var")
'simple_var'
paroto.viz.utils.get_subsystem_name(full_name)#

Extract subsystem name from dotted variable name.

Parameters:

full_name (str) – Full variable name (e.g., “vedef.breakdown.voltage”)

Returns:

Subsystem name (e.g., “vedef.breakdown”) or ‘root’ if no subsystem

Return type:

str

Examples

>>> get_subsystem_name("vedef.breakdown.voltage")
'vedef.breakdown'
>>> get_subsystem_name("simple_var")
'root'
paroto.viz.utils.serialize_value(value)#

Convert value to string, handling arrays.

Parameters:

value (Any) – Value to serialize

Returns:

String representation of value

Return type:

str

paroto.viz.utils.deduplicate_nodes_by_label(nodes, levels, max_level=None)#

Deduplicate nodes with same label, preferring primary params.

When multiple nodes have the same simplified label (e.g., multiple “gap_distance” nodes from different subsystems), keeps only one canonical representative.

Parameters:
  • nodes (dict) – Mapping of node_id -> node attributes

  • levels (dict) – Mapping of node_id -> hierarchy level

  • max_level (int, optional) – Maximum level to include

Returns:

(deduplicated_nodes, node_to_canonical, deduplicated_by_level) - deduplicated_nodes: dict of canonical nodes - node_to_canonical: mapping from any node to its canonical version - deduplicated_by_level: dict of level -> list of canonical node_ids

Return type:

tuple

paroto.viz.utils.deduplicate_edges(edges, node_to_canonical, displayed_nodes)#

Deduplicate edges using canonical node mapping.

Parameters:
  • edges (list of tuple) – Original (source, target) edges

  • node_to_canonical (dict) – Mapping from node_name to canonical node_name

  • displayed_nodes (set) – Set of node IDs actually being displayed

Returns:

Deduplicated (canonical_source, canonical_target) edges

Return type:

list of tuple