Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topography grid with NaN elevation values #6

Closed
banesullivan opened this issue May 15, 2019 · 2 comments
Closed

Topography grid with NaN elevation values #6

banesullivan opened this issue May 15, 2019 · 2 comments
Assignees
Labels
data-arrays Adding, using, and accessing data arrays on meshes filtering General topics around filtering and usage of filters

Comments

@banesullivan
Copy link
Member

Description

Originally posted by @lperozzi in OpenGeoVis/omfvista#7

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?

Example Data

Here is the point set
mod_base_quaternary_300_nan.txt.zip

import pyvista as pv
import pandas as pd
import bumpy as np
import omf
import omfvista

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

# simply pass the numpy points to the PolyData constructor
cloud = pv.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

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

many thanks for your help!

@banesullivan
Copy link
Member Author

banesullivan commented May 15, 2019

@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 omfvista
import pyvista as pv
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 = pv.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
omfvista.wrap(base_quaternary_omf).plot(notebook=False)

download

@banesullivan
Copy link
Member Author

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 banesullivan self-assigned this May 15, 2019
@banesullivan banesullivan added filtering General topics around filtering and usage of filters data-arrays Adding, using, and accessing data arrays on meshes labels May 16, 2019
@pyvista pyvista locked and limited conversation to collaborators Feb 12, 2022
@tkoyama010 tkoyama010 converted this issue into a discussion Feb 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
data-arrays Adding, using, and accessing data arrays on meshes filtering General topics around filtering and usage of filters
Projects
None yet
Development

No branches or pull requests

1 participant