.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/06_reblocking.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_06_reblocking.py: Reblocking ========== .. GENERATED FROM PYTHON SOURCE LINES 7-16 .. code-block:: default import tempfile import pandas as pd from pathlib import Path import pyvista as pv from parq_blockmodel import ParquetBlockModel .. GENERATED FROM PYTHON SOURCE LINES 17-20 Create a Parquet Block Model ---------------------------- We leverage the create_demo_block_model class method to create a Parquet Block Model. .. GENERATED FROM PYTHON SOURCE LINES 20-28 .. code-block:: default temp_dir = Path(tempfile.gettempdir()) / "block_model_example" temp_dir.mkdir(parents=True, exist_ok=True) pbm: ParquetBlockModel = ParquetBlockModel.create_demo_block_model( filename=temp_dir / "demo_block_model.parquet") pbm .. rst-class:: sphx-glr-script-out .. code-block:: none ParquetBlockModel(name=demo_block_model, path=/tmp/block_model_example/demo_block_model.pbm.parquet) .. GENERATED FROM PYTHON SOURCE LINES 29-32 Visualise the Model ------------------- A continuous attribute. .. GENERATED FROM PYTHON SOURCE LINES 32-34 .. code-block:: default pbm.plot(scalar='depth', threshold=False, enable_picking=True).show() .. image-sg:: /auto_examples/images/sphx_glr_06_reblocking_001.png :alt: 06 reblocking :srcset: /auto_examples/images/sphx_glr_06_reblocking_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 35-36 A categorical attribute. .. GENERATED FROM PYTHON SOURCE LINES 36-39 .. code-block:: default pbm.plot(scalar='depth_category', threshold=False, enable_picking=True).show() .. image-sg:: /auto_examples/images/sphx_glr_06_reblocking_002.png :alt: 06 reblocking :srcset: /auto_examples/images/sphx_glr_06_reblocking_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 40-43 Upsampling ------- Create a new grid with smaller blocks, and visualise. .. GENERATED FROM PYTHON SOURCE LINES 43-51 .. code-block:: default upsampled_pbm: ParquetBlockModel = pbm.upsample(new_block_size=(0.5, 0.5, 0.5), interpolation_config={ 'depth': 'linear', 'depth_category': 'nearest' }) upsampled_pbm.plot(scalar='depth', threshold=False, enable_picking=True).show() .. image-sg:: /auto_examples/images/sphx_glr_06_reblocking_003.png :alt: 06 reblocking :srcset: /auto_examples/images/sphx_glr_06_reblocking_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 52-53 Visualise a reblocked categorical attribute. .. GENERATED FROM PYTHON SOURCE LINES 53-55 .. code-block:: default upsampled_pbm.plot(scalar='depth_category', threshold=False, enable_picking=True).show() .. image-sg:: /auto_examples/images/sphx_glr_06_reblocking_004.png :alt: 06 reblocking :srcset: /auto_examples/images/sphx_glr_06_reblocking_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 56-59 Downsample ---------- Downsample the upsampled model back to the original block size. .. GENERATED FROM PYTHON SOURCE LINES 59-69 .. code-block:: default downsampled_pbm: ParquetBlockModel = upsampled_pbm.downsample(new_block_size=(1.0, 1.0, 1.0), aggregation_config={ 'depth': {'method': 'mean'}, 'depth_category': {'method': 'mode'} }) downsampled_pbm.plot(scalar='depth', threshold=False, enable_picking=True).show() downsampled_pbm.plot(scalar='depth_category', threshold=False, enable_picking=True).show() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/images/sphx_glr_06_reblocking_005.png :alt: 06 reblocking :srcset: /auto_examples/images/sphx_glr_06_reblocking_005.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_06_reblocking_006.png :alt: 06 reblocking :srcset: /auto_examples/images/sphx_glr_06_reblocking_006.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 70-73 Validate -------- Confirm the round trip returned the original data .. GENERATED FROM PYTHON SOURCE LINES 73-77 .. code-block:: default blocks_original: pd.DataFrame = pbm.data.to_pandas() blocks_up_down: pd.DataFrame = pbm.data.to_pandas() pd.testing.assert_frame_equal(blocks_original, blocks_up_down) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.160 seconds) .. _sphx_glr_download_auto_examples_06_reblocking.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 06_reblocking.py <06_reblocking.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 06_reblocking.ipynb <06_reblocking.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_