-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit de8a8fa
Showing
624 changed files
with
210,507 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+24.2 KB
.doctrees/api/_autosummary/elphick.mass_composition.datasets.datasets.doctree
Binary file not shown.
Binary file added
BIN
+5.78 KB
...es/api/_autosummary/elphick.mass_composition.datasets.datasets.load_a072391_assay.doctree
Binary file not shown.
Binary file added
BIN
+5.81 KB
.../api/_autosummary/elphick.mass_composition.datasets.datasets.load_a072391_collars.doctree
Binary file not shown.
Binary file added
BIN
+5.75 KB
...rees/api/_autosummary/elphick.mass_composition.datasets.datasets.load_a072391_geo.doctree
Binary file not shown.
Binary file added
BIN
+5.75 KB
...rees/api/_autosummary/elphick.mass_composition.datasets.datasets.load_a072391_met.doctree
Binary file not shown.
Binary file added
BIN
+5.82 KB
...api/_autosummary/elphick.mass_composition.datasets.datasets.load_a072391_wireline.doctree
Binary file not shown.
Binary file added
BIN
+5.73 KB
.doctrees/api/_autosummary/elphick.mass_composition.datasets.datasets.load_demo_data.doctree
Binary file not shown.
Binary file added
BIN
+5.92 KB
...tosummary/elphick.mass_composition.datasets.datasets.load_iron_ore_sample_a072391.doctree
Binary file not shown.
Binary file added
BIN
+5.98 KB
...mmary/elphick.mass_composition.datasets.datasets.load_iron_ore_sample_xyz_a072391.doctree
Binary file not shown.
Binary file added
BIN
+5.97 KB
...ummary/elphick.mass_composition.datasets.datasets.load_nordic_iron_ore_sink_float.doctree
Binary file not shown.
Binary file added
BIN
+5.78 KB
...es/api/_autosummary/elphick.mass_composition.datasets.datasets.load_size_by_assay.doctree
Binary file not shown.
Binary file added
BIN
+5.84 KB
...pi/_autosummary/elphick.mass_composition.datasets.datasets.load_size_distribution.doctree
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+13.2 KB
.doctrees/api/_autosummary/elphick.mass_composition.datasets.downloader.Downloader.doctree
Binary file not shown.
Binary file added
BIN
+5.27 KB
.doctrees/api/_autosummary/elphick.mass_composition.datasets.downloader.doctree
Binary file not shown.
Binary file added
BIN
+5.33 KB
.../api/_autosummary/elphick.mass_composition.datasets.sample_data.demo_size_network.doctree
Binary file not shown.
Binary file added
BIN
+10.1 KB
...trees/api/_autosummary/elphick.mass_composition.datasets.sample_data.dh_intervals.doctree
Binary file not shown.
Binary file added
BIN
+17.9 KB
.doctrees/api/_autosummary/elphick.mass_composition.datasets.sample_data.doctree
Binary file not shown.
Binary file added
BIN
+5.4 KB
...utosummary/elphick.mass_composition.datasets.sample_data.iron_ore_met_sample_data.doctree
Binary file not shown.
Binary file added
BIN
+5.34 KB
...i/_autosummary/elphick.mass_composition.datasets.sample_data.iron_ore_sample_data.doctree
Binary file not shown.
Binary file added
BIN
+9.62 KB
.doctrees/api/_autosummary/elphick.mass_composition.datasets.sample_data.sample_data.doctree
Binary file not shown.
Binary file added
BIN
+5.39 KB
...rees/api/_autosummary/elphick.mass_composition.datasets.sample_data.size_by_assay.doctree
Binary file not shown.
Binary file added
BIN
+5.45 KB
...es/api/_autosummary/elphick.mass_composition.datasets.sample_data.size_by_assay_2.doctree
Binary file not shown.
Binary file added
BIN
+5.45 KB
...es/api/_autosummary/elphick.mass_composition.datasets.sample_data.size_by_assay_3.doctree
Binary file not shown.
Binary file added
BIN
+5.29 KB
.../api/_autosummary/elphick.mass_composition.datasets.sample_data.size_distribution.doctree
Binary file not shown.
Binary file added
BIN
+180 KB
.doctrees/api/_autosummary/elphick.mass_composition.flowsheet.Flowsheet.doctree
Binary file not shown.
Binary file added
BIN
+5.11 KB
.doctrees/api/_autosummary/elphick.mass_composition.flowsheet.doctree
Binary file not shown.
Binary file added
BIN
+288 KB
.doctrees/api/_autosummary/elphick.mass_composition.mass_composition.MassComposition.doctree
Binary file not shown.
Binary file added
BIN
+5.36 KB
.doctrees/api/_autosummary/elphick.mass_composition.mass_composition.doctree
Binary file not shown.
Binary file added
BIN
+29.3 KB
.doctrees/api/_autosummary/elphick.mass_composition.mc_node.MCNode.doctree
Binary file not shown.
Binary file added
BIN
+9.49 KB
.doctrees/api/_autosummary/elphick.mass_composition.mc_node.NodeType.doctree
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+9.9 KB
.doctrees/api/_autosummary/elphick.mass_composition.mc_xarray.CompositionContext.doctree
Binary file not shown.
Binary file added
BIN
+78 KB
...trees/api/_autosummary/elphick.mass_composition.mc_xarray.MassCompositionAccessor.doctree
Binary file not shown.
Binary file added
BIN
+8.42 KB
.doctrees/api/_autosummary/elphick.mass_composition.mc_xarray.doctree
Binary file not shown.
Binary file added
BIN
+6.72 KB
.doctrees/api/_autosummary/elphick.mass_composition.mc_xarray.mc_aggregate.doctree
Binary file not shown.
Binary file added
BIN
+117 KB
.doctrees/api/_autosummary/elphick.mass_composition.stream.Stream.doctree
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+10.3 KB
...ees/api/_autosummary/elphick.mass_composition.utils.amenability.amenability_index.doctree
Binary file not shown.
Binary file added
BIN
+4.58 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.amenability.area_trapezoid.doctree
Binary file not shown.
Binary file added
BIN
+7.37 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.amenability.doctree
Binary file not shown.
Binary file added
BIN
+4.83 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.amenability.pairwise.doctree
Binary file not shown.
Binary file added
BIN
+19.2 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.components.doctree
Binary file not shown.
Binary file added
BIN
+5.39 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.components.elements.doctree
Binary file not shown.
Binary file added
BIN
+7.65 KB
...trees/api/_autosummary/elphick.mass_composition.utils.components.is_compositional.doctree
Binary file not shown.
Binary file added
BIN
+7.57 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.components.is_element.doctree
Binary file not shown.
Binary file added
BIN
+7.54 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.components.is_oxide.doctree
Binary file not shown.
Binary file added
BIN
+5.43 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.components.oxides.doctree
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+5.07 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.geometry.doctree
Binary file not shown.
Binary file added
BIN
+4.46 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.geometry.midpoint.doctree
Binary file not shown.
Binary file added
BIN
+5.3 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.hash_utils.check_hash.doctree
Binary file not shown.
Binary file added
BIN
+10.8 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.hash_utils.doctree
Binary file not shown.
Binary file added
BIN
+6.66 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.hash_utils.read_hash.doctree
Binary file not shown.
Binary file added
BIN
+5.73 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.hash_utils.read_hash_file.doctree
Binary file not shown.
Binary file added
BIN
+5.31 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.hash_utils.write_hash.doctree
Binary file not shown.
Binary file added
BIN
+6.48 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.interp.doctree
Binary file not shown.
Binary file added
BIN
+10.6 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.interp.interp_monotonic.doctree
Binary file not shown.
Binary file added
BIN
+16.1 KB
...ees/api/_autosummary/elphick.mass_composition.utils.interp.mass_preserving_interp.doctree
Binary file not shown.
Binary file added
BIN
+7.5 KB
...es/api/_autosummary/elphick.mass_composition.utils.loader.create_mass_composition.doctree
Binary file not shown.
Binary file added
BIN
+8.59 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.loader.doctree
Binary file not shown.
Binary file added
BIN
+13 KB
...ees/api/_autosummary/elphick.mass_composition.utils.loader.streams_from_dataframe.doctree
Binary file not shown.
Binary file added
BIN
+5.34 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.moisture.doctree
Binary file not shown.
Binary file added
BIN
+14.3 KB
...rees/api/_autosummary/elphick.mass_composition.utils.moisture.solve_mass_moisture.doctree
Binary file not shown.
Binary file added
BIN
+23.2 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.parallel.TqdmParallel.doctree
Binary file not shown.
Binary file added
BIN
+5.25 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.parallel.doctree
Binary file not shown.
Binary file added
BIN
+6.32 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.partition.doctree
Binary file not shown.
Binary file added
BIN
+8.81 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.partition.napier_munn.doctree
Binary file not shown.
Binary file added
BIN
+7.43 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.partition.perfect.doctree
Binary file not shown.
Binary file added
BIN
+10.8 KB
...rees/api/_autosummary/elphick.mass_composition.utils.pd_utils.calculate_partition.doctree
Binary file not shown.
Binary file added
BIN
+10.6 KB
...trees/api/_autosummary/elphick.mass_composition.utils.pd_utils.calculate_recovery.doctree
Binary file not shown.
Binary file added
BIN
+6.08 KB
...ees/api/_autosummary/elphick.mass_composition.utils.pd_utils.column_prefix_counts.doctree
Binary file not shown.
Binary file added
BIN
+6.35 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.pd_utils.column_prefixes.doctree
Binary file not shown.
Binary file added
BIN
+10.5 KB
...rees/api/_autosummary/elphick.mass_composition.utils.pd_utils.composition_to_mass.doctree
Binary file not shown.
Binary file added
BIN
+16 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.pd_utils.doctree
Binary file not shown.
Binary file added
BIN
+10.4 KB
...rees/api/_autosummary/elphick.mass_composition.utils.pd_utils.mass_to_composition.doctree
Binary file not shown.
Binary file added
BIN
+10.4 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.pd_utils.weight_average.doctree
Binary file not shown.
Binary file added
BIN
+5.08 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.sampling.doctree
Binary file not shown.
Binary file added
BIN
+4.14 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.sampling.random_int.doctree
Binary file not shown.
Binary file added
BIN
+5.1 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.size.doctree
Binary file not shown.
Binary file added
BIN
+7.34 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.size.mean_size.doctree
Binary file not shown.
Binary file added
BIN
+8.99 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.size_distribution.doctree
Binary file not shown.
Binary file added
BIN
+7.38 KB
...pi/_autosummary/elphick.mass_composition.utils.size_distribution.gaudin_schuhmann.doctree
Binary file not shown.
Binary file added
BIN
+7.17 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.size_distribution.lynch.doctree
Binary file not shown.
Binary file added
BIN
+7.52 KB
...tosummary/elphick.mass_composition.utils.size_distribution.modified_rosin_rammler.doctree
Binary file not shown.
Binary file added
BIN
+7.42 KB
...s/api/_autosummary/elphick.mass_composition.utils.size_distribution.rosin_rammler.doctree
Binary file not shown.
Binary file added
BIN
+93.9 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.sklearn.PandasPipeline.doctree
Binary file not shown.
Binary file added
BIN
+7.12 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.sklearn.doctree
Binary file not shown.
Binary file added
BIN
+4.49 KB
...ees/api/_autosummary/elphick.mass_composition.utils.sklearn.extract_feature_names.doctree
Binary file not shown.
Binary file added
BIN
+5.16 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.viz.doctree
Binary file not shown.
Binary file added
BIN
+10 KB
.doctrees/api/_autosummary/elphick.mass_composition.utils.viz.plot_parallel.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 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.
Empty file.
Binary file not shown.
238 changes: 238 additions & 0 deletions
238
_downloads/073e157de6860283284de3d1698f0b22/resampling_interval_data.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
92
_downloads/079fc7d94a1d3363e8991794bfa25ec0/200_interval_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.