Create Network

Create a network from a DataFrame

import pandas as pd
import plotly

from elphick.mass_composition.datasets.sample_data import size_by_assay_2
from elphick.mass_composition.flowsheet import Flowsheet

Load a dataframe containing 3 streams

The dataframe is tall, indexed by size fractions and stream name

df_data: pd.DataFrame = size_by_assay_2()
df_data
mass_wet mass_dry H2O Fe SiO2 Al2O3
size name
[0.85, 2.0) feed 3.300000 3.300000 0.0 64.15 2.04 2.68
[0.5, 0.85) feed 9.900000 9.900000 0.0 64.33 2.05 2.23
[0.15, 0.5) feed 26.500000 26.500000 0.0 64.52 1.84 2.19
[0.075, 0.15) feed 2.500000 2.500000 0.0 62.65 2.88 3.32
[0.045, 0.075) feed 8.800000 8.800000 0.0 62.81 2.12 2.25
[0.0, 0.045) feed 49.000000 49.000000 0.0 55.95 6.39 6.34
[0.85, 2.0) coarse 3.299990 3.299990 0.0 64.15 2.04 2.68
[0.5, 0.85) coarse 9.860347 9.860347 0.0 64.33 2.05 2.23
[0.15, 0.5) coarse 21.092951 21.092951 0.0 64.52 1.84 2.19
[0.075, 0.15) coarse 0.953958 0.953958 0.0 62.65 2.88 3.32
[0.045, 0.075) coarse 2.349356 2.349356 0.0 62.81 2.12 2.25
[0.0, 0.045) coarse 9.543785 9.543785 0.0 55.95 6.39 6.34
[0.85, 2.0) fine 0.000010 0.000010 0.0 64.15 2.04 2.68
[0.5, 0.85) fine 0.039653 0.039653 0.0 64.33 2.05 2.23
[0.15, 0.5) fine 5.407049 5.407049 0.0 64.52 1.84 2.19
[0.075, 0.15) fine 1.546042 1.546042 0.0 62.65 2.88 3.32
[0.045, 0.075) fine 6.450644 6.450644 0.0 62.81 2.12 2.25
[0.0, 0.045) fine 39.456215 39.456215 0.0 55.95 6.39 6.34


Create a network

fs: Flowsheet = Flowsheet.from_dataframe(df=df_data, mc_name_col='name')
fig = fs.table_plot(plot_type='sankey', table_pos='left', table_area=0.3)
fig
Preparing MassComposition data:   0%|          | 0/3 [00:00<?, ?it/s]
Preparing MassComposition data: 100%|##########| 3/3 [00:00<00:00, 492.17it/s]

Creating MassComposition objects:   0%|          | 0/3 [00:00<?, ?it/s]
Creating MassComposition objects: 100%|##########| 3/3 [00:00<00:00, 24.06it/s]
Creating MassComposition objects: 4it [00:00, 32.02it/s]


The network has no knowledge of the stream relationships, so we need to create those relationships.

fs.set_stream_parent(stream='coarse', parent='feed')
fs.set_stream_parent(stream='fine', parent='feed')

fig = fs.table_plot(plot_type='sankey', table_pos='left', table_area=0.3)
# noinspection PyTypeChecker
plotly.io.show(fig)  # this call to show will set the thumbnail for use in the gallery

Total running time of the script: ( 0 minutes 0.705 seconds)

Gallery generated by Sphinx-Gallery