.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/examples/04_block_model/02_load_block_model.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_examples_04_block_model_02_load_block_model.py: Load Block Model ================ Demonstrates loading a block model in parquet format into pyvista. .. GENERATED FROM PYTHON SOURCE LINES 8-19 .. code-block:: Python import logging from pathlib import Path import numpy as np import pandas as pd import pyvista as pv from elphick.geomet import Sample from elphick.geomet.block_model import BlockModel logging.basicConfig(level=logging.DEBUG) .. GENERATED FROM PYTHON SOURCE LINES 20-22 Load ---- .. GENERATED FROM PYTHON SOURCE LINES 22-30 .. code-block:: Python block_model_filepath: Path = Path("../../assets/copper_deposit.parquet") # Load the parquet file into a DataFrame df = pd.read_parquet(block_model_filepath) print(df.shape) df.head() .. rst-class:: sphx-glr-script-out .. code-block:: none (1689600, 1) .. raw:: html
CU_pct
x y z
444705.0 492805.0 2335.0 0.002696
444715.0 492805.0 2335.0 0.002760
444725.0 492805.0 2335.0 0.002826
444735.0 492805.0 2335.0 0.002894
444745.0 492805.0 2335.0 0.002964


.. GENERATED FROM PYTHON SOURCE LINES 31-39 Create a BlockModel ------------------- The `BlockModel` class is a subclass of `MassComposition` and inherits all its attributes and methods. The block model plotted below is regular, that is, it has a record for every block in the model. Blocks are the same size and adjacent to each other. The block model is created from a DataFrame that has columns for the x, y, z coordinates and the copper percentage. We need to assign a dry mass (DMT) to the block model to conform to the underlying `MassComposition` class. .. GENERATED FROM PYTHON SOURCE LINES 39-46 .. code-block:: Python bm: BlockModel = BlockModel(data=df.rename(columns={'CU_pct': 'Cu'}).assign(**{'DMT': 2000}), name='block_model', moisture_in_scope=False) bm._mass_data.head() print(bm.is_irregular) print(bm.common_block_size()) .. rst-class:: sphx-glr-script-out .. code-block:: none False (np.float64(10.0), np.float64(10.0), np.float64(10.0)) .. GENERATED FROM PYTHON SOURCE LINES 47-50 .. code-block:: Python bm.data.head() .. raw:: html
DMT Cu
x y z
444705.0 492805.0 2335.0 2000 0.002696
444715.0 492805.0 2335.0 2000 0.002760
444725.0 492805.0 2335.0 2000 0.002826
444735.0 492805.0 2335.0 2000 0.002894
444745.0 492805.0 2335.0 2000 0.002964


.. GENERATED FROM PYTHON SOURCE LINES 51-53 Plot the block model -------------------- .. GENERATED FROM PYTHON SOURCE LINES 53-56 .. code-block:: Python bm.plot('Cu').show(auto_close=False) .. image-sg:: /auto_examples/examples/04_block_model/images/sphx_glr_02_load_block_model_001.png :alt: 02 load block model :srcset: /auto_examples/examples/04_block_model/images/sphx_glr_02_load_block_model_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 57-63 Filter the data --------------- When a dataframe that represents a regular block model (a record for every block) is filtered, the resulting block model cannot be regular anymore. This is because the filtering operation may remove blocks that are adjacent to each other, resulting in a block model that is irregular. This example demonstrates this behavior. The plot below is generated from a filtered block model that was originally regular. .. GENERATED FROM PYTHON SOURCE LINES 63-69 .. code-block:: Python df_filtered = df.query('CU_pct > 0.132').copy() bm2: BlockModel = BlockModel(data=df_filtered.rename(columns={'CU_pct': 'Cu'}).assign(**{'DMT': 2000}), name='block_model', moisture_in_scope=False) bm2._mass_data.shape .. rst-class:: sphx-glr-script-out .. code-block:: none (766492, 2) .. GENERATED FROM PYTHON SOURCE LINES 70-72 .. code-block:: Python bm2.plot('Cu').show(auto_close=False) .. image-sg:: /auto_examples/examples/04_block_model/images/sphx_glr_02_load_block_model_002.png :alt: 02 load block model :srcset: /auto_examples/examples/04_block_model/images/sphx_glr_02_load_block_model_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.062 seconds) .. _sphx_glr_download_auto_examples_examples_04_block_model_02_load_block_model.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 02_load_block_model.ipynb <02_load_block_model.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 02_load_block_model.py <02_load_block_model.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_