OpenGeoVis / omfvista

3D visualization for the Open Mining Format (omf)

Home Page:https://opengeovis.github.io/omfvista/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nan's int a OMF object

lperozzi opened this issue · comments

I would like to get a surface from a point set into an OMF object. I set np.nan value of points a would like to greyed out. The resulting surface is something like this

image

When I set an out of range value as -9999 to my value the resulting image is:

image

I would like to have the first image with plein color where the value is not np.nan. Any idea?

@lperozzi - would you mind sharing this data file with me? If the data is proprietary, you could sen over a direct message on Slack, I can create a code snippet to perform the task (and fix any bugs if encountered), then delete the file.

@banesullivan no problem to share the data. Here is the point set
mod_base_quaternary_300_nan.txt.zip

base_quaternary = pd.read_csv('mod_base_quaternary_300.txt')

# simply pass the numpy points to the PolyData constructor
cloud = vtki.PolyData(base_quaternary.values)
# Make a surface using the delaunay filter
surf = cloud.delaunay_2d()

tris = surf.faces.reshape(surf.n_cells, 4)[:, 1:4]
base_quaternary = omf.SurfaceElement(
    name='My Surface',
    description='This is a decription of "My Surface"',
    geometry=omf.SurfaceGeometry(vertices=surf.points,
                                 triangles=tris)
    )
base_quaternary.validate()

and then

omfvtk.wrap(base_quaternary).plot(show_edges=False, notebook=False)

many thanks for your help!

@lperozzi, this is an easy fix! The spatial reference of all meshes must be explicit - there cannot be any NaN values when it comes to the mesh's location in space.

NaN values are appropriate when it comes to describing that you do not have data at a given location on the mesh - so it would be more appropriate for you to define your mesh like so...

import pandas as pd
import omf
import omfvtk
import vtki
import numpy as np

base_quaternary_df = pd.read_csv('mod_base_quaternary_300_nan.txt')
base_quaternary_df.head()

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 = vtki.PolyData(np.c_[x,y,z])
# Add data values onto the mesh nodes
cloud['my data'] = base_quaternary_df['z'].values
             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
# Make a surface using the delaunay filter
surf = cloud.delaunay_2d()
surf.plot()

download

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

download

Then you could make an OMF object like:

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

# Sanity check
omfvtk.wrap(base_quaternary_omf).plot(notebook=False)

download

Please note the scaling factor when I call:

warped = surf.warp_by_scalar(factor=5.0)

You likely do not want this and actually want:

warped = surf.warp_by_scalar()

@banesullivan thank you very much!

I'm moving this over to https://github.com/pyvista/pyvista-support as this question mostly pertains to creating a surface from XYZ points with NaN values on a grid in PyVista - this is not necessarily an omfvista specific question.

Welp, this provides an example of why we might want to combine @OpenGeoVis and @pyvista - I can't transfer issues across organizations

In the meantime, I will simply duplicate this