windkit.spatial.interp_unstructured#

windkit.spatial.interp_unstructured(obj, west_east=None, south_north=None, height=None, method='linear', **kwargs)[source]#

Interpolate spatially from unstructured dataset/dataarray to new coordinates.

Parameters:
  • obj (xarray.Dataset or xarray.DataArray) – Source dataset/dataarray with spatial coordinates. Can be a cuboid, stacked_point or point. Must have the same crs as the west_east, south_north and height coordinates provided.

  • west_east (xarray.DataArray, optional) – Target dataarray with spatial coordinates. Can be in cuboid, stacked_point or point structure

  • south_north (xarray.DataArray, optional) – Target dataarray with spatial coordinates. Can be in cuboid, stacked_point or point structure

  • height (xarray.DataArray, optional) – Target dataarray with spatial coordinates. Can be in cuboid, stacked_point or point structure

  • method (str, optional) – Interpolation method. Must be ‘nearest’, ‘linear’, ‘cubic’, ‘natural’ or ‘rbf’. Default is ‘linear’. The ‘linear’ and ‘cubic’ methods use Delaunay triangulation and return NaN outside the convex hull of the source points, while ‘nearest’ takes the value of the closest source point everywhere. ‘natural’ uses natural neighbor interpolation and requires point structured targets. ‘rbf’ uses radial basis functions, interpolates horizontally only (pass exclude_dims=["height"] or omit height), extrapolates outside the convex hull, and works with as few as two source points when kernel="linear" is passed.

  • **kwargs (dict) – Keyword arguments passed to the interpolation function. For ‘nearest’, ‘linear’ and ‘cubic’ these are forwarded to the matching scipy.interpolate interpolator, e.g. fill_value for ‘linear’ and ‘cubic’. ‘natural’ takes none. For ‘rbf’ these are forwarded to scipy.interpolate.RBFInterpolator: kernel (default ‘thin_plate_spline’), neighbors, smoothing, epsilon and degree. Note that the default global fit solves a dense linear system whose cost grows with the cube of the number of source points; pass neighbors to fit locally for large sources.

Returns:

Interpolated dataset/dataarray with spatial coordinates provided.

Return type:

xarray.Dataset or xarray.DataArray

Raises:
  • ValueError – If obj is not an xarray.Dataset or xarray.DataArray

  • ValueError – If method is not one of the supported methods

  • ValueError – If keyword arguments are passed with method ‘natural’

  • ValueError – If any of the coordinates in coords_kwargs are not xarray.DataArray

  • ValueError – If any of the coordinates in coords_kwargs are not in obj

Warning

If any of the variables in obj are not numeric, they will be skipped and a warning will be raised.