Resampling & Interpolating

Resample one mesh’s point/cell arrays onto another meshes nodes.

This example will resample a volumetric mesh’s scalar data onto the surface of a sphere contained in that volume.

# sphinx_gallery_thumbnail_number = 4
import pyvista as pv
from pyvista import examples
import numpy as np

Query a grids points onto a sphere

mesh = pv.Sphere(center=(4.5, 4.5, 4.5), radius=4.5)
data_to_probe = examples.load_uniform()

Plot the two datasets

p = pv.Plotter()
p.add_mesh(mesh, color=True)
p.add_mesh(data_to_probe, opacity=0.5)
p.show()
../../_images/sphx_glr_resample_001.png

Out:

[(21.886664873203234, 21.886664873203234, 21.886664873203234), (4.5, 4.5, 4.5), (0.0, 0.0, 1.0)]

Run the algorithm and plot the result

result = mesh.sample(data_to_probe)

# Plot result
name = "Spatial Point Data"
result.plot(scalars=name, clim=data_to_probe.get_data_range(name))
../../_images/sphx_glr_resample_002.png

Out:

[(21.83804075669771, 21.83804051827913, 21.83804075669771), (4.5, 4.499999761581421, 4.5), (0.0, 0.0, 1.0)]

Interpolate

Resample the points’ arrays onto a surface using an interpolation from a Gaussian Kernel

# Download sample data
surface = examples.download_saddle_surface()
points = examples.download_sparse_points()


p = pv.Plotter()
p.add_mesh(points, point_size=30.0, render_points_as_spheres=True)
p.add_mesh(surface)
p.show()
../../_images/sphx_glr_resample_003.png

Out:

[(66.17150713734922, 85.97370065980253, 73.43684689932165), (-0.006363868713378906, 19.79582965373993, 7.2589758932590485), (0.0, 0.0, 1.0)]

Run the interpolation

interpolated = surface.interpolate(points, radius=12.0)


p = pv.Plotter()
p.add_mesh(points, point_size=30.0, render_points_as_spheres=True)
p.add_mesh(interpolated, scalars="val")
p.show()
../../_images/sphx_glr_resample_004.png

Out:

[(66.17150713734922, 85.97370065980253, 73.43684689932165), (-0.006363868713378906, 19.79582965373993, 7.2589758932590485), (0.0, 0.0, 1.0)]

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

Gallery generated by Sphinx-Gallery