interpolate

function of dascore.proc.resample source

interpolate(
    patch: Patch ,
    kind: str | int[str, int] = linear,
    **kwargs ,
)-> ‘PatchType’

Set coordinates of patch along a dimension using interpolation.

Parameters

Parameter Description
patch The patch object to which interpolation is applied.
kind The type of interpolation. See Notes for more details.
If a string, the following are supported:
linear - linear interpolation between a pair of points.
nearest - use the nearest sample for interpolation.
If an int, it specifies the order of spline to use. EG 1 is a linear
spline, 2 is quadratic, 3 is cubic, etc.
**kwargs Used to specify dimension and interpolation values. Use a value of
None to “snap” coordinate to evenly sampled points along coordinate.
Note

Uses scipy.interpolate.interp1d; see its documentation for interpolation details.

Coordinates measured on the interpolated dimension are interpolated with it where they are numbers, and dropped otherwise: a label has nothing between its values, and a time does not survive the trip through floating point.

See Also

Patch.snap_coords Snap coordinates to evenly sampled values without interpolating data. resample Resample data to a target sampling interval or number of samples.

Examples

import numpy as np
import dascore as dc
patch = dc.get_example_patch()
# up-sample time coordinate
time = patch.coords.get_array('time')
time_step = patch.get_coord("time").step
new_time = np.arange(time.min(), time.max(), 0.5 * time_step)
patch_uptime = patch.interpolate(time=new_time)
# interpolate unevenly sampled dim to evenly sampled
patch = dc.get_example_patch("wacky_dim_coords_patch")
patch_time_even = patch.interpolate(time=None)