bloc.sankey#
Sankey diagrams tools for Bloc.
Attributes#
Functions#
|
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. |
|
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. |
Module Contents#
- bloc.sankey.color_mass = '#EBE2F6'#
- bloc.sankey.color_H2 = '#B481FF'#
- bloc.sankey.color_Cs = '#000000'#
- bloc.sankey.color_CH4 = '#6828B4'#
- bloc.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.sankey.plot_sankey_diagram_from_links_and_nodes(links, nodes, show=False)#
Plot Sankey Diagram from links and nodes.
- 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.sankey.generate_sankey_input_from_sim(sim, node_order=[], flow_type='hhv', show_species=['H2', 'CH4', 'C(s)'], if_no_species='raise', verbose=False)#
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()
sphx_glr_auto_examples_generate_sankey_diagram.py
Generate a Sankey diagram from a Cantera Reactor Net simulation.See also
- bloc.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.sankey.get_downstream_nodes(links, nodes, node_name)#
List all outlets of a 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 downstream nodes of the node.
- Return type:
list
- bloc.sankey.get_inlet_value(links, nodes, node_name, filter_links='', get_color=False)#
Get the sum of all inlet streams of a node.
Also returns the color of the largest link.
- 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.filter_links (
str) –Expression to capture name of output streams to aggregate. Default is “”, i.e. all output streams are aggregated. Example:
filter_links = "H2|CH4"
get_color (
str) – If True, get color of the largest link. The default is False.
- bloc.sankey.get_outlet_value(links, nodes, node_name, filter_links='', get_color=False)#
Get the sum of all outlet streams of a node.
Also returns the color of the largest link.
- 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.filter_links (
str) –Expression to capture name of output streams to aggregate. Default is “”, i.e. all output streams are aggregated. Example:
filter_links = "H2|CH4"
get_color (
str) – If True, get color of the largest link. The default is False.
- bloc.sankey.print_links(links, nodes)#
Print the links in a readable format.
- Parameters:
links (
dict) – Dictionary of links, with keys {‘source’, ‘target’, ‘value’, ‘color’, ‘label’}nodes (
list) – List of names of nodes.
- Returns:
Prints the links in a readable format.
- Return type:
None
- bloc.sankey.add_link(links, nodes, source_str, target_str, value, color=None, label=None)#
Add a connection between Source and Target.
- Parameters:
links (
dict) – Dictionary of links, with keys {‘source’, ‘target’, ‘value’, ‘color’, ‘label’}nodes (
list) – list of names of nodes.source_str (
str) – Name of the source node.target_str (
str) – Name of the target node.value (
float) – Value of the link.color (
str, optional) – Color of the link. The default is None.label (
str, optional) – Label of the link. The default is None.
- bloc.sankey.add_node(nodes, node_str, color=None)#
- bloc.sankey.substract_value(links, nodes, source_str, target_str, value, link_name=None, allow_negative=False)#
Substract a value from a link.
- Parameters:
links (
dict) – Dictionary of links, with keys {‘source’, ‘target’, ‘value’, ‘color’, ‘label’}nodes (
list) – list of names of nodes.source_str (
str) – Name of the source node.target_str (
str) – Name of the target node.value (
float) – Value to substract from existing link.link_name (
str, optional) – Name of the link. The default is None.allow_negative (
bool, optional) – Allow negative values. The default is False. If True, the value being subtracted cannot be greater than the existing value.
- Returns:
links and nodes are modified in place.
- Return type:
None
- bloc.sankey.config#