elphick.mass_composition.flowsheet.Flowsheet

class elphick.mass_composition.flowsheet.Flowsheet(name='Flowsheet')[source]
__init__(name='Flowsheet')[source]

Methods

__init__([name])

from_dag(dag)

Construct a flowsheet from a dag object

from_dataframe(df[, name, mc_name_col, n_jobs])

Instantiate from a DataFrame

from_streams(streams[, name])

Instantiate from a list of objects

from_yaml(flowsheet_file)

Construct a flowsheet defined in a yaml file

get_column_formats(columns[, strip_percent])

type columns:

List[str]

get_edge_by_name(name)

Get the MC object from the network by its name

get_input_streams()

Get the input (feed) streams (edge objects)

get_node_input_outputs(node)

rtype:

Tuple

get_output_streams()

Get the output (product) streams (edge objects)

get_stream_names()

Get the names of the streams (MC objects on the edges)

imbalance_report(node)

nodes_to_dict()

Export the MCNode objects to a Dict

plot([orientation])

Plot the network with matplotlib

plot_balance([facet_col_wrap, color])

Plot input versus output across all nodes in the network

plot_network([orientation])

Plot the network with plotly

plot_parallel([names, color, vars_include, ...])

Create an interactive parallel plot

plot_sankey([width_var, color_var, ...])

Plot the Network as a sankey

query(mc_name, queries)

Query/filter across the network

report([apply_formats])

Summary Report

reset_stream_nodes([stream])

Reset stream nodes to break relationships

set_node_names(node_names)

Set the names of network nodes with a Dict

set_stream_child(stream, child)

set_stream_data(stream_data)

Set the data (MassComposition) of network edges (streams) with a Dict

set_stream_nodes(stream, nodes)

set_stream_parent(stream, parent)

streams_to_dict()

Export the Stream objects to a Dict

table_plot([plot_type, cols_exclude, ...])

Plot with table of edge averages

to_dataframe([names])

Return a tidy dataframe

to_json()

rtype:

Dict

to_simple([node_name])

Return the simplified flowsheet

Attributes

balanced

edge_status

classmethod from_dag(dag)[source]

Construct a flowsheet from a dag object

Parameters:

dag (DAG) – The dag object that has been run previously.

Return type:

Flowsheet

Returns:

classmethod from_dataframe(df, name='Flowsheet', mc_name_col=None, n_jobs=1)[source]

Instantiate from a DataFrame

Parameters:
  • df (DataFrame) – The DataFrame

  • name (Optional[str]) – name of the network

  • mc_name_col (Optional[str]) – The column specified contains the names of objects to create. If None the DataFrame is assumed to be wide and the mc objects will be extracted from column prefixes.

  • n_jobs (int) – The number of parallel jobs to run. If -1, will use all available cores.

Returns:

An instance of the Flowsheet class initialized from the provided DataFrame.

Return type:

Flowsheet

classmethod from_streams(streams, name='Flowsheet')[source]

Instantiate from a list of objects

Parameters:
  • streams (List[Union[Stream, MassComposition]]) – List of MassComposition objects

  • name (Optional[str]) – name of the network

Return type:

Flowsheet

Returns:

classmethod from_yaml(flowsheet_file)[source]

Construct a flowsheet defined in a yaml file

Parameters:

flowsheet_file (Path) – The yaml file following the prescribed format

Return type:

Flowsheet

Returns:

get_column_formats(columns, strip_percent=False)[source]
Parameters:
  • columns (List[str]) – The columns to lookup format strings for

  • strip_percent (bool) – If True remove the leading % symbol from the format (for plotly tables)

Return type:

Dict[str, str]

Returns:

get_edge_by_name(name)[source]

Get the MC object from the network by its name

Parameters:

name (str) – The string name of the MassComposition object stored on an edge in the network.

Return type:

MassComposition

Returns:

get_input_streams()[source]

Get the input (feed) streams (edge objects)

Return type:

List[Union[Stream, MassComposition]]

Returns:

List of MassComposition objects

get_output_streams()[source]

Get the output (product) streams (edge objects)

Return type:

List[Union[Stream, MassComposition]]

Returns:

List of MassComposition objects

get_stream_names()[source]

Get the names of the streams (MC objects on the edges)

Returns:

Return type:

List[str]

nodes_to_dict()[source]

Export the MCNode objects to a Dict

Return type:

Dict[int, MCNode]

Returns:

A dictionary keyed by integer containing MCNode objects

plot(orientation='horizontal')[source]

Plot the network with matplotlib

Parameters:

orientation (str) – ‘horizontal’|’vertical’ network layout

Return type:

Figure

Returns:

plot_balance(facet_col_wrap=3, color='node')[source]

Plot input versus output across all nodes in the network

Parameters:
  • facet_col_wrap (int) – the number of subplots per row before wrapping

  • color (Optional[str]) – The optional variable to color by. If None color will be by Node

Return type:

Figure

Returns:

plot_network(orientation='horizontal')[source]

Plot the network with plotly

Parameters:

orientation (str) – ‘horizontal’|’vertical’ network layout

Return type:

Figure

Returns:

plot_parallel(names=None, color=None, vars_include=None, vars_exclude=None, title=None, include_dims=True, plot_interval_edges=False)[source]

Create an interactive parallel plot

Useful to explore multidimensional data like mass-composition data

Parameters:
  • names (Optional[str]) – Optional List of Names to plot

  • color (Optional[str]) – Optional color variable

  • vars_include (Optional[List[str]]) – Optional List of variables to include in the plot

  • vars_exclude (Optional[List[str]]) – Optional List of variables to exclude in the plot

  • title (Optional[str]) – Optional plot title

  • include_dims (Union[bool, List[str], None]) – Optional boolean or list of dimension to include in the plot. True will show all dims.

  • plot_interval_edges (bool) – If True, interval edges will be plotted instead of interval mid

Return type:

Figure

Returns:

plot_sankey(width_var='mass_wet', color_var=None, edge_colormap='copper_r', vmin=None, vmax=None)[source]

Plot the Network as a sankey

Parameters:
  • width_var (str) – The variable that determines the sankey width

  • color_var (Optional[str]) – The optional variable that determines the sankey edge color

  • edge_colormap (Optional[str]) – The optional colormap. Used with color_var.

  • vmin (Optional[float]) – The value that maps to the minimum color

  • vmax (Optional[float]) – The value that maps to the maximum color

Return type:

Figure

Returns:

query(mc_name, queries)[source]

Query/filter across the network

The queries provided will be applied to the MassComposition object in the network with the mc_name. The indexes for that result are then used to filter the other edges of the network.

Parameters:
  • mc_name (str) – The name of the MassComposition object in the network to which the first filter to be applied.

  • queries (Dict) – The query or queries to apply to the object with mc_name.

Return type:

Flowsheet

Returns:

report(apply_formats=False)[source]

Summary Report

Total Mass and weight averaged composition Returns:

Return type:

DataFrame

reset_stream_nodes(stream=None)[source]

Reset stream nodes to break relationships

Parameters:

stream (Optional[str]) – The optional stream (edge) within the network. If None all streams nodes on the network will be reset.

Returns:

set_node_names(node_names)[source]

Set the names of network nodes with a Dict

set_stream_data(stream_data)[source]

Set the data (MassComposition) of network edges (streams) with a Dict

streams_to_dict()[source]

Export the Stream objects to a Dict

Return type:

Dict[str, MassComposition]

Returns:

A dictionary keyed by name containing MassComposition objects

table_plot(plot_type='sankey', cols_exclude=None, table_pos='left', table_area=0.4, table_header_color='cornflowerblue', table_odd_color='whitesmoke', table_even_color='lightgray', sankey_width_var='mass_wet', sankey_color_var=None, sankey_edge_colormap='copper_r', sankey_vmin=None, sankey_vmax=None, network_orientation='horizontal')[source]

Plot with table of edge averages

Parameters:
  • plot_type (str) – The type of plot [‘sankey’, ‘network’]

  • cols_exclude (Optional[List]) – List of columns to exclude from the table

  • table_pos (str) – Position of the table [‘left’, ‘right’, ‘top’, ‘bottom’]

  • table_area (float) – The proportion of width or height to allocate to the table [0, 1]

  • table_header_color (str) – Color of the table header

  • table_odd_color (str) – Color of the odd table rows

  • table_even_color (str) – Color of the even table rows

  • sankey_width_var (str) – If plot_type is sankey, the variable that determines the sankey width

  • sankey_color_var (Optional[str]) – If plot_type is sankey, the optional variable that determines the sankey edge color

  • sankey_edge_colormap (Optional[str]) – If plot_type is sankey, the optional colormap. Used with sankey_color_var.

  • sankey_vmin (Optional[float]) – The value that maps to the minimum color

  • sankey_vmax (Optional[float]) – The value that maps to the maximum color

  • network_orientation (Optional[str]) – The orientation of the network layout ‘vertical’|’horizontal’

Return type:

Figure

Returns:

to_dataframe(names=None)[source]

Return a tidy dataframe

Adds the mc name to the index so indexes are unique.

Parameters:

names (Optional[str]) – Optional List of names of MassComposition objects (network edges) for export

Returns:

to_simple(node_name=None)[source]

Return the simplified flowsheet

Return type:

Flowsheet