elphick.geomet.flowsheet.flowsheet.Flowsheet

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

Methods

__init__([name])

copy_without_stream_data()

Copy without stream data

filter_by_index(index[, inplace])

Filter the Flowsheet Stream records by a given index.

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

Instantiate from a DataFrame

from_dict(config)

Create a flowsheet from a dictionary

from_json(file_path)

Create a flowsheet from json

from_objects(objects[, name])

Instantiate from a list of objects

from_yaml(file_path)

Create a flowsheet from yaml

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_output_streams()

Get the output (product) streams (edge objects)

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(expr[, stream_name, inplace])

Reduce the Flowsheet Stream records with a query

report([apply_formats])

Summary Report

reset_nodes([stream])

Reset stream nodes to break relationships

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_nodes(stream, nodes)

set_stream_child(stream, child)

set_stream_data(stream_data)

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

set_stream_parent(stream, parent)

solve()

Solve missing streams

streams_to_dict()

Export the Stream objects to a Dict

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

Plot with table of edge averages

to_dataframe([stream_names])

Return a tidy dataframe

Attributes

balanced

copy_without_stream_data()[source]

Copy without stream data

filter_by_index(index, inplace=False)[source]

Filter the Flowsheet Stream records by a given index.

Parameters:
  • index (Index) – The index to filter the data.

  • inplace (bool) – If True, apply the filter in place on the same object, otherwise return a new instance.

Return type:

Flowsheet

Returns:

A Flowsheet object where the stream records are filtered by the given index.

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_dict(config)[source]

Create a flowsheet from a dictionary

Parameters:

config (dict) – dictionary containing the flowsheet configuration

Return type:

TypeVar(FS, bound= Flowsheet)

Returns:

A Flowsheet object with no data on the edges

classmethod from_json(file_path)[source]

Create a flowsheet from json

Parameters:

file_path (Path) – path to the json file

Return type:

TypeVar(FS, bound= Flowsheet)

Returns:

A Flowsheet object with no data on the edges

classmethod from_objects(objects, name='Flowsheet')[source]

Instantiate from a list of objects

This method is only suitable for objects that have the _nodes property set, such as objects that have been created from math operations, which preserve relationships between objects (via the nodes property)

Parameters:
  • objects (list[TypeVar(MC, bound= MassComposition)]) – List of MassComposition objects, such as Sample, IntervalSample, Stream or BlockModel

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

Return type:

TypeVar(FS, bound= Flowsheet)

Returns:

classmethod from_yaml(file_path)[source]

Create a flowsheet from yaml

Parameters:

file_path (Path) – path to the yaml file

Return type:

TypeVar(FS, bound= Flowsheet)

Returns:

A Flowsheet object with no data on the edges

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:

TypeVar(MC, bound= MassComposition)

Returns:

get_input_streams()[source]

Get the input (feed) streams (edge objects)

Return type:

list[TypeVar(MC, bound= MassComposition)]

Returns:

List of MassComposition-like objects

get_output_streams()[source]

Get the output (product) streams (edge objects)

Return type:

list[TypeVar(MC, bound= MassComposition)]

Returns:

List of MassComposition-like objects

nodes_to_dict()[source]

Export the MCNode objects to a Dict

Return type:

Dict[int, TypeVar(OP, bound= Operation)]

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_dry', 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(expr, stream_name=None, inplace=False)[source]

Reduce the Flowsheet Stream records with a query

Parameters:
  • expr (str) – The query string to apply to all streams. The query is applied in place. The LHS of the expression requires a prefix that defines the stream name e.g. stream_name.var_name > 0.5

  • stream_name (Optional[str]) – The name of the stream to apply the query to. If None, the query is applied to the first input stream.

  • inplace – If True, apply the query in place on the same object, otherwise return a new instance.

Return type:

Flowsheet

Returns:

A Flowsheet object where the stream records conform to the query

report(apply_formats=False)[source]

Summary Report

Total Mass and weight averaged composition Returns:

Return type:

DataFrame

reset_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:

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

solve()[source]

Solve missing streams

streams_to_dict()[source]

Export the Stream objects to a Dict

Return type:

Dict[str, TypeVar(MC, bound= 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_dry', 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(stream_names=None)[source]

Return a tidy dataframe

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

Parameters:

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

Returns: