Filtering

Filtering is often required to reduce the data of a MassComposition object to a specific subset of interest.

Both individual objects can be filtered, as can multiple objects contained within a Flowsheet object.

import pandas as pd

from elphick.mass_composition import MassComposition
from elphick.mass_composition.flowsheet import Flowsheet
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='demo')
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


Filtering Single Objects

One of the most common subsets is one that contains records above a particular grade. The method used to filter is called query, for consistency with the xarray and pandas methods that execute the same.

obj_1: MassComposition = obj_mc.query({'index': 'Fe>58'})
obj_1.data.to_dataframe()
mass_wet mass_dry H2O Fe SiO2 Al2O3 LOI group
index
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


Notice that the record with an Fe value below 58 has been removed.

Filtering Multiple Objects

Multiple objects can be loaded into a Flowsheet. We’ll make a small network to demonstrate.

obj_one, obj_two = obj_mc.split(fraction=0.6, name_1='one', name_2='two')

fs: Flowsheet = Flowsheet.from_streams([obj_mc, obj_one, obj_two], name='Network')

The weighted mean mass-composition of each object/edge/stream in the network can be reported out with the report method.

fs.report()
mass_wet mass_dry H2O Fe SiO2 Al2O3 LOI
name
demo 300.0 260.0 13.333333 59.0 3.515385 1.873077 4.0
one 180.0 156.0 13.333333 59.0 3.515385 1.873077 4.0
two 120.0 104.0 13.333333 59.0 3.515385 1.873077 4.0


Now we’ll filter as we did before, though we must specify which object the query criteria is to be applied to.

fs.query(mc_name='demo', queries={'index': 'Fe>58'}).report()
mass_wet mass_dry H2O Fe SiO2 Al2O3 LOI
name
demo 200.0 170.0 15.0 60.058824 2.623529 1.276471 3.470588
one 120.0 102.0 15.0 60.058824 2.623529 1.276471 3.470588
two 80.0 68.0 15.0 60.058824 2.623529 1.276471 3.470588


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

Gallery generated by Sphinx-Gallery