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:
Calculate the moments of the Weibull distribution from the A and k parameters.
Spatially interpolate the moments to the output locations.
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.
z0mesois log-transformed before interpolation and transformed back afterward.Warning
This function is experimental and its signature may change.
- Parameters:
gwc (
Dataset) – GWC or GeoWC datasetoutput_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_locsto be apointstructure
engine (
{"windkit"}, optional) – Backend to use for interpolation. Thefortranengine 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_northand the CRS are always taken fromoutput_locs.heighttakes its shape fromoutput_locsbut its values fromgwc.
So
out.west_eastequalsoutput_locs.west_east, butout.heightgenerally does not equaloutput_locs.height. Do not assume that the output coordinates matchoutput_locsuniformly; 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
heightcoordinate 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]returnsheight = [50, 50, 100]. Incuboidandstacked_pointoutputs this makesheighta 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, somethodandfill_valuehave no effect on the values in that case; only the nearest-height mapping above applies. This holds regardless of how faroutput_locslies from the source location, and no distance-based extrapolation limit is applied.Global attributes from
gwc(includingwind_dir_crsand 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
engineis not"windkit".PywaspError – If
gwcis apointstructure 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.