Load Surface from XYZ FileΒΆ

Load a surface from a file of XYZ coordinates

# sphinx_gallery_thumbnail_number = 2
import pandas as pd
import omf
import omfvista
import pyvista as pv
import numpy as np
base_quaternary_df = pd.read_csv('../assets/mod_base_quaternary_300_nan.txt')
print(base_quaternary_df.head())

Out:

             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()
../_images/sphx_glr_load-surface_001.png

Out:

[(893251.2484534496, 5951702.218353449, 211625.25205344972),
 (681625.9963999998, 5740076.9662999995, 0.0),
 (0.0, 0.0, 1.0)]

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()
../_images/sphx_glr_load-surface_002.png

Out:

[(877968.7779754738, 5937620.777975474, 197263.7918914894),
 (684176.0, 5743828.0, 3471.013916015625),
 (0.0, 0.0, 1.0)]

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()

Out:

True

Sanity check

omfvista.wrap(base_quaternary_omf).plot()
../_images/sphx_glr_load-surface_003.png

Out:

[(877968.7779754738, 5937620.777975474, 197263.7918914894),
 (684176.0, 5743828.0, 3471.013916015625),
 (0.0, 0.0, 1.0)]

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

Gallery generated by Sphinx-Gallery