elphick.geomet.flowsheet.flowsheet.Flowsheet
- class elphick.geomet.flowsheet.flowsheet.Flowsheet(name='Flowsheet')[source]
 - 
Methods
__init__([name])add_operation(operation)Add an operation to the flowsheet.
add_stream(stream)Add a stream to the flowsheet.
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 the input (feed) streams (edge objects)
Get the output (product) streams (edge objects)
get_stream_by_name(name)Get the Stream object from the network by its name
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_operation_data(node)Set the input and output data for a node.
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
Export the Stream objects to a Dict
table_plot([plot_type, cols_exclude, ...])Plot with table of edge averages
to_dataframe([stream_names, tidy, as_mass])Return a tidy dataframe
Return unhealthy nodes
Return on unhealthy streams
Attributes
all_nodes_healthyCheck if all streams are healthy
healthyname- property all_streams_healthy: bool
 Check if all streams are healthy
- 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:
 - 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 DataFramename (
Optional[str]) – name of the networkmc_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:
 
- 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 BlockModelname (
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_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
- get_stream_by_name(name)[source]
 Get the Stream object from the network by its name
- Parameters:
 name (
str) – The string name of the Stream object stored on an edge in the network.- Return type:
 TypeVar(MC, bound= MassComposition)
Returns:
- 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 wrappingcolor (
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 plotcolor (
Optional[str]) – Optional color variablevars_include (
Optional[List[str]]) – Optional List of variables to include in the plotvars_exclude (
Optional[List[str]]) – Optional List of variables to exclude in the plottitle (
Optional[str]) – Optional plot titleinclude_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 widthcolor_var (
Optional[str]) – The optional variable that determines the sankey edge coloredge_colormap (
Optional[str]) – The optional colormap. Used with color_var.vmin (
Optional[float]) – The value that maps to the minimum colorvmax (
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.5stream_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:
 - 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_operation_data(node)[source]
 Set the input and output data for a node. Uses the data on the edges (streams) connected to the node to refresh the data and check for node balance.
- 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,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 tabletable_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 headertable_odd_color (
str) – Color of the odd table rowstable_even_color (
str) – Color of the even table rowssankey_width_var (
str) – If plot_type is sankey, the variable that determines the sankey widthsankey_color_var (
Optional[str]) – If plot_type is sankey, the optional variable that determines the sankey edge colorsankey_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 colorsankey_vmax (
Optional[float]) – The value that maps to the maximum colornetwork_orientation (
Optional[str]) – The orientation of the network layout ‘vertical’|’horizontal’
- Return type:
 Figure
Returns:
- to_dataframe(stream_names=None, tidy=True, as_mass=False)[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 exporttidy (
bool) – If True, the data will be returned in a tidy format, otherwise wideas_mass (
bool) – If True, the mass data will be returned instead of the mass-composition data
- Return type:
 DataFrame
Returns: