GithubHelp home page GithubHelp logo

Comments (14)

banesullivan avatar banesullivan commented on July 1, 2024 1

So in brief, the code to make the surface is:

import pandas as pd
import pyvista as pv

# Load Excel sheet using Pandas
# Note - you may need to `pip install xlrd`
df = pd.read_excel('/Users/bane/Downloads/WFA.xlsx')
coords = df[['X', 'Y', 'Z']].values

# Make the structured surface manually
structured = pv.StructuredGrid()
# Set coordinates
structured.points = coords
# Set the dimensions of the structured grid
structured.dimensions = [143, 135, 1]

# Apply an Elevation filter
elevation = structured.elevation()
elevation.plot(show_edges=True, show_grid=True, notebook=False)

from pyvista-support.

akaszynski avatar akaszynski commented on July 1, 2024 1

We should add this as an example in the docs.

Looks great @banesullivan!

from pyvista-support.

banesullivan avatar banesullivan commented on July 1, 2024

Hi @gunjan71011! Could you perhaps share a data file with this type of point data set?

Are your points scattered? or do they have some sort of inherit structure?

Perhaps a quick/dirty approach would be to run a Delaunay triangulation much like this example. To say anything more, I'd need to see the dataset either with a data file or if you could take screenshots from plotting the point set with PyVista.

from pyvista-support.

banesullivan avatar banesullivan commented on July 1, 2024

@gunjan71011, did you attach the file to the email when you replied? You may need to visit this thread’s webpage and drag’n’drop the file into the text box

from pyvista-support.

banesullivan avatar banesullivan commented on July 1, 2024
import pandas as pd
import numpy as np
import pyvista as pv

# Load Excel sheet using Pandas
# Note - you may need to `pip install xlrd`
df = pd.read_excel('/Users/bane/Downloads/WFA.xlsx')
coords = df[['X', 'Y', 'Z']].values

# Preview the coordinates to see what we are dealing with
poly = pv.PolyData(coords)
poly['order'] = np.linspace(0,1,poly.n_points)
poly.plot(notebook=False, show_grid=True, point_size=1)

Screen Shot 2019-06-18 at 9 57 50 AM

The coordinates definitely have some sort of inherit structure present as I can see a structured grid of the points that is a bit rotated from the cartesian reference frame. This dataset would work well if we know the dimensions of the structured grid (nx by ny by 1) as we could recover that structure and add connectivity with quad cells, but this is incredibly difficult to do without knowing the dimensions of the grid (and assuming the coordinates are ordered which they appear to be from the linear trends in the color mapping shown above). Perhaps the original source of this dataset has more details on the grid's structure?

The quick and dirty method of Delaunay triangulation would work to create a surface, however this is a bit expensive for this dataset as it will have twice as many cells as a structured grid with quads and not have exactly the resolution you might desire:

surf = poly.delaunay_2d()
surf.plot(notebook=False, show_grid=True)

Screen Shot 2019-06-18 at 9 55 08 AM

Screen Shot 2019-06-18 at 9 58 52 AM

So this new surface mesh has 38056 triangle cells and 19305 points. Ideally, I'd like to see this mesh as a structured grid with quads and not a polygonal surface, so here's an attempt to recover the structure of the gird which I did by brought force guessing dimensions that looked right and were multiples of the total number of points. I ended up with [143, 135, 1]:

# Make the structured surface manually
structured = pv.StructuredGrid()
# Set coordinates
structured.points = coords
# Set the dimensions of the structured grid
structured.dimensions = [143, 135, 1]

# Apply an Elevation filter
elevation = structured.elevation()
elevation.plot(show_edges=True, show_grid=True, notebook=False)

Screen Shot 2019-06-18 at 10 13 33 AM

Screen Shot 2019-06-18 at 10 13 26 AM

And there you have it, a properly structured surface from your point set with 19028 quad cells and 19305 points/nodes!

from pyvista-support.

banesullivan avatar banesullivan commented on July 1, 2024

Added a simple example and linked to this issue for a better/more complicated example

from pyvista-support.

gunjan71011 avatar gunjan71011 commented on July 1, 2024

Thanks that looks good, although being able to see the changes in elevation would be nice. But thanks for the help!

from pyvista-support.

banesullivan avatar banesullivan commented on July 1, 2024

although being able to see the changes in elevation would be nice

Maybe try adding exaggeration to the render view:

plotter = pv.Plotter(notebook=False)
plotter.add_mesh(elevation)
plotter.set_scale(1, 1, 10)
plotter.show()

from pyvista-support.

gunjan71011 avatar gunjan71011 commented on July 1, 2024

Thanks Bane! That really makes the surface stand out. However, I noticed that if there are multiple surfaces in one plotter then all of it would be exaggerted by the same amount (plotter.set_scale(1, 1, 10)). Is there a way to give each mesh its own exaggeration?

from pyvista-support.

banesullivan avatar banesullivan commented on July 1, 2024

However, I noticed that if there are multiple surfaces in one plotter then all of it would be exaggerted by the same amount (plotter.set_scale(1, 1, 10)). Is there a way to give each mesh its own exaggeration?

You could give each dataset it's own exaggeration by editing the coordinates of each mesh individually and leaving the scale alone - the set_scale function exaggerates the entire render view's spatial reference system so it would be impossible for us to set a scale on each dataset individually and have them still appear next to each other. As a user, though, you could manually scale and shift datasets to your liking. Try editing and shifting the .points of your different meshes before plotting and not using the set_scale function:

import pyvista as pv
from pyvista import examples

data = examples.download_bolt_nut()
bolt = data['bolt'].threshold(1)
nut = data['nut'].threshold(1)

# Original data
p = pv.Plotter()
p.add_mesh(bolt)
p.add_mesh(nut)
p.show(use_panel=False)

download

# Scale and shift the bolt
bolt.points[:,1] *=3
bolt.points[:,1] -= bolt.points[:,1].ptp()/2

#scale and shift the nut
nut.points[:,0] *=3
nut.points[:,0] -= nut.points[:,0].ptp()/2
nut.points[:,2] *=3
nut.points[:,2] -= nut.points[:,2].ptp()/2

p = pv.Plotter()
p.add_mesh(bolt)
p.add_mesh(nut)
p.show(use_panel=False)

download

from pyvista-support.

akaszynski avatar akaszynski commented on July 1, 2024

Would it be possible to implement either a set_scale on the actor or maybe make it a keyword arg for add_mesh?

from pyvista-support.

banesullivan avatar banesullivan commented on July 1, 2024

That could also work... but you might still need to shift the datasets around to make sure they appear next to each other?

from pyvista-support.

akaszynski avatar akaszynski commented on July 1, 2024

Good point. Maybe a scene-wise implementation is best.

from pyvista-support.

banesullivan avatar banesullivan commented on July 1, 2024

Maybe a scene-wise implementation is best.

That's what I went with by implementing set_scale a while back. I very often have to exaggerate the Z axis and found that a scene wide scaling worked best - its quite rare (in my experience) to need individual exaggerations per mesh in a single scene

from pyvista-support.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.