OMF Block Model to DataFrame

An omf TensorGridBlockModel represents a Block Model, and can be converted to a Pandas DataFrame.

from pathlib import Path

import pandas as pd

from omfpandas import OMFPandasReader

Instantiate

Create the object OMFPandas with the path to the OMF file.

test_omf_path: Path = Path('../assets/v2/test_file.omf')
omfp: OMFPandasReader = OMFPandasReader(filepath=test_omf_path)

We’ll inspect the elements in the omf file, and determine what volume element to convert.

omfp.elements
{'Random Points': 'PointSet', 'Random Line': 'LineSet', 'trisurf': 'Surface', 'gridsurf': 'TensorGridSurface', 'vol': 'TensorGridBlockModel'}

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.

blocks: pd.DataFrame = omfp.read_blockmodel(blockmodel_name='vol', attributes=None)
print(f"DataFrame shape: {blocks.shape}")
blocks.head()
DataFrame shape: (3000, 1)
random attr
x y z dx dy dz
10.5 10.5 -9.5 1.0 1.0 1.0 0.727986
11.5 10.5 -9.5 1.0 1.0 1.0 0.277389
12.5 10.5 -9.5 1.0 1.0 1.0 0.351741
13.5 10.5 -9.5 1.0 1.0 1.0 0.999272
14.5 10.5 -9.5 1.0 1.0 1.0 0.495092


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.

Filter

Standard pandas query expressions can be used to filter the returned data.

blocks_filtered: pd.DataFrame = omfp.read_blockmodel(blockmodel_name='vol', attributes=None, query='`random attr`>0.5')
print(f"DataFrame shape: {blocks_filtered.shape}")
blocks_filtered.head()
DataFrame shape: (1449, 1)
random attr
x y z dx dy dz
10.5 10.5 -9.5 1.0 1.0 1.0 0.727986
13.5 10.5 -9.5 1.0 1.0 1.0 0.999272
15.5 10.5 -9.5 1.0 1.0 1.0 0.795395
17.5 10.5 -9.5 1.0 1.0 1.0 0.922014
19.5 10.5 -9.5 1.0 1.0 1.0 0.514966


Total running time of the script: (0 minutes 0.036 seconds)

Gallery generated by Sphinx-Gallery