XRSite.interp is to simplistic for circular quantities like Turnings ( -180 <phi < 180 )
When XRSite.interp is called to interpolate Turnings (Line 236) which are further than 180deg apart, the interpolated value will point in the opposite direction, than the expected one.
I believe this issue could be solved either in the interpolation function, in case there are other circular quantities being interpolated in PyWake, or the Turnings can be normalized before and after the interpolation while keeping the same interpolation function.
Please run the code snippet below to recreate this issue.
This example is a simple 2x2 map (x = [0, 500]; y=[0, 500]).
Below are some illustrations of the issue, when one tries to interpolate at the points (x=0; y=250) and (x=0; y=500)
from py_wake.site import XRSite
import xarray as xr
import numpy as np
f = [0.1, 0.5, 0.2, 0.2]
wd = np.array([0, 90, 180, 270])
site = XRSite(ds=xr.Dataset(
data_vars={'Turning': (['x', 'y'], np.array([[170, -40], [170, -100]])),
'P': ('wd', f)},
coords={'x': [0, 500], 'y': [0, 500], 'wd': wd}))
print()
turning_x_500 = site.local_wind(x_i=500, y_i=250, wd=0, ws=10)
print(f"Expected Turning = {-145}deg, at x=500, Computed Turning = {turning_x_500.WD.values.squeeze()[()]}deg")
turning_x_0 = site.local_wind(x_i=0, y_i=250, wd=0, ws=10)
print(f"Expected Turning = {-115}deg, at x=0, Computed Turning = {turning_x_0.WD.values.squeeze()[()]}deg")
Edited by Rene Rauffus