pywasp.wasp.interpolate_gwc#

pywasp.wasp.interpolate_gwc(gwc, /, output_locs, method='nearest', engine='windkit', fill_value=nan)[source]#

Spatially interpolate GWC data to a grid of locations.

The interpolation is done in several steps:
  1. Calculate the moments of the Weibull distribution from the A and k parameters.

  2. Spatially interpolate the moments to the output locations.

  3. Fit new A and k parameters from the interpolated moments.

The first and third moments as well as the frequency of wind speeds greater than the mean are used, corresponding to WASP methodology. For geostrophic wind climates, the geostrophic wind frequency and turning angle and the additional roughness parameters are interpolated directly. z0meso is log-transformed before interpolation and transformed back afterward.

Warning

This function is experimental and its signature may change.

Parameters:
  • gwc (Dataset) – GWC or GeoWC dataset

  • output_locs (Dataset) – WindKit spatial dataset defining the output locations.

  • method (str, optional) – Interpolation method. By default “nearest”. Options are:

    • “nearest” for nearest neighbor interpolation

    • “linear” for bilinear interpolation

    • “cubic” for cubic interpolation

    • “natural” for natural neighbor interpolation; requires output_locs to be a point structure

  • engine ({"windkit"}, optional) – Backend to use for interpolation. The fortran engine has been removed; only "windkit" (the default) is accepted.

  • fill_value ({float, None}, optional) – The value given to points that cannot be interpolated from the points contained in gwc. If None, these points will be filled with nearest neighbor interpolation.

Returns:

Dataset – Interpolated GWC dataset.

Notes

Horizontal and vertical coordinates are treated differently in the output:

  • west_east, south_north and the CRS are always taken from output_locs.

  • height takes its shape from output_locs but its values from gwc.

So out.west_east equals output_locs.west_east, but out.height generally does not equal output_locs.height. Do not assume that the output coordinates match output_locs uniformly; that holds horizontally and not vertically.

Target heights are mapped to the nearest available source heights, and the output retains those source-height values. When a target height is equidistant between two source heights, the lower source height is selected. This mapping also applies when the source and target heights are ordered differently.

Because the output keeps one entry per target height, the returned height coordinate repeats a source height whenever several target heights map to it. For example, interpolating a source with heights [50, 100] to a target with heights [10, 60, 200] returns height = [50, 50, 100]. In cuboid and stacked_point outputs this makes height a non-unique dimension coordinate, so a subsequent .sel(height=...) can return more than one element. Select on the source heights directly, or drop duplicates, if a unique height index is required.

A GWC at a single horizontal location is broadcast to all output locations rather than interpolated, for any method. The source climate is reused unchanged at every output location, so method and fill_value have no effect on the values in that case; only the nearest-height mapping above applies. This holds regardless of how far output_locs lies from the source location, and no distance-based extrapolation limit is applied.

Global attributes from gwc (including wind_dir_crs and custom metadata) are preserved in the output. The output history records the public interpolation call without exposing internal spatial-conversion steps.

Raises:
  • ValueError – If the GWC and output locations have different CRSs, if the GWC contains any of “__m1__”, “__m3__”, “__fgtm__” (these names are reserved for internal use), or if engine is not "windkit".

  • PywaspError – If gwc is a point structure holding several heights at some locations but not the same heights at every location.

Warns:
  • UserWarning – If the GWC is in geographic coordinates and method is “nearest”, “linear”, “cubic”, or “natural”. Interpolation in geographic coordinates can be inaccurate.

  • UserWarning – If the interpolation results in NaN’s. These can be filled with nearest neighbor interpolation by setting fill_value=None.