.. 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/01_consuming_omf.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_01_consuming_omf.py: Consuming OMF ============= This example demonstrates how to consume an Open Mining Format file .. GENERATED FROM PYTHON SOURCE LINES 7-16 .. code-block:: Python import tempfile from pathlib import Path import pandas as pd import pooch from omfpandas import OMFPandasReader from elphick.geomet.block_model import BlockModel .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/geometallurgy/geometallurgy/.venv/lib/python3.12/site-packages/stringcase.py:247: SyntaxWarning: invalid escape sequence '\W' .. GENERATED FROM PYTHON SOURCE LINES 17-19 Load ---- .. GENERATED FROM PYTHON SOURCE LINES 19-29 .. code-block:: Python # Cache an omf2 file locally filepath: Path = Path(pooch.retrieve( url="https://raw.githubusercontent.com/elphick/omfpandas/main/assets/copper_deposit.omf", known_hash=None, path=Path(tempfile.gettempdir()) / "geometallurgy")) omfpr: OMFPandasReader = OMFPandasReader(filepath=filepath) blocks: pd.DataFrame = omfpr.read_blockmodel(blockmodel_name='Block Model') .. GENERATED FROM PYTHON SOURCE LINES 30-33 Create mass ----------- The mass of each block is calculated from the volume and a density of 2.265 g/cm3. .. GENERATED FROM PYTHON SOURCE LINES 33-40 .. code-block:: Python blocks.reset_index(level=['dx', 'dy', 'dz'], inplace=True) blocks['volume'] = blocks.dx * blocks.dy * blocks.dz blocks.reset_index().set_index(keys=['x', 'y', 'z', 'dx', 'dy', 'dz'], inplace=True) blocks.rename(columns={'CU_pct': 'Cu'}, inplace=True) blocks['mass'] = blocks['volume'] * 2.265 .. GENERATED FROM PYTHON SOURCE LINES 41-45 Create a BlockModel ------------------- The BlockModel is created from the DataFrame and visualised. This model can be used in a Flowsheet model to make metallurgical predictions and preserve the spatial context. .. GENERATED FROM PYTHON SOURCE LINES 45-52 .. code-block:: Python bm: BlockModel = BlockModel(name=filepath.stem, data=blocks, mass_dry_var='mass', moisture_in_scope=False) p = bm.plot(scalar='Cu') p.title = filepath.stem p.show() .. image-sg:: /auto_examples/examples/04_block_model/images/sphx_glr_01_consuming_omf_001.png :alt: 01 consuming omf :srcset: /auto_examples/examples/04_block_model/images/sphx_glr_01_consuming_omf_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 53-59 Create from the omf directly ---------------------------- The BlockModel can be created directly from the OMF file. This is useful when the data is not yet in a DataFrame. .. note:: This requires components to be chemical symbols. This is not the case for the sample omf file (at this stage). .. GENERATED FROM PYTHON SOURCE LINES 59-62 .. code-block:: Python # bm: BlockModel = BlockModel.from_omf(omf_filepath=filepath, element_name='Block Model', mass_dry_var='mass', # moisture_in_scope=False) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 7.453 seconds) .. _sphx_glr_download_auto_examples_examples_04_block_model_01_consuming_omf.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01_consuming_omf.ipynb <01_consuming_omf.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01_consuming_omf.py <01_consuming_omf.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_