.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/001_basic_usage.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_001_basic_usage.py: Basic usage =========== A simple example demonstrating how to use mass-composition. Design notes: Once data is loaded chemical analyte names and H2O will conform to the internal standard. .. GENERATED FROM PYTHON SOURCE LINES 11-17 .. code-block:: default import pandas as pd from elphick.mass_composition import MassComposition from elphick.mass_composition.datasets.sample_data import sample_data .. GENERATED FROM PYTHON SOURCE LINES 18-22 Create a MassComposition object ------------------------------- We get some demo data in the form of a pandas DataFrame .. GENERATED FROM PYTHON SOURCE LINES 23-27 .. code-block:: default df_data: pd.DataFrame = sample_data() df_data .. raw:: html
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


.. GENERATED FROM PYTHON SOURCE LINES 28-29 Construct a MassComposition object .. GENERATED FROM PYTHON SOURCE LINES 30-34 .. code-block:: default obj_mc: MassComposition = MassComposition(df_data) print(obj_mc) .. rst-class:: sphx-glr-script-out .. code-block:: none unnamed Size: 216B Dimensions: (index: 3) Coordinates: * index (index) int64 24B 0 1 2 Data variables: mass_wet (index) float64 24B 100.0 90.0 110.0 mass_dry (index) float64 24B 90.0 80.0 90.0 H2O (index) float64 24B 10.0 11.11 18.18 Fe (index) float64 24B 57.0 59.0 61.0 SiO2 (index) float64 24B 5.2 3.1 2.2 Al2O3 (index) float64 24B 3.0 1.7 0.9 LOI (index) float64 24B 5.0 4.0 3.0 group (index) object 24B 'grp_1' 'grp_1' 'grp_2' Attributes: mc_name: unnamed mc_vars_mass: ['mass_wet', 'mass_dry'] mc_vars_chem: ['Fe', 'SiO2', 'Al2O3', 'LOI'] mc_vars_attrs: ['group'] mc_interval_edges: {} .. GENERATED FROM PYTHON SOURCE LINES 35-39 Demonstrate the aggregate method -------------------------------- i.e. weight average of the dataset, a.k.a. head grade .. GENERATED FROM PYTHON SOURCE LINES 40-43 .. code-block:: default obj_mc.aggregate() .. raw:: html
mass_wet mass_dry H2O Fe SiO2 Al2O3 LOI
name
unnamed 300.0 260.0 13.333333 59.0 3.515385 1.873077 4.0


.. GENERATED FROM PYTHON SOURCE LINES 44-46 .. code-block:: default obj_mc.aggregate(as_dataframe=False) .. raw:: html
<xarray.Dataset> Size: 56B
    Dimensions:   (index: 1)
    Dimensions without coordinates: index
    Data variables:
        mass_wet  (index) float64 8B 300.0
        mass_dry  (index) float64 8B 260.0
        H2O       (index) float64 8B 13.33
        Fe        (index) float64 8B 59.0
        SiO2      (index) float64 8B 3.515
        Al2O3     (index) float64 8B 1.873
        LOI       (index) float64 8B 4.0
    Attributes:
        mc_name:            Aggregate of unnamed
        mc_vars_mass:       ['mass_wet', 'mass_dry']
        mc_vars_chem:       ['Fe', 'SiO2', 'Al2O3', 'LOI']
        mc_vars_attrs:      []
        mc_interval_edges:  {}


.. GENERATED FROM PYTHON SOURCE LINES 47-48 Aggregate by a group variable .. GENERATED FROM PYTHON SOURCE LINES 49-52 .. code-block:: default obj_mc.aggregate(group_var='group') .. raw:: html
mass_wet mass_dry H2O Fe SiO2 Al2O3 LOI
group
grp_1 190.0 170.0 10.526316 57.941176 4.211765 2.388235 4.529412
grp_2 110.0 90.0 18.181818 61.000000 2.200000 0.900000 3.000000


.. GENERATED FROM PYTHON SOURCE LINES 53-57 Filter the object ----------------- Filter with a criteria, just like pandas .. GENERATED FROM PYTHON SOURCE LINES 58-61 .. code-block:: default obj_mc.query(queries={'index': 'Fe>58'}).aggregate() .. raw:: html
mass_wet mass_dry H2O Fe SiO2 Al2O3 LOI
name
unnamed 200.0 170.0 15.0 60.058824 2.623529 1.276471 3.470588


.. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.151 seconds) .. _sphx_glr_download_auto_examples_001_basic_usage.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 001_basic_usage.py <001_basic_usage.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 001_basic_usage.ipynb <001_basic_usage.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_