elphick.mass_composition.flowsheet.Flowsheet
- class elphick.mass_composition.flowsheet.Flowsheet(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 the input (feed) streams (edge objects)
get_node_input_outputs
(node)- rtype:
Tuple
Get the output (product) streams (edge objects)
Get the names of the streams (MC objects on the edges)
imbalance_report
(node)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)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:
Returns:
- 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_streams(streams, name='Flowsheet')[source]
Instantiate from a list of objects
- Parameters:
streams (
List
[Union
[Stream
,MassComposition
]]) – List of MassComposition objectsname (
Optional
[str
]) – name of the network
- Return type:
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:
Returns:
- get_column_formats(columns, strip_percent=False)[source]
- Parameters:
columns (
List
[str
]) – The columns to lookup format strings forstrip_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:
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 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_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 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(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:
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_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 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: