Skip to content

Commit

Permalink
deploy: b8fb961
Browse files Browse the repository at this point in the history
  • Loading branch information
elphick committed May 19, 2024
0 parents commit de8a8fa
Show file tree
Hide file tree
Showing 624 changed files with 210,507 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .buildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 41749d055d2b2d79c607248c527c05e5
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/api/modules.doctree
Binary file not shown.
Binary file added .doctrees/auto_examples/001_basic_usage.doctree
Binary file not shown.
Binary file added .doctrees/auto_examples/002_data_examples.doctree
Binary file not shown.
Binary file added .doctrees/auto_examples/003_constrain.doctree
Binary file not shown.
Binary file added .doctrees/auto_examples/004_plot_demo.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/auto_examples/107_filtering.doctree
Binary file not shown.
Binary file added .doctrees/auto_examples/108_sankey_plots.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/auto_examples/112_compare.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/auto_examples/200_interval_data.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/auto_examples/502_dag.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/auto_examples/grade_tonnage.doctree
Binary file not shown.
Binary file added .doctrees/auto_examples/index.doctree
Binary file not shown.
Binary file added .doctrees/auto_examples/iron_ore_assays.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/datasets/datasets.doctree
Binary file not shown.
Binary file added .doctrees/environment.pickle
Binary file not shown.
Binary file added .doctrees/glossary/glossary.doctree
Binary file not shown.
Binary file added .doctrees/index.doctree
Binary file not shown.
Binary file added .doctrees/license/license.doctree
Binary file not shown.
Binary file added .doctrees/usage/installation.doctree
Binary file not shown.
Binary file added .doctrees/usage/quickstart.doctree
Binary file not shown.
Binary file added .doctrees/usage/troubleshooting.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/user_guide/content/03_data.doctree
Binary file not shown.
Binary file added .doctrees/user_guide/user_guide.doctree
Binary file not shown.
Empty file added .nojekyll
Empty file.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Resampling Interval Data\n\nInterval (or fractional) data is common in metallurgy and mineral processing. Samples are sized using sieves\nin a laboratory and each resultant fraction is often assayed to determine chemical composition.\nThe typical nomenclature is of the interval edges is size_retained, size passing - any particle within an interval\nor fraction was retained by the lower sieve size, but passed the sieve size above it.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import logging\n\nimport numpy as np\nimport pandas as pd\nimport plotly\n\nfrom elphick.mass_composition import MassComposition\nfrom elphick.mass_composition.datasets.sample_data import size_by_assay"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"logging.basicConfig(level=logging.INFO,\n format='%(asctime)s %(levelname)s %(module)s - %(funcName)s: %(message)s',\n datefmt='%Y-%m-%dT%H:%M:%S%z',\n )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create a MassComposition object\n\nWe get some demo data in the form of a pandas DataFrame\nWe create this object as 1D based on the pandas index\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df_data: pd.DataFrame = size_by_assay()\ndf_data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The size index is of the Interval type, maintaining the fractional information.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"mc_size: MassComposition = MassComposition(df_data, name='Sample')\nmc_size.data.to_dataframe()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"mc_size.aggregate()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First we'll plot the intervals\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig = mc_size.plot_intervals(variables=['mass_dry', 'Fe', 'SiO2', 'Al2O3'],\n cumulative=False)\nfig"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Size distributions are often plotted in the cumulative form. Cumulative passing is achieved by setting the\ndirection = ascending.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig = mc_size.plot_intervals(variables=['mass_dry', 'Fe', 'SiO2', 'Al2O3'],\n cumulative=True, direction='ascending')\nfig"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we will resample on a defined grid (interval edges) and view the resampled fractions\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"new_edges = np.unique(np.geomspace(1.0e-03, mc_size.data.to_dataframe().index.right.max() * 3, 50))\nnew_coords = np.insert(new_edges, 0, 0)\n\nmc_upsampled: MassComposition = mc_size.resample_1d(interval_edges=new_edges, precision=3, include_original_edges=True)\n\nfig = mc_upsampled.plot_intervals(variables=['mass_dry', 'Fe', 'SiO2', 'Al2O3'], cumulative=False)\n# noinspection PyTypeChecker\nplotly.io.show(fig)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Close inspection of the plot above reals some sharp dips for some mass intervals. This is caused by those intervals\nbeing narrower than the adjacent neighbours, hence they have less absolute mass.\nThis is a visual artefact only, numerically it is correct, as shown by the cumulative plot.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig = mc_upsampled.plot_intervals(variables=['mass_dry', 'Fe', 'SiO2', 'Al2O3'], cumulative=True, direction='ascending')\nfig"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can upsample each of the original fraction by a factor. Since adjacent fractions are similar, the fractional\nplot is reasonably smooth. Note however, that fraction widths are still different, caused by the original sieve\nselection.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"mc_upsampled_2: MassComposition = mc_size.resample_1d(interval_edges=10, precision=3)\nfig = mc_upsampled_2.plot_intervals(variables=['mass_dry', 'Fe', 'SiO2', 'Al2O3'], cumulative=False)\nfig"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Validate the head grade against the original sample\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"pd.testing.assert_frame_equal(mc_size.aggregate().reset_index(drop=True),\n mc_upsampled.aggregate().reset_index(drop=True))\n\npd.testing.assert_frame_equal(mc_size.aggregate().reset_index(drop=True),\n mc_upsampled_2.aggregate().reset_index(drop=True))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Complete a round trip by converting the up-sampled objects back to the original intervals and validate.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"orig_index = mc_size.data.to_dataframe().index\noriginal_edges: np.ndarray = np.sort(np.unique(list(orig_index.left) + list(orig_index.right)))\n\nmc_downsampled: MassComposition = mc_upsampled.resample_1d(interval_edges=original_edges, precision=3)\nmc_downsampled_2: MassComposition = mc_upsampled_2.resample_1d(interval_edges=original_edges, precision=3)\n\npd.testing.assert_frame_equal(mc_size.data.to_dataframe(), mc_downsampled.data.to_dataframe())\npd.testing.assert_frame_equal(mc_size.data.to_dataframe(), mc_downsampled_2.data.to_dataframe())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
92 changes: 92 additions & 0 deletions _downloads/079fc7d94a1d3363e8991794bfa25ec0/200_interval_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"""
Interval Data
=============
This example adds a second dimension. The second dimension is an interval, of the form interval_from, interval_to.
It is also known as binned data, where each 'bin' is bounded between and upper and lower limit.
An interval is relevant in geology, when analysing drill hole data.
Intervals are also encountered in metallurgy, but in that discipline they are often called fractions,
e.g. size fractions. In that case the typical nomenclature is size_retained, size passing, since the data
originates from a sieve stack.
"""
import logging

import pandas as pd
from matplotlib import pyplot as plt

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


# %%
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(levelname)s %(module)s - %(funcName)s: %(message)s',
datefmt='%Y-%m-%dT%H:%M:%S%z',
)

# %%
#
# Create a MassComposition object
# -------------------------------
#
# We get some demo data in the form of a pandas DataFrame
# We create this object as 1D based on the pandas index

df_data: pd.DataFrame = iron_ore_sample_data()
df_data.head()

# %%

obj_mc: MassComposition = MassComposition(df_data,
name='Drill program',
mass_units='kg')
obj_mc

# %%

obj_mc.aggregate()

# %%
obj_mc.aggregate('DHID')

# %%
#
# We will now make a 2D dataset using DHID and the interval.
# We will first create a mean interval variable. Then we will set the dataframe index to both variables before
# constructing the object.

print(df_data.columns)

df_data['DHID'] = df_data['DHID'].astype('category')
# make an int based drillhole identifier
code, dh_id = pd.factorize(df_data['DHID'])
df_data['DH'] = code
df_data = df_data.reset_index().set_index(['DH', 'interval_from', 'interval_to'])

obj_mc_2d: MassComposition = MassComposition(df_data,
name='Drill program',
mass_units='kg')
# obj_mc_2d._data.assign(hole_id=dh_id)
print(obj_mc_2d)
print(obj_mc_2d.aggregate())
print(obj_mc_2d.aggregate('DHID'))

# %%
#
# View some plots
#
# First confirm the parallel plot still works

# TODO: work on the display order
# TODO - fails for DH (integer)

# fig: Figure = obj_mc_2d.plot_parallel(color='Fe')
# fig.show()

# now plot using the xarray data - take advantage of the multi-dim nature of the package

obj_mc_2d.data['Fe'].plot()
plt.show()
Loading

0 comments on commit de8a8fa

Please sign in to comment.