.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_omf_blockmodel_to_pandas.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_01_omf_blockmodel_to_pandas.py: OMF Block Model to DataFrame ============================ An omf TensorGridBlockModel represents a `Block Model`, and can be converted to a Pandas DataFrame. .. GENERATED FROM PYTHON SOURCE LINES 8-14 .. code-block:: Python from pathlib import Path import pandas as pd from omfpandas import OMFPandasReader .. GENERATED FROM PYTHON SOURCE LINES 15-18 Instantiate ----------- Create the object OMFPandas with the path to the OMF file. .. GENERATED FROM PYTHON SOURCE LINES 18-21 .. code-block:: Python test_omf_path: Path = Path('../assets/test_file.omf') omfp: OMFPandasReader = OMFPandasReader(filepath=test_omf_path) .. GENERATED FROM PYTHON SOURCE LINES 22-23 We'll inspect the elements in the omf file, and determine what volume element to convert. .. GENERATED FROM PYTHON SOURCE LINES 23-26 .. code-block:: Python omfp.element_types .. rst-class:: sphx-glr-script-out .. code-block:: none {'tensor': 'TensorGridBlockModel', 'regular': 'RegularBlockModel'} .. GENERATED FROM PYTHON SOURCE LINES 27-31 Read ---- We can see by inspection that we have one volume element in the omf file called *vol*, so we will convert that to a Pandas DataFrame. .. GENERATED FROM PYTHON SOURCE LINES 31-36 .. code-block:: Python blocks: pd.DataFrame = omfp.read_blockmodel(blockmodel_name='regular', attributes=None) print(f"DataFrame shape: {blocks.shape}") blocks.head() .. rst-class:: sphx-glr-script-out .. code-block:: none DataFrame shape: (3000, 1) .. raw:: html
random attr
x y z
10.5 10.5 -9.5 0.727986
-8.5 0.277389
-7.5 0.351741
-6.5 0.999272
-5.5 0.495092


.. GENERATED FROM PYTHON SOURCE LINES 37-40 The index contains the centroid coordinates and the dimensions of the block. The columns contain the *cell* variables in the block model. Data assigned as points (at the grid vertices) are not included in the DataFrame. .. GENERATED FROM PYTHON SOURCE LINES 42-45 Filter ------ Standard pandas query expressions can be used to filter the returned data. .. GENERATED FROM PYTHON SOURCE LINES 45-49 .. code-block:: Python blocks_filtered: pd.DataFrame = omfp.read_blockmodel(blockmodel_name='regular', attributes=None, query='`random attr`>0.5') print(f"DataFrame shape: {blocks_filtered.shape}") blocks_filtered.head() .. rst-class:: sphx-glr-script-out .. code-block:: none DataFrame shape: (1449, 1) .. raw:: html
random attr
x y z
10.5 10.5 -9.5 0.727986
-6.5 0.999272
-4.5 0.795395
-2.5 0.922014
-0.5 0.514966


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.035 seconds) .. _sphx_glr_download_auto_examples_01_omf_blockmodel_to_pandas.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01_omf_blockmodel_to_pandas.ipynb <01_omf_blockmodel_to_pandas.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01_omf_blockmodel_to_pandas.py <01_omf_blockmodel_to_pandas.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_