Compare

Consistent MassComposition objects can be compared. Objects generated by math operations, or connected in an Flowsheet are candidates for comparison.

Comparison can be performed by: - recovery - difference - divide

import pandas as pd
import plotly
import xarray as xr

from elphick.mass_composition import MassComposition
from elphick.mass_composition.datasets.sample_data import sample_data

Create a MassComposition object

We get some demo data in the form of a pandas DataFrame

df_data: pd.DataFrame = sample_data()
df_data
wet_mass mass_dry FE SIO2 al2o3 LOI group
index
0 100.0 90.0 57.0 5.2 3.0 5.0 grp_1
1 90.0 80.0 59.0 3.1 1.7 4.0 grp_1
2 110.0 90.0 61.0 2.2 0.9 3.0 grp_2


Construct a MassComposition object

obj_mc: MassComposition = MassComposition(df_data, name='product')
obj_mc.data.to_dataframe()
mass_wet mass_dry H2O Fe SiO2 Al2O3 LOI group
index
0 100.0 90.0 10.000000 57.0 5.2 3.0 5.0 grp_1
1 90.0 80.0 11.111111 59.0 3.1 1.7 4.0 grp_1
2 110.0 90.0 18.181818 61.0 2.2 0.9 3.0 grp_2


Compare by Recovery

Recovery for an object is defined as the proportion of component mass compared with (divided by) the component mass of another object. In mineral processing recovery is often used to compare the recovered “metal” in product compared to what was fed. Recovery is also an important metric when considering internal separation circuits inside a larger facility.

In this example we’ll simply double the test object and call it ‘feed’

obj_mc_ref: MassComposition = obj_mc.add(obj_mc, name='feed')
obj_mc_ref.data.to_dataframe()
mass_wet mass_dry H2O Fe SiO2 Al2O3 LOI group
index
0 200.0 180.0 10.000000 57.0 5.2 3.0 5.0 grp_1
1 180.0 160.0 11.111111 59.0 3.1 1.7 4.0 grp_1
2 220.0 180.0 18.181818 61.0 2.2 0.9 3.0 grp_2


rec_1: pd.DataFrame = obj_mc.compare(comparisons='recovery', other=obj_mc_ref)
rec_1
product_mass_wet_rec_feed product_mass_dry_rec_feed product_H2O_rec_feed product_Fe_rec_feed product_SiO2_rec_feed product_Al2O3_rec_feed product_LOI_rec_feed
index
0 0.5 0.5 0.5 0.5 0.5 0.5 0.5
1 0.5 0.5 0.5 0.5 0.5 0.5 0.5
2 0.5 0.5 0.5 0.5 0.5 0.5 0.5


By default the variable names are explicit for clarity, though the basic variables names can be preserved.

rec_2: pd.DataFrame = obj_mc.compare(comparisons='recovery', other=obj_mc_ref, explicit_names=False)
rec_2
mass_wet mass_dry H2O Fe SiO2 Al2O3 LOI
index
0 0.5 0.5 0.5 0.5 0.5 0.5 0.5
1 0.5 0.5 0.5 0.5 0.5 0.5 0.5
2 0.5 0.5 0.5 0.5 0.5 0.5 0.5


An xarray Dataset can be returned if desired.

rec_3: xr.Dataset = obj_mc.compare(comparisons='recovery', other=obj_mc_ref, explicit_names=False, as_dataframe=False)
rec_3
<xarray.Dataset> Size: 192B
Dimensions:   (index: 3)
Coordinates:
  * index     (index) int64 24B 0 1 2
Data variables:
    mass_wet  (index) float64 24B 0.5 0.5 0.5
    mass_dry  (index) float64 24B 0.5 0.5 0.5
    H2O       (index) float64 24B 0.5 0.5 0.5
    Fe        (index) float64 24B 0.5 0.5 0.5
    SiO2      (index) float64 24B 0.5 0.5 0.5
    Al2O3     (index) float64 24B 0.5 0.5 0.5
    LOI       (index) float64 24B 0.5 0.5 0.5


Compare by Difference

Comparing by difference simply subtracts mass and composition. No conversion of composition to mass units is made.

rec_4: pd.DataFrame = obj_mc.compare(comparisons='difference', other=obj_mc_ref)
rec_4
product_mass_wet_diff_feed product_mass_dry_diff_feed product_H2O_diff_feed product_Fe_diff_feed product_SiO2_diff_feed product_Al2O3_diff_feed product_LOI_diff_feed
index
0 -100.0 -90.0 0.0 7.105427e-15 0.0 -4.440892e-16 0.000000e+00
1 -90.0 -80.0 0.0 -7.105427e-15 0.0 -2.220446e-16 0.000000e+00
2 -110.0 -90.0 0.0 0.000000e+00 0.0 -1.110223e-16 -4.440892e-16


Compare by Division

Comparing by simply dividing mass and composition. No conversion of composition to mass units is made. In the mineral processing context, the result may be described as the “upgrade ratio”.

rec_5: pd.DataFrame = obj_mc.compare(comparisons='divide', other=obj_mc_ref)
rec_5
product_mass_wet_ur_feed product_mass_dry_ur_feed product_H2O_ur_feed product_Fe_ur_feed product_SiO2_ur_feed product_Al2O3_ur_feed product_LOI_ur_feed
index
0 0.5 0.5 1.0 1.0 1.0 1.0 1.0
1 0.5 0.5 1.0 1.0 1.0 1.0 1.0
2 0.5 0.5 1.0 1.0 1.0 1.0 1.0


Multiple Comparisons

More than one comparison can be performed at once.

rec_6: pd.DataFrame = obj_mc.compare(comparisons=['recovery', 'divide'], other=obj_mc_ref)
rec_6.T
index 0 1 2
product_mass_wet_rec_feed 0.5 0.5 0.5
product_mass_dry_rec_feed 0.5 0.5 0.5
product_H2O_rec_feed 0.5 0.5 0.5
product_Fe_rec_feed 0.5 0.5 0.5
product_SiO2_rec_feed 0.5 0.5 0.5
product_Al2O3_rec_feed 0.5 0.5 0.5
product_LOI_rec_feed 0.5 0.5 0.5
product_mass_wet_ur_feed 0.5 0.5 0.5
product_mass_dry_ur_feed 0.5 0.5 0.5
product_H2O_ur_feed 1.0 1.0 1.0
product_Fe_ur_feed 1.0 1.0 1.0
product_SiO2_ur_feed 1.0 1.0 1.0
product_Al2O3_ur_feed 1.0 1.0 1.0
product_LOI_ur_feed 1.0 1.0 1.0


Or using “all”

rec_7: pd.DataFrame = obj_mc.compare(comparisons='all', other=obj_mc_ref)
rec_7.T
index 0 1 2
product_mass_wet_rec_feed 5.000000e-01 5.000000e-01 5.000000e-01
product_mass_dry_rec_feed 5.000000e-01 5.000000e-01 5.000000e-01
product_H2O_rec_feed 5.000000e-01 5.000000e-01 5.000000e-01
product_Fe_rec_feed 5.000000e-01 5.000000e-01 5.000000e-01
product_SiO2_rec_feed 5.000000e-01 5.000000e-01 5.000000e-01
product_Al2O3_rec_feed 5.000000e-01 5.000000e-01 5.000000e-01
product_LOI_rec_feed 5.000000e-01 5.000000e-01 5.000000e-01
product_mass_wet_diff_feed -1.000000e+02 -9.000000e+01 -1.100000e+02
product_mass_dry_diff_feed -9.000000e+01 -8.000000e+01 -9.000000e+01
product_H2O_diff_feed 0.000000e+00 0.000000e+00 0.000000e+00
product_Fe_diff_feed 7.105427e-15 -7.105427e-15 0.000000e+00
product_SiO2_diff_feed 0.000000e+00 0.000000e+00 0.000000e+00
product_Al2O3_diff_feed -4.440892e-16 -2.220446e-16 -1.110223e-16
product_LOI_diff_feed 0.000000e+00 0.000000e+00 -4.440892e-16
product_mass_wet_ur_feed 5.000000e-01 5.000000e-01 5.000000e-01
product_mass_dry_ur_feed 5.000000e-01 5.000000e-01 5.000000e-01
product_H2O_ur_feed 1.000000e+00 1.000000e+00 1.000000e+00
product_Fe_ur_feed 1.000000e+00 1.000000e+00 1.000000e+00
product_SiO2_ur_feed 1.000000e+00 1.000000e+00 1.000000e+00
product_Al2O3_ur_feed 1.000000e+00 1.000000e+00 1.000000e+00
product_LOI_ur_feed 1.000000e+00 1.000000e+00 1.000000e+00


Comparison Plot

This plot compares one stream against another, with one component per subplot.

fig = obj_mc.plot_comparison(other=obj_mc_ref)
fig.update_layout(height=600)
fig


With color, excluded variable, and trendline. The trendline is per color (group). Since grp2 is a single point, no trendline applies.

fig = obj_mc.plot_comparison(other=obj_mc_ref, vars_exclude=['H2O'], color='group', trendline=True)
fig.update_layout(height=600)
# noinspection PyArgumentList,PyTypeChecker
plotly.io.show(fig)

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

Gallery generated by Sphinx-Gallery