bloc.plotting.sankey#
Sankey link/node graph manipulation helpers.
Attributes#
Functions#
|
List names of upstream nodes of a given node. |
|
List all outlets of a node. |
|
Get the sum of all inlet streams of a node. |
|
Get the sum of all outlet streams of a node. |
|
Print the links in a readable format. |
|
Add a connection between Source and Target. |
|
|
|
Substract a value from a link. |
|
Print a message, safely handling Unicode characters on Windows. |
|
Plot Sankey Diagram for a simulation. |
|
Plot Sankey Diagram from links and nodes. |
|
Generate input data for sankey plot from a Cantera Reactor Net simulation. |
Module Contents#
- bloc.plotting.sankey.get_upstream_nodes(links, nodes, node_name)#
List names of upstream nodes of a given node.
- Parameters:
links (
dict) – Network links. Dictionary with keys {‘source’, ‘target’, ‘value’, ‘color’, ‘label’}nodes (
list) – Network list of names of nodes.node_name (
str) – Name of the node.
- Returns:
List of upstream nodes of the node.
- Return type:
listofstr
- bloc.plotting.sankey.get_downstream_nodes(links, nodes, node_name)#
List all outlets of a node.
- bloc.plotting.sankey.get_inlet_value(links, nodes, node_name, filter_links='', get_color=False)#
Get the sum of all inlet streams of a node.
- bloc.plotting.sankey.get_outlet_value(links, nodes, node_name, filter_links='', get_color=False)#
Get the sum of all outlet streams of a node.
- bloc.plotting.sankey.print_links(links, nodes)#
Print the links in a readable format.
- bloc.plotting.sankey.add_link(links, nodes, source_str, target_str, value, color=None, label=None)#
Add a connection between Source and Target.
- bloc.plotting.sankey.add_node(nodes, node_str, color=None)#
- bloc.plotting.sankey.substract_value(links, nodes, source_str, target_str, value, link_name=None, allow_negative=False)#
Substract a value from a link.
- bloc.plotting.sankey.color_mass = '#EBE2F6'#
- bloc.plotting.sankey.safe_print(msg)#
Print a message, safely handling Unicode characters on Windows.
- bloc.plotting.sankey.plot_sankey_diagram(sim)#
Plot Sankey Diagram for a simulation.
Show the figure by default. If you want the figure without showing it, use
plot_sankey_diagram_from_links_and_nodes().- Parameters:
sim (
Cantera ReactorNet object) – A ReactorNet instance containing a list of reactors; already resolved.
Example
sim.advance_to_steady_state() plot_sankey_diagram(sim)
- bloc.plotting.sankey.plot_sankey_diagram_from_links_and_nodes(links, nodes, show=False)#
Plot Sankey Diagram from links and nodes.
Note: Physical nodes should already have circled-number prefixes applied to their names before calling this function.
- Parameters:
links (
dict) – Dictionary containing the links for the sankey diagram.nodes (
list) – List of nodes for the sankey diagram.show (
bool) – Whether to show the plot or not. Default is False.
- Returns:
The Sankey diagram.
- Return type:
plotly.graph_objects.Figure
- bloc.plotting.sankey.generate_sankey_input_from_sim(sim, node_order=[], exclude_nodes=None, flow_type='hhv', show_species=['H2', 'CH4', 'C(s)'], if_no_species='raise', verbose=False, **kwargs)#
Generate input data for sankey plot from a Cantera Reactor Net simulation.
- Parameters:
sim (
Cantera ReactorNet object) – A ReactorNet instance containing a list of reactors.node_order (
listofstr) – Order for the nodes in the sankey diagram (optional). In case no order is passed, a generic order will be used.flow_type (
str) – Type of flow to be considered in the sankey diagram. Default is “hhv”. # TODO : implement other types of flow (e.g. “enthalpy”, “exergy”, etc.)show_species (
listof(str, orlist-of-str) elements) –List of species to show in the sankey diagram. Default is [“H2”, “C(s)”]. Set to [] not to show any species. If a list-of-str is given, these species names are merged together and given the name of the first one. Ex:
show_species = ["H2", "CH4", ["C(s)", "C(soot)", "BIN25"]]
if_no_species (
"raise","ignore") – what to do if one of the species in show_species list is absent in at least one of the reactors of the ReactorNet: raise an error, or ignore it.verbose (
bool) – if True, print details about Sankey network generation.
- Returns:
Tuple containing the links and node_order for the plotly sankey diagram.
- Return type:
tuple
Example
links, nodes = generate_sankey_input_from_sim(sim) import plotly.graph_objects as go fig = go.Figure(go.Sankey( arrangement='snap', node={ 'label': nodes, 'pad':11, 'color': 'orange' }, link=links )) fig.show()
See also
plot_sankey_diagram()