Load Surface from XYZ File

Load a surface from a file of XYZ coordinates

import numpy as np
import omf

# sphinx_gallery_thumbnail_number = 2
import pandas as pd
import pyvista as pv

import omfvista
/home/runner/work/omfvista/omfvista/examples/load-surface.py:11: DeprecationWarning:
Pyarrow will become a required dependency of pandas in the next major release of pandas (pandas 3.0),
(to allow more performant data types, such as the Arrow string type, and better interoperability with other libraries)
but was not found to be installed on your system.
If this would cause problems for you,
please provide us feedback at https://github.com/pandas-dev/pandas/issues/54466

  import pandas as pd
base_quaternary_df = pd.read_csv("../assets/mod_base_quaternary_300_nan.txt")
print(base_quaternary_df.head())
             x             y   z
0  633025.9964  5.821552e+06 NaN
1  633325.9964  5.821552e+06 NaN
2  633625.9964  5.821552e+06 NaN
3  633925.9964  5.821552e+06 NaN
4  634225.9964  5.821552e+06 NaN

Create a pyvista dataset out of the coordinates

x = base_quaternary_df["x"].values
y = base_quaternary_df["y"].values
z = np.zeros_like(x)
# simply pass the numpy points to the PolyData constructor
cloud = pv.PolyData(np.c_[x, y, z])
# Add data values onto the mesh nodes
cloud["my data"] = base_quaternary_df["z"].values

Make a surface using the delaunay filter

surf = cloud.delaunay_2d()
surf.plot()
load surface

Now warp by a scalar to have a more realistic surface Note the scaling factor that exagerates the surface

warped = surf.warp_by_scalar(factor=5.0)
warped.plot()
load surface

Create an OMF element that can be saved out

tris = warped.faces.reshape(surf.n_cells, 4)[:, 1:4]
base_quaternary_omf = omf.SurfaceElement(
    name="My Surface",
    description='This is a decription of "My Surface"',
    geometry=omf.SurfaceGeometry(vertices=warped.points, triangles=tris),
    data=[
        omf.ScalarData(
            name="My awesome data", array=np.array(surf["my data"]), location="vertices"
        ),
    ],
)
base_quaternary_omf.validate()
True

Sanity check

omfvista.wrap(base_quaternary_omf).plot()
load surface

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

Gallery generated by Sphinx-Gallery