Debian Codegraph @

examples/01-filter/interpolate.py

raw
1 """
2 .. _interpolate_example:
3
4 Detailed Interpolating Points
5 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6
7 This example uses :func:`pyvista.DataSetFilters.interpolate`.
8 :func:`pyvista.DataObjectFilters.sample` is similar, and the two
9 methods are compared in :ref:`interpolate_sample_example`.
10
11 Interpolate one mesh's point/cell arrays onto another mesh's nodes using a
12 Gaussian Kernel.
13 """
14
15 # sphinx_gallery_thumbnail_number = 4
16 import pyvista as pv
17 from pyvista import examples
18
19 # %%
20 # Simple Surface Interpolation
21 # ++++++++++++++++++++++++++++
22 # Resample the points' arrays onto a surface
23
24 # Download sample data
25 surface = examples.download_saddle_surface()
26 points = examples.download_sparse_points()
27
28 pl = pv.Plotter()
29 pl.add_mesh(points, scalars='val', point_size=30.0, render_points_as_spheres=True)
30 pl.add_mesh(surface)
31 pl.show()
32
33 # %%
34 # Run the interpolation
35
36 interpolated = surface.interpolate(points, radius=12.0)
37
38
39 pl = pv.Plotter()
40 pl.add_mesh(points, scalars='val', point_size=30.0, render_points_as_spheres=True)
41 pl.add_mesh(interpolated, scalars='val')
42 pl.show()
43
44
45 # %%
46 # Complex Interpolation
47 # +++++++++++++++++++++
48 # In this example, we will in interpolate sparse points in 3D space into a
49 # volume. These data are from temperature probes in the subsurface and the goal
50 # is to create an approximate 3D model of the temperature field in the
51 # subsurface.
52 #
53 # This approach is a great for back-of-the-hand estimations but pales in
54 # comparison to kriging
55
56 # Download the sparse data
57 probes = examples.download_thermal_probes()
58
59 # %%
60 # Create the interpolation grid around the sparse data
61 grid = pv.ImageData()
62 grid.origin = (329700, 4252600, -2700)
63 grid.spacing = (250, 250, 50)
64 grid.dimensions = (60, 75, 100)
65
66 # %%
67 dargs = dict(cmap='coolwarm', clim=[0, 300], scalars='temperature (C)')
68 cpos = pv.CameraPosition(
69 position=(364280.5723737897, 4285326.164400684, 14093.431895014139),
70 focal_point=(337748.7217949739, 4261154.45054595, -637.1092549935128),
71 viewup=(-0.29629216102673206, -0.23840196609932093, 0.9248651025279784),
72 )
73
74 pl = pv.Plotter()
75 pl.add_mesh(grid.outline(), color='k')
76 pl.add_mesh(probes, render_points_as_spheres=True, **dargs)
77 pl.show(cpos=cpos)
78
79
80 # %%
81 # Run an interpolation
82 interp = grid.interpolate(probes, radius=15000, sharpness=10, strategy='mask_points')
83
84 # %%
85 # Visualize the results
86
87 # sphinx_gallery_start_ignore
88 # volume rendering does not work in interactive plots currently
89 PYVISTA_GALLERY_FORCE_STATIC = True
90 # sphinx_gallery_end_ignore
91
92 vol_opac = [0, 0, 0.2, 0.2, 0.5, 0.5]
93
94 pl = pv.Plotter(shape=(1, 2), window_size=[1024 * 3, 768 * 2])
95 pl.add_volume(interp, opacity=vol_opac, **dargs)
96 pl.add_mesh(probes, render_points_as_spheres=True, point_size=10, **dargs)
97 pl.subplot(0, 1)
98 pl.add_mesh(interp.contour(5), opacity=0.5, **dargs)
99 pl.add_mesh(probes, render_points_as_spheres=True, point_size=10, **dargs)
100 pl.link_views()
101 pl.show(cpos=cpos)
102 # %%
103 # .. tags:: filter