pywatershed.analysis.ModelGraph#

class pywatershed.analysis.ModelGraph(model, show_params=False, process_colors=None, node_penwidth=2, edge_penwidth=1.5, edge_arrowsize=1.2, default_edge_color='black', from_file_edge_color=None, hide_variables=True)[source]#

Visualize a pywatershed Model as a directed graph.

Creates a GraphViz visualization showing processes, their inputs/variables, and the data flow between them. Uses the dot layout engine with left-to-right orientation.

Parameters:
  • model (Model) – The pywatershed Model to visualize

  • show_params (bool) – Whether to display parameters in process nodes

  • process_colors (dict[str, str] | None) – Dictionary mapping process names to colors for node borders

  • node_penwidth (int) – Width of node borders (default: 2)

  • edge_penwidth (float) – Width of edges/arrows (default: 1.5)

  • edge_arrowsize (float) – Size of arrowheads (default: 1.2)

  • default_edge_color (str) – Color for edges between processes (default: “black”)

  • from_file_edge_color (str | None) – Color for edges from file inputs (default: same as default_edge_color)

  • hide_variables (bool) – If True, hide individual variable names and only show process-to-process connections (default: True)

Example

>>> import pywatershed as pws
>>> model = pws.Model(process_list, control=control, parameters=params)
>>> mg = pws.analysis.ModelGraph(model, hide_variables=False)
>>> mg.SVG()
__init__(model, show_params=False, process_colors=None, node_penwidth=2, edge_penwidth=1.5, edge_arrowsize=1.2, default_edge_color='black', from_file_edge_color=None, hide_variables=True)[source]#

Methods

SVG([verbose, dpi, show_legend])

Render and display the graph as SVG in a Jupyter notebook.

__init__(model[, show_params, ...])

build_graph()

Build the GraphViz graph structure.

display_legend()

Display a complete legend for the ModelGraph visualization.

SVG(verbose=False, dpi=45, show_legend=False)[source]#

Render and display the graph as SVG in a Jupyter notebook.

Parameters:
  • verbose (bool) – If True, print the temporary file path

  • dpi (int) – Resolution for the SVG output (default: 45)

  • show_legend (bool) – If True, display legend for process colors and mass/energy budget terms before the graph

Return type:

None

build_graph()[source]#

Build the GraphViz graph structure.

Creates nodes for all processes and files, establishes connections between them, and sets up invisible ordering edges to enforce left-to-right layout according to model.process_order.

The graph uses the dot layout engine with: - Left-to-right orientation (rankdir=”LR”) - Invisible edges to control node ordering - constraint=false on data edges so they don’t affect layout

Return type:

None

display_legend()[source]#

Display a complete legend for the ModelGraph visualization.

Shows: - Process colors (node border colors) - Mass budget variable colors (lightsteelblue background, if present) - Energy budget variable colors (lightcoral background, if present)