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

Visualise a 2D image (from array of x, y, z and data points) #28

Closed
kinverarity1 opened this issue Jul 23, 2019 · 3 comments
Closed

Visualise a 2D image (from array of x, y, z and data points) #28

kinverarity1 opened this issue Jul 23, 2019 · 3 comments
Assignees
Labels
add-to-gallery For examples that need to be added to the gallery in the docs mesh-creation Topics around creating a PyVista mesh

Comments

@kinverarity1
Copy link

Description

I'm a bit stuck on how to view a 2D image in a 3D scene. The 2D image is a conductivity model inverted from airborne EM data, collected along a flight line.

I have an array of x, y, z and data points. The x coordinates are not constant, but broadly similar (the flight lines are north-south). The y coordinates are not at a constant spacing, but roughly so. The z coordinates have a similar spacing, but a different starting point, as the elevation changes from north to south. There are the same number of z coordinates for each set of x, y coordinates.

Example code:

import pyvista as pv
import numpy as np
import pandas as pd

df = pd.read_csv("example_flightline.csv")
array = df.sort_values(["elev", "northing", "easting"]).values
ny = len(df.northing.unique())
nz = len(df[(df.easting == soundings.easting[0]) & (df.northing == soundings.northing[0])])
mesh = pv.StructuredGrid()
mesh.points = array[:, :3]
mesh.dimensions = [232, 30, 1]

Full example notebook here: https://github.com/kinverarity1/paraview-2d-viz/blob/master/trying%20to%20create%20structuredgrid.ipynb

image

Example Data

example_flightline.zip

@kinverarity1
Copy link
Author

@banesullivan has very kindly helped me out with this!

So it looks like your points aren’t ordered the way the structured grid needs them. I got it to work by changing where you sort the points from the dataframe:

array = df.sort_values(["northing", "easting", "elev"]).values

then change the dimensions to (1, 30, 232):

dims = (1, 30, 232)
mesh = pv.StructuredGrid()
mesh.points = array[:, :3]
assert np.product(dims) == len(mesh.points)
mesh.dimensions = dims

mesh['log10(cond)'] = np.log10(array[:, -1])

mesh.plot( show_edges=False, show_grid=False, cpos="yz", notebook=False)

Why have the dimensions as (1, 30, 232)? That’s x, z, y - which is how we want to structure the points for this particular data. Your x is constant so ignore that and have it first, then you iterate over the points along the z axis so you will come across 30 nodes before moving to the next sounding which you have 232 of… the dimensions are less about how many nodes are on each axes and more about what is the ordering/structure of the points array because all VTK is doing is creating an indexing array to make the quads between the nodes which doesn’t care about where the nodes are located, just their order with respect to each other.

image

@banesullivan banesullivan added add-to-gallery For examples that need to be added to the gallery in the docs mesh-creation Topics around creating a PyVista mesh labels Jul 23, 2019
@banesullivan
Copy link
Member

Thanks for posting here @kinverarity1!

This is related to pyvista/pyvista#318

@banesullivan
Copy link
Member

And for completeness, the resulting grid looks like:

...
p = pv.BackgroundPlotter()
p.add_mesh(mesh, show_edges=True, nan_opacity=0.)

Screen Shot 2019-07-23 at 8 11 13 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add-to-gallery For examples that need to be added to the gallery in the docs mesh-creation Topics around creating a PyVista mesh
Projects
None yet
Development

No branches or pull requests

2 participants