Skip to content
Snippets Groups Projects
Commit 34140a0c authored by Mads M. Pedersen's avatar Mads M. Pedersen
Browse files

fix raise issue in xrsite when interpolating P

parent 2b81a9d7
No related branches found
No related tags found
No related merge requests found
......@@ -224,9 +224,14 @@ class XRSite(Site):
lw.set_data_array(TI_std, 'TI_std', 'Standard deviation of turbulence intensity')
if 'P' in self.ds:
if 'ws' in self.ds.P.dims and 'ws' in lw.coords and \
(self.ds.P.ws.shape != lw.coords['ws'].shape or np.any(self.ds.P.ws.values != lw.coords['ws'].values)):
raise ValueError("Cannot interpolate ws-dependent P to other set of ws")
if ('ws' in self.ds.P.dims and 'ws' in lw.coords):
d_ws = self.ds.P.ws.values
c_ws = lw.coords['ws'].values
i = np.searchsorted(d_ws, c_ws[0])
if (np.any([ws not in d_ws for ws in c_ws]) or # check all coordinate ws in data ws
len(d_ws[i:i + len(c_ws)]) != len(c_ws) or # check subset has same length
np.any(d_ws[i:i + len(c_ws)] != c_ws)): # check subset are equal
raise ValueError("Cannot interpolate ws-dependent P to other range of ws")
lw['P'] = self.interp(self.ds.P, lw.coords) / \
self.ds.sector_width * lw.wd_bin_size
else:
......
......@@ -237,8 +237,13 @@ def test_plot_wd_distribution(complex_ws_site):
def test_local_wind_P_diff_ws(complex_ws_site):
with pytest.raises(ValueError, match='Cannot interpolate ws-dependent P to other set of ws'):
complex_ws_site.local_wind([0], [0], 100, wd=np.arange(360), ws=10)
with pytest.raises(ValueError, match='Cannot interpolate ws-dependent P to other range of ws'):
complex_ws_site.local_wind([0], [0], 100, wd=np.arange(360), ws=9)
def test_local_wind_P_same_ws(complex_ws_site):
complex_ws_site.local_wind([0], [0], 100, wd=np.arange(360), ws=10)
complex_ws_site.local_wind([0], [0], 100, wd=np.arange(360), ws=[8, 10])
def test_cyclic_interpolation(uniform_site):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment