pyvista.DataSetFilters.interpolate

pyvista.DataSetFilters.interpolate#

DataSetFilters.interpolate(
target: DataSet | _vtk.vtkDataSet,
sharpness: float = 2.0,
radius: float = 1.0,
strategy: Literal['null_value', 'mask_points', 'closest_point'] = 'null_value',
null_value: float = 0.0,
n_points: int | None = None,
pass_cell_data: bool = True,
pass_point_data: bool = True,
progress_bar: bool = False,
)[source]#

Interpolate values onto this mesh from a given dataset.

The target dataset is typically a point cloud. Only point data from the target mesh will be interpolated onto points of this mesh. Whether preexisting point and cell data of this mesh are preserved in the output can be customized with the pass_point_data and pass_cell_data parameters.

This uses a Gaussian interpolation kernel. Use the sharpness and radius parameters to adjust this kernel. You can also switch this kernel to use an N closest points approach.

If the cell topology is more useful for interpolating, e.g. from a discretized FEM or CFD simulation, use pyvista.DataSetFilters.sample() instead.

Parameters:
targetpyvista.DataSet

The vtk data object to sample from. Point and cell arrays from this object are interpolated onto this mesh.

sharpnessfloat, default: 2.0

Set the sharpness (i.e., falloff) of the Gaussian kernel. As the sharpness increases the effects of distant points are reduced.

radiusfloat, optional

Specify the radius within which the basis points must lie.

strategystr, default: “null_value”

Specify a strategy to use when encountering a “null” point during the interpolation process. Null points occur when the local neighborhood (of nearby points to interpolate from) is empty. If the strategy is set to 'mask_points', then an output array is created that marks points as being valid (=1) or null (invalid =0) (and the NullValue is set as well). If the strategy is set to 'null_value', then the output data value(s) are set to the null_value (specified in the output point data). Finally, the strategy 'closest_point' is to simply use the closest point to perform the interpolation.

null_valuefloat, default: 0.0

Specify the null point value. When a null point is encountered then all components of each null tuple are set to this value.

n_pointsint, optional

If given, specifies the number of the closest points used to form the interpolation basis. This will invalidate the radius argument in favor of an N closest points approach. This typically has poorer results.

pass_cell_databool, default: True

Preserve input mesh’s original cell data arrays.

pass_point_databool, default: True

Preserve input mesh’s original point data arrays.

progress_barbool, default: False

Display a progress bar to indicate progress.

Returns:
pyvista.DataSet

Interpolated dataset. Return type matches input.

Examples

Interpolate the values of 5 points onto a sample plane.

>>> import pyvista as pv
>>> import numpy as np
>>> rng = np.random.default_rng(7)
>>> point_cloud = rng.random((5, 3))
>>> point_cloud[:, 2] = 0
>>> point_cloud -= point_cloud.mean(0)
>>> pdata = pv.PolyData(point_cloud)
>>> pdata['values'] = rng.random(5)
>>> plane = pv.Plane()
>>> plane.clear_data()
>>> plane = plane.interpolate(pdata, sharpness=3)
>>> pl = pv.Plotter()
>>> _ = pl.add_mesh(pdata, render_points_as_spheres=True, point_size=50)
>>> _ = pl.add_mesh(plane, style='wireframe', line_width=5)
>>> pl.show()
../../../_images/pyvista-DataSetFilters-interpolate-1_00_00.png

See Detailed Interpolating Points for more examples using this filter.