Note
Click here to download the full example code
Grade Tonnage
The “Grade Tonnage” curve is often used to characterise an entire deposit. It is a cumulative view that presents the “mass (tonnes) and head grade” with increasing cut-off grade.
They are useful in comparing deposits.
import pandas as pd
import plotly
from elphick.mass_composition import MassComposition
from elphick.mass_composition.datasets.sample_data import iron_ore_sample_data
import xarray as xr
Create a MassComposition object
We get some demo data in the form of a pandas DataFrame
df_data: pd.DataFrame = iron_ore_sample_data()
name = 'A072391'
df_data.drop(columns=['Na2O', 'CaO', 'MnO', 'TiO2', 'P', 'K2O', 'MgO'], inplace=True)
print(df_data.shape)
df_data.head()
(126, 8)
obj_mc: MassComposition = MassComposition(df_data, name=name)
Demonstrate the aggregate function
i.e. weight average of the dataset, a.k.a. head grade
print(obj_mc.aggregate())
print(obj_mc.aggregate(as_dataframe=False))
res: xr.Dataset = obj_mc.binned_mass_composition(cutoff_var='Fe', bin_width=1.0, cumulative=True, as_dataframe=False)
res
mass_wet mass_dry H2O Al2O3 Fe SiO2
name
A072391 2029.617808 1981.688 2.361519 1.773585 60.443938 2.82721
<xarray.Dataset> Size: 48B
Dimensions: (index: 1)
Dimensions without coordinates: index
Data variables:
mass_wet (index) float64 8B 2.03e+03
mass_dry (index) float64 8B 1.982e+03
H2O (index) float64 8B 2.362
Al2O3 (index) float64 8B 1.774
Fe (index) float64 8B 60.44
SiO2 (index) float64 8B 2.827
Attributes:
mc_name: Aggregate of A072391
mc_vars_mass: ['mass_wet', 'mass_dry']
mc_vars_chem: ['Al2O3', 'Fe', 'SiO2']
mc_vars_attrs: []
mc_interval_edges: {}
/home/runner/work/mass-composition/mass-composition/elphick/mass_composition/mc_xarray.py:157: FutureWarning:
The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`.
Tabular Grade bin data
res: pd.DataFrame = obj_mc.binned_mass_composition(cutoff_var='Fe', bin_width=1.0, cumulative=True,
direction='ascending', as_dataframe=True)
res
/home/runner/work/mass-composition/mass-composition/elphick/mass_composition/mc_xarray.py:157: FutureWarning:
The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`.
res: pd.DataFrame = obj_mc.binned_mass_composition(cutoff_var='Fe', bin_width=1.0, cumulative=True,
direction='descending', as_dataframe=True)
res
/home/runner/work/mass-composition/mass-composition/elphick/mass_composition/mc_xarray.py:157: FutureWarning:
The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`.
Plot the Grade Bins
fig = obj_mc.plot_bins(variables=['mass_dry', 'Fe', 'SiO2', 'Al2O3'],
cutoff_var='Fe',
bin_width=1.0,
cumulative=True,
direction='descending')
# noinspection PyTypeChecker
plotly.io.show(fig) # this call to show will set the thumbnail for the gallery
/home/runner/work/mass-composition/mass-composition/elphick/mass_composition/mc_xarray.py:157: FutureWarning:
The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`. To access a mapping from dimension names to lengths, please use `Dataset.sizes`.
Total running time of the script: ( 0 minutes 0.654 seconds)