def test_time_series_values(): wt = V80() site = Hornsrev1Site() x, y = site.initial_position.T wfm = NOJ(site, wt) wd = np.arange(350, 360) ws = np.arange(5, 10) wd_t, ws_t = [v.flatten() for v in np.meshgrid(wd, ws)] sim_res_t = wfm(x, y, ws=ws_t, wd=wd_t, time=True, verbose=False) sim_res = wfm(x, y, wd=wd, ws=ws) for k in ['WS_eff', 'TI_eff', 'Power', 'CT']: npt.assert_array_equal( np.moveaxis(sim_res_t[k].values.reshape((80, 5, 10)), 1, 2), sim_res[k].values)
def test_double_wind_farm_model_All2AllIterative(): """Check that a new wind farm model does not change results of previous""" site = IEA37Site(64) x, y = site.initial_position.T x, y = wt_x, wt_y windTurbines = IEA37_WindTurbines() wfm = All2AllIterative( site, windTurbines, wake_deficitModel=IEA37SimpleBastankhahGaussianDeficit()) aep_ref = wfm(x, y).aep().sum() All2AllIterative(site, windTurbines, wake_deficitModel=NoWakeDeficit())(x, y) aep = wfm(x, y).aep().sum() npt.assert_array_equal(aep, aep_ref)
def test_i_dependent_WS(): ds = xr.Dataset( data_vars={'WS': ('i', [8, 9, 10]), 'P': ('wd', f)}, coords={'wd': np.linspace(0, 360, len(f), endpoint=False)}) site = XRSite(ds) lw = site.local_wind([0, 200, 400], [0, 0, 0], [70, 70, 70], wd=0, ws=10) npt.assert_array_equal(lw.WS, [8, 9, 10]) WS = np.arange(6).reshape(3, 2) + 9 ds = xr.Dataset( data_vars={'WS': (('i', 'ws'), WS), 'Sector_frequency': ('wd', f), 'Weibull_A': ('wd', A), 'Weibull_k': ('wd', k)}, coords={'wd': np.linspace(0, 360, len(f), endpoint=False), 'ws': [9, 10], 'i': [0, 1, 2]}) site = XRSite(ds) lw = site.local_wind([0, 200, 400], [0, 0, 0], [70, 70, 70], wd=0, ws=10) npt.assert_array_equal(lw.WS.squeeze(), [10, 12, 14])
def test_vector2vector_dependent(): def f(x): return x**2 + x[::-1] def df(x): return np.diag(2 * x) + np.diag(np.ones(3))[::-1] x = np.array([2., 3, 4]) ref = [[4., 0., 1.], [0., 7., 0.], [1., 0., 8.]] npt.assert_array_almost_equal(fd(f, True)(x), ref, 5) npt.assert_array_almost_equal_nulp(cs(f, True)(x), ref) npt.assert_array_equal(autograd(f, True)(x), ref) pf = primitive(f) defvjp(pf, lambda ans, x: lambda g: np.dot(g, df(x))) npt.assert_array_equal(autograd(pf, True)(x), ref)
def test_distance2_outside_map_NorthSouth(): site = ParqueFicticioSiteTerrainFollowingDistance2() y = np.arange(-1500, 1000, 500) + 6506613.0 h = y * 0 x = h + 264200 site.distance.setup(src_x_i=x, src_y_i=y, src_h_i=h, dst_xyh_j=(x, y, h * 0)) dw = site.distance(wd_il=[180])[0] if 0: site.ds.Elevation.plot() plt.plot(x, y, '.-', label='Terrain line') plt.plot(x + site.elevation(x, y), y) plt.legend() plt.show() # distance between points should be >500 m due to terrain, except last point which is outside map npt.assert_array_equal(np.round(np.diff(dw[0, :, 0])), [510, 505, 507, 500])
def test_distance2_outside_map_WestEast(): site = ParqueFicticioSiteTerrainFollowingDistance2() site.plot_map('elev') x = np.arange(-1500, 1000, 500) + 264777 h = x * 0 y = h + 6505450 dw = site.distances(src_x_i=x, src_y_i=y, src_h_i=h, dst_x_j=x, dst_y_j=y, dst_h_j=h * 0, wd_il=[270])[0] if 0: plt.plot(x, y, '.-', label='Terrain line') plt.plot(x, y + site.elevation(x, y)) plt.legend() plt.show() # distance between points should be >500 m due to terrain, except last point which is outside map npt.assert_array_equal(np.round(np.diff(dw[0, :, 0])), [527, 520, 505, 500.])
def test_PowerCtXr(): u_p, p_c, ct_c = v80_upct.copy() ds = xr.Dataset(data_vars={ 'ct': (['ws', 'boost'], np.array([ct_c, ct_c]).T), 'power': (['ws', 'boost'], np.array([p_c, p_c * 2]).T) }, coords={ 'boost': [0, 1], 'ws': u_p, }).transpose('boost', 'ws') curve = PowerCtXr(ds, 'w') u = np.linspace(3, 25, 10) wfm = get_wfm(curve) ri, oi = wfm.windTurbines.function_inputs npt.assert_array_equal(ri, ['boost']) npt.assert_array_equal(oi, ['Air_density', 'tilt', 'yaw']) sim_res = wfm([0], [0], wd=0, ws=u, boost=0) p = sim_res.Power.values ct = sim_res.CT.values npt.assert_array_almost_equal_nulp(p, np.interp(u, u_p, p_c)) npt.assert_array_almost_equal_nulp(ct, np.interp(u, u_p, ct_c)) sim_res = wfm([0], [0], wd=0, ws=u, boost=.5) p = sim_res.Power.values ct = sim_res.CT.values npt.assert_array_almost_equal_nulp(p[0, 0], np.interp(u, u_p, p_c * 1.5)) npt.assert_array_almost_equal_nulp(ct, np.interp(u, u_p, ct_c)) boost_16 = (np.arange(16) > 7) * .1 boost_16_360 = np.broadcast_to(boost_16[:, na], (16, 360)) boost_16_360_23 = np.broadcast_to(boost_16[:, na, na], (16, 360, 23)) ref_p = np.array( np.broadcast_to(hornsrev1.power_curve[:, 1][na, na], (16, 360, 23))) ref_p[8:] *= 1.1 wfm = get_wfm(curve) for b in [boost_16, boost_16_360, boost_16_360_23]: sim_res = wfm(np.arange(16) * 1e3, [0] * 16, wd=np.arange(360) % 5, boost=b) # no wake effects p = sim_res.Power.values npt.assert_array_almost_equal(p, ref_p)
def test_missing_input_PowerCtFunctionList(): u_p, p, ct = v80_upct.copy() curve = PowerCtFunctionList('mode', [ PowerCtTabular(ws=u_p, power=p + 1, power_unit='w', ct=ct), PowerCtTabular(ws=u_p, power=p + 2, power_unit='w', ct=ct), PowerCtTabular(ws=u_p, power=p + 3, power_unit='w', ct=ct) ]) wfm = get_wfm(curve) ri, oi = wfm.windTurbines.function_inputs npt.assert_array_equal(ri, ['mode']) npt.assert_array_equal(oi, ['Air_density', 'tilt', 'yaw']) with pytest.raises( KeyError, match="Argument, mode, required to calculate power and ct not found" ): wfm([0], [0])
def test_complex_fixed_pos_local_wind(complex_fixed_pos_site): site = complex_fixed_pos_site x_i, y_i = site.initial_position.T npt.assert_array_equal(x_i, np.arange(5)) npt.assert_array_equal(y_i, np.arange(5) + 1) wdir_lst = np.arange(0, 360, 90) wsp_lst = np.arange(3, 6) lw = site.local_wind(x_i=x_i, y_i=y_i, h_i=100, wd=wdir_lst, ws=wsp_lst) npt.assert_array_equal(lw.WS, [3, 4, 5] * np.arange(.8, 1.3, .1)[:, na]) npt.assert_array_equal(lw.WD, (wdir_lst + np.arange(-2, 3)[:, na]) % 360) npt.assert_array_equal(lw.TI, 0.1) npt.assert_array_almost_equal(lw.P, [[0.00553222, 0.00770323, 0.00953559], [0.0078508, 0.01177761, 0.01557493], [0.0105829, 0.01576518, 0.02066746], [0.01079997, 0.01656828, 0.02257487]])
def test_twotype_windturbines(): v80 = V80() v88 = WindTurbine('V88', 88, 77, powerCtFunction=PowerCtTabular( hornsrev1.power_curve[:, 0], hornsrev1.power_curve[:, 1] * 1.1, 'w', hornsrev1.ct_curve[:, 1])) wts = WindTurbines.from_WindTurbines([v80, v88]) types0 = [0] * 9 types1 = [0, 0, 0, 1, 1, 1, 0, 0, 0] types2 = [1] * 9 for wfm in get_wfms(wts): npt.assert_array_equal(wts.types(), [0, 1]) npt.assert_almost_equal(wfm.aep(wt9_x, wt9_y, type=types0), 81.2066072392765) npt.assert_almost_equal(wfm.aep(wt9_x, wt9_y, type=types1), 83.72420504573488) npt.assert_almost_equal(wfm.aep(wt9_x, wt9_y, type=types2), 88.87227386796884)
def test_MultiMultiPowerCtCurve_subset(): u_p, p, ct = v80_upct.copy() curves = PowerCtFunctionList('mytype', [ PowerCtFunctionList('mode', [ PowerCtTabular(ws=u_p, power=p + 1, power_unit='w', ct=ct), PowerCtTabular(ws=u_p, power=p + 2, power_unit='w', ct=ct), PowerCtTabular(ws=u_p, power=p + 3, power_unit='w', ct=ct) ]), PowerCtFunctionList('mode', [ PowerCtTabular(ws=u_p, power=p + 4, power_unit='w', ct=ct), PowerCtTabular(ws=u_p, power=p + 5, power_unit='w', ct=ct), PowerCtTabular(ws=u_p, power=p + 6, power_unit='w', ct=ct) ]), ]) wfm = get_wfm(curves) ri, oi = wfm.windTurbines.function_inputs npt.assert_array_equal(ri, ['mode', 'mytype']) npt.assert_array_equal(oi, ['Air_density', 'tilt', 'yaw']) u = np.zeros((2, 3, 4)) + np.arange(3, 7)[na, na, :] type_2 = np.array([0, 1]) type_2_3 = np.broadcast_to(type_2[:, na], (2, 3)) type_2_3_4 = np.broadcast_to(type_2[:, na, na], (2, 3, 4)) mode_2_3 = np.broadcast_to(np.array([0, 1, 2])[na, :], (2, 3)) mode_2_3_4 = np.broadcast_to(mode_2_3[:, :, na], (2, 3, 4)) ref_p = np.array( np.broadcast_to(hornsrev1.power_curve[:4, 1][na, na], (2, 3, 4))) ref_p[0, :] += np.array([1, 2, 3])[:, na] ref_p[1, :] += np.array([4, 5, 6])[:, na] for t in [type_2, type_2_3, type_2_3_4]: for m in [mode_2_3, mode_2_3_4]: sim_res = wfm([0, 1000], [0, 0], wd=np.arange(3), ws=np.arange(3, 7), mode=m, mytype=t) # no wake effects p = sim_res.Power.values npt.assert_array_almost_equal(p, ref_p)
def test_flat_distances_wt2wt(distance): x = [0, 50, 100] y = [100, 100, 0] h = [0, 10, 20] wdirs = [0, 30] dw_ijl, hcw_ijl, dh_ijl, dw_indices_l = distance(FlatSite(), src_x_i=x, src_y_i=y, src_h_i=h, dst_x_j=x, dst_y_j=y, dst_h_j=[1, 2, 3], wd_il=np.array(wdirs)[na]) if 0: distance.plot(src_x_i=x, src_y_i=y, src_h_i=h, dst_x_j=x, dst_y_j=y, dst_h_j=[1, 2, 3], wd_ijl=np.array(wdirs)[na, na]) # check down wind distance wind from North and 30 deg npt.assert_array_almost_equal(dw_ijl[:, :, 0], [[0, 0, 100], [0, 0, 100], [-100, -100, 0]]) npt.assert_array_almost_equal(dw_ijl[:, :, 1], [[0, -25, 36.60254038], [25, 0, 61.60254038], [-36.60254038, -61.60254038, 0]]) # check cross wind distance wind from North and 30 deg npt.assert_array_almost_equal(hcw_ijl[:, :, 0], [[0, 50, 100], [-50, 0, 50], [-100, -50, 0]]) npt.assert_array_almost_equal( hcw_ijl[:, :, 1], [[0, 43.30127019, 136.60254038], [-43.30127019, 0., 93.30127019], [-136.60254038, -93.30127019, 0.]]) # check cross wind distance wind from North npt.assert_array_almost_equal(dh_ijl[:, :, 0], [[1, 2, 3], [-9, -8, -7], [-19, -18, -17]]) # check dw indices npt.assert_array_equal(dw_indices_l, [[1, 0, 2], [1, 0, 2]])
def test_2d_tabular(): u_p, p_c = np.asarray(hornsrev1.power_curve).T.copy() ct_c = hornsrev1.ct_curve[:, 1] curve = PowerCtNDTabular(['ws', 'boost'], [u_p, [0, 1]], np.array([p_c, 2 * p_c]).T, 'w', np.array([ct_c, ct_c]).T) npt.assert_array_equal( sorted(curve.optional_inputs)[::-1], ['yaw', 'tilt', 'Air_density']) npt.assert_array_equal(sorted(curve.required_inputs)[::-1], ['boost']) u = np.linspace(3, 25, 10) p, ct = curve(ws=u, boost=0) npt.assert_array_almost_equal_nulp(p, np.interp(u, u_p, p_c)) npt.assert_array_almost_equal_nulp(ct, np.interp(u, u_p, ct_c)) # check out of bounds with pytest.raises( ValueError, match='Input, boost, with value, 2.0 outside range 0-1'): curve(ws=u, boost=2) # no default value > KeyError with pytest.raises(KeyError, match="boost"): curve(ws=u) p, ct = curve(ws=u, boost=.5) npt.assert_array_almost_equal_nulp(p, np.interp(u, u_p, p_c * 1.5)) npt.assert_array_almost_equal_nulp(ct, np.interp(u, u_p, ct_c)) # subset u = np.zeros((16, 360, 23)) + np.arange(3, 26)[na, na, :] boost_16 = (np.arange(16) > 7) * .1 boost_16_360 = np.broadcast_to(boost_16[:, na], (16, 360)) boost_16_360_23 = np.broadcast_to(boost_16[:, na, na], (16, 360, 23)) ref_p = np.array( np.broadcast_to(hornsrev1.power_curve[:, 1][na, na], (16, 360, 23))) ref_p[8:] *= 1.1 for b in [boost_16, boost_16_360, boost_16_360_23]: p, ct = curve(u, boost=b) npt.assert_array_almost_equal(p, ref_p)
def test_Mirror_flow_map(wfm_cls, groundModel, superpositionModel): site = UniformSite([1], ti=0.1) wt = V80() wfm = NOJ(site, wt, k=.5, superpositionModel=superpositionModel) fm_ref = wfm([0, 0 + 1e-20], [0, 0 + 1e-20], wd=0, h=[50, -50] ).flow_map(YZGrid(x=0, y=np.arange(-100, 100, 1) + .1, z=np.arange(1, 100))) fm_ref.plot_wake_map() plt.title("Underground WT added manually") plt.figure() wfm = wfm_cls(site, wt, NOJDeficit(k=.5), groundModel=groundModel, superpositionModel=superpositionModel) fm_res = wfm([0], [0], wd=0, h=[50]).flow_map(YZGrid(x=0, y=np.arange(-100, 100, 1) + .1, z=np.arange(1, 100))) fm_res.plot_wake_map() plt.title("With Mirror GroundModel") if 0: plt.show() plt.close('all') npt.assert_array_equal(fm_ref.WS_eff, fm_res.WS_eff)
def test_superposition_model_indices(): class WTSite(UniformSite): def local_wind(self, x_i=None, y_i=None, h_i=None, wd=None, ws=None, time=False, wd_bin_size=None, ws_bins=None): lw = UniformSite.local_wind(self, x_i=x_i, y_i=y_i, h_i=h_i, wd=wd, ws=ws, wd_bin_size=wd_bin_size, ws_bins=ws_bins) lw['TI'] = xr.DataArray(lw.TI_ilk + np.arange(len(x_i))[:, np.newaxis, np.newaxis] * .1, [('wt', [0, 1, 2]), ('wd', np.atleast_1d(wd)), ('ws', np.atleast_1d(ws))]) return lw site = WTSite([1], 0.1) x_i = [0, 0, 0] y_i = [0, -40, -100] h_i = [50, 50, 50] # WS_ilk different at each wt position TI_ilk = site.local_wind(x_i, y_i, h_i, wd=0, ws=8.1).TI_ilk npt.assert_array_almost_equal(TI_ilk, np.reshape([0.1, 0.2, 0.3], (3, 1, 1)), 10) def get_wf_model(cls): return cls(site, NibeA0, wake_deficitModel=NoWakeDeficit(), superpositionModel=LinearSum(), turbulenceModel=STF2017TurbulenceModel()) for wake_model in [get_wf_model(PropagateDownwind), get_wf_model(All2AllIterative)]: # No wake (ct = 0), i.e. WS_eff == WS TI_eff_ilk = wake_model.calc_wt_interaction(x_i, y_i, h_i, [1, 1, 1], 0.0, 8.1)[1] npt.assert_array_equal(TI_eff_ilk, TI_ilk) # full wake (CT=8/9) ref_TI_eff_ilk = TI_ilk + np.reshape([0, 0.33738364, np.sum([0.19369135, 0.21239116])], (3, 1, 1)) TI_eff_ilk = wake_model.calc_wt_interaction(x_i, y_i, h_i, [0, 0, 0], 0.0, 8.1)[1] npt.assert_array_almost_equal(TI_eff_ilk, ref_TI_eff_ilk) sim_res = wake_model(x_i, y_i, h_i, [0, 0, 0], 0.0, 8.1) TI_eff_ilk = sim_res.flow_map(HorizontalGrid(x=[0], y=y_i, h=50)).TI_eff_xylk[:, 0] npt.assert_array_almost_equal(TI_eff_ilk, ref_TI_eff_ilk)
def test_scalar2multi_scalar(): def fxy(x): return x**2 + 1, 2 * x + 1 def f(x): fx, fy = fxy(x) return fx + fy x = 3. ref = 8 npt.assert_equal(cs(f)(x), ref) npt.assert_almost_equal(fd(f)(x), ref, 5) npt.assert_equal(autograd(f)(x), ref) pf = primitive(f) defvjp(pf, lambda ans, x: lambda g: g * (2 * x + 2)) npt.assert_array_equal(autograd(pf, False)(x), ref) pf = primitive(fxy) defvjp(pf, lambda ans, x: lambda g: (g[0] * 2 * x, g[1] * 2)) npt.assert_array_equal(autograd(f, False)(x), ref)
def test_get_defaults(): v80 = V80() npt.assert_array_equal(np.array(v80.get_defaults(1))[:, 0], [0, 70, 80]) npt.assert_array_equal( np.array(v80.get_defaults(1, h_i=100))[:, 0], [0, 100, 80]) npt.assert_array_equal( np.array(v80.get_defaults(1, d_i=100))[:, 0], [0, 70, 100])
def test_TabularPowerCtCurve(method, unit, p_scale, p_ref, ct_ref): u_p, p = np.asarray(hornsrev1.power_curve).T.copy() p *= p_scale u_ct, ct = hornsrev1.ct_curve.T npt.assert_array_equal(u_p, u_ct) curve = PowerCtTabular(ws=u_p, power=p, power_unit=unit, ct=ct, ws_cutin=4, ws_cutout=25, method=method) npt.assert_array_equal(curve.optional_inputs, ['Air_density', 'tilt', 'yaw']) npt.assert_array_equal(curve.required_inputs, []) u = np.arange(0, 30, .1) p, ct = curve(u) s = slice(5, None, 30) if 0: plt.plot(u, p) plt.plot(u[s], p[s], '.') ax2 = plt.gca().twinx() ax2.plot(u, ct) ax2.plot(u[s], ct[s], '.') print(np.round(p[s], 3).tolist()) print(np.round(ct[s], 3).tolist()) plt.show() npt.assert_array_almost_equal(p[s], p_ref, 3) npt.assert_array_almost_equal(ct[s], ct_ref, 3) p, ct = curve(u, run_only=0), curve(u, run_only=1) npt.assert_array_almost_equal(p[s], p_ref, 3) npt.assert_array_almost_equal(ct[s], ct_ref, 3)
def test_MultiMultiPowerCtCurve_subset(): u_p, p = np.asarray(hornsrev1.power_curve).T.copy() ct = hornsrev1.ct_curve[:, 1] curve = PowerCtFunctionList('type', [ PowerCtFunctionList('mode', [ PowerCtTabular(ws=u_p, power=p + 1, power_unit='w', ct=ct), PowerCtTabular(ws=u_p, power=p + 2, power_unit='w', ct=ct), PowerCtTabular(ws=u_p, power=p + 3, power_unit='w', ct=ct) ]), PowerCtFunctionList('mode', [ PowerCtTabular(ws=u_p, power=p + 4, power_unit='w', ct=ct), PowerCtTabular(ws=u_p, power=p + 5, power_unit='w', ct=ct), PowerCtTabular(ws=u_p, power=p + 6, power_unit='w', ct=ct) ]), ]) npt.assert_array_equal( sorted(curve.optional_inputs)[::-1], ['yaw', 'tilt', 'Air_density']) npt.assert_array_equal( sorted(curve.required_inputs)[::-1], ['type', 'mode']) u = np.zeros((2, 3, 4)) + np.arange(3, 7)[na, na, :] type_2 = np.array([0, 1]) type_2_3 = np.broadcast_to(type_2[:, na], (2, 3)) type_2_3_4 = np.broadcast_to(type_2[:, na, na], (2, 3, 4)) mode_2_3 = np.broadcast_to(np.array([0, 1, 2])[na, :], (2, 3)) mode_2_3_4 = np.broadcast_to(mode_2_3[:, :, na], (2, 3, 4)) ref_p = np.array( np.broadcast_to(hornsrev1.power_curve[:4, 1][na, na], (2, 3, 4))) ref_p[0, :] += np.array([1, 2, 3])[:, na] ref_p[1, :] += np.array([4, 5, 6])[:, na] for t in [type_2, type_2_3, type_2_3_4]: for m in [mode_2_3, mode_2_3_4]: p, ct = curve(u, mode=m, type=t) npt.assert_array_almost_equal(p, ref_p)
def test_time_series_override_TI(): d = np.load(os.path.dirname(examples.__file__) + "/data/time_series.npz") wd, ws, ws_std = [d[k][:6 * 24] for k in ['wd', 'ws', 'ws_std']] ti = np.minimum(ws_std / ws, .5) t = pd.date_range("2000-01-01", freq="10T", periods=24 * 6) wt = V80() site = Hornsrev1Site() x, y = site.initial_position.T wfm = NOJ(site, wt) sim_res = wfm(x, y, ws=ws, wd=wd, time=t, TI=ti, verbose=False) npt.assert_array_equal(sim_res.WS, ws) npt.assert_array_equal(sim_res.WD, wd) npt.assert_array_equal(sim_res.time, t) npt.assert_array_equal(sim_res.TI[0], ti)
def test_interp_special_cases(): wd = np.arange(5) ws = np.arange(10) ds = xr.Dataset({ 'TI': (['i', 'wd', 'ws'], np.random.rand(10, len(wd), len(ws))), 'P': 1 }, coords={'i': np.arange(10), 'wd': wd, 'ws': ws} ) site = XRSite(ds) with pytest.raises(ValueError, match=r"Number of points, i\(=10\), in site data variable, TI, must match "): lw = LocalWind(x_i=[25, 50], y_i=[225, 250], h_i=110, wd=wd, ws=ws, wd_bin_size=1) site.interp(site.ds.TI, lw.coords) x = y = np.arange(10) lw = LocalWind(x_i=x, y_i=y, h_i=110, wd=wd, ws=ws, wd_bin_size=1) ip1 = site.interp(site.ds.TI, lw.coords) ip2 = ds.TI.sel_interp_all(lw.coords) npt.assert_array_equal(ip1.shape, ip2.shape) npt.assert_array_almost_equal(ip1.data, ip2.data)
def _test_wts_wtg(wts_wtg): assert(wts_wtg.name(types=0) == 'Vestas V80 (2MW, Offshore)') assert(wts_wtg.diameter(types=0) == 80) assert(wts_wtg.hub_height(types=0) == 67) npt.assert_array_equal(wts_wtg.power(np.array([0, 3, 5, 9, 18, 26]), type_i=0), np.array([0, 0, 154000, 996000, 2000000, 0])) npt.assert_array_equal(wts_wtg.ct(np.array([1, 4, 7, 9, 17, 27]), type_i=0), np.array([0.052, 0.818, 0.805, 0.807, 0.167, 0.052])) assert(wts_wtg.name(types=1) == 'NEG-Micon 2750/92 (2750 kW)') assert(wts_wtg.diameter(types=1) == 92) assert(wts_wtg.hub_height(types=1) == 70) npt.assert_array_equal(wts_wtg.power(np.array([0, 3, 5, 9, 18, 26]), type_i=1), np.array([0, 0, 185000, 1326000, 2748000, 0])) npt.assert_array_equal(wts_wtg.ct(np.array([1, 4, 7, 9, 17, 27]), type_i=1), np.array([.059, 0.871, 0.841, 0.797, 0.175, 0.059]))
def test_MultiPowerCtCurve(): u_p, p, ct = v80_upct.copy() curve = PowerCtFunctionList('mode', [ PowerCtTabular(ws=u_p, power=p, power_unit='w', ct=ct), PowerCtTabular(ws=u_p, power=p * 1.1, power_unit='w', ct=ct + .1) ]) u = np.arange(0, 30, .1) wfm = get_wfm(curve) ri, oi = wfm.windTurbines.function_inputs npt.assert_array_equal(ri, ['mode']) npt.assert_array_equal(oi, ['Air_density', 'tilt', 'yaw']) sim_res = wfm([0], [0], ws=u, wd=0, mode=0) p0, ct0 = sim_res.Power.squeeze().values, sim_res.CT.squeeze().values, sim_res = wfm([0], [0], ws=u, wd=0, mode=1) p1, ct1 = sim_res.Power.squeeze().values, sim_res.CT.squeeze().values, npt.assert_array_almost_equal(p0, p1 / 1.1) npt.assert_array_almost_equal(ct0, ct1 - .1) mode_16 = (np.arange(16) > 7) mode_16_360 = np.broadcast_to(mode_16[:, na], (16, 360)) mode_16_360_23 = np.broadcast_to(mode_16[:, na, na], (16, 360, 23)) ref_p = np.array( np.broadcast_to(hornsrev1.power_curve[:, 1][na, na], (16, 360, 23))) ref_p[8:] *= 1.1 for m in [mode_16, mode_16_360, mode_16_360_23]: sim_res = wfm(np.arange(16) * 1e3, [0] * 16, wd=np.arange(360) % 5, mode=m) # no wake effects p = sim_res.Power.values npt.assert_array_almost_equal(p, ref_p)
def test_local_wind(site): x_i = y_i = np.arange(5) wdir_lst = np.arange(0, 360, 90) wsp_lst = np.arange(3, 6) lw = site.local_wind(x_i=x_i, y_i=y_i, h_i=50, wd=wdir_lst, ws=wsp_lst) npt.assert_array_equal(lw.WS_ilk.shape, (1, 4, 3)) lw = site.local_wind(x_i=x_i, y_i=y_i, h_i=50) npt.assert_array_equal(lw.WS_ilk.shape, (1, 360, 23)) # check probability local_wind()[-1] npt.assert_equal( site.local_wind(x_i=x_i, y_i=y_i, h_i=50, wd=[0], ws=[10], wd_bin_size=1).P_ilk, site.local_wind( x_i=x_i, y_i=y_i, h_i=50, wd=[0], ws=[10], wd_bin_size=2).P_ilk / 2) npt.assert_almost_equal( site.local_wind(x_i=x_i, y_i=y_i, h_i=50, wd=[0], ws=[9, 10, 11]).P_ilk.sum((1, 2)), site.local_wind(x_i=x_i, y_i=y_i, h_i=50, wd=[0], ws=[10], ws_bins=3).P_ilk[:, 0, 0], 5) z = np.arange(1, 100) zero = [0] * len(z) ws = site.local_wind(x_i=zero, y_i=zero, h_i=z, wd=[0], ws=[10]).WS_ilk[:, 0, 0] site2 = UniformWeibullSite(f, A, k, ti, shear=PowerShear(70, alpha=np.zeros_like(f) + .3)) ws70 = site2.local_wind(x_i=zero, y_i=zero, h_i=z, wd=[0], ws=[10]).WS_ilk[:, 0, 0] if 0: plt.plot(ws, z) plt.plot(ws70, z) plt.show() npt.assert_array_equal(10 * (z / 50)**.3, ws) npt.assert_array_equal(10 * (z / 70)**.3, ws70)
def test_wasp_wtg(wts_wtg): wts_wtg = wts_wtg() assert(wts_wtg.name(type=0) == 'Vestas V80 (2MW, Offshore)') assert(wts_wtg.diameter(type=0) == 80) assert(wts_wtg.hub_height(type=0) == 67) npt.assert_array_equal(wts_wtg.power(np.array([0, 3, 3.99, 4, 5, 9, 18, 25, 25.01, 100]), type=0), np.array([0, 0, 0, 66600, 154000, 996000, 2e6, 2e6, 0, 0])) npt.assert_array_equal(wts_wtg.ct(np.array([1, 3.99, 4, 7, 9, 17, 25, 25.01, 100]), type=0), np.array([0.052, 0.052, 0.818, 0.805, 0.807, 0.167, 0.052, 0.052, 0.052])) assert(wts_wtg.name(type=1) == 'NEG-Micon 2750/92 (2750 kW)') assert(wts_wtg.diameter(type=1) == 92) assert(wts_wtg.hub_height(type=1) == 70) npt.assert_array_equal(wts_wtg.power(np.array([0, 3, 3.99, 4, 5, 9, 18, 25, 25.01, 100]), type=1), np.array([0, 0, 0, 55000, 185000, 1326000, 2748000, 2750000, 0, 0])) npt.assert_array_equal(wts_wtg.ct(np.array([1, 3.99, 4, 7, 9, 17, 100]), type=1), np.array([.059, .059, 0.871, 0.841, 0.797, 0.175, 0.059]))
def test_flat_distances_src_neq_dst(distance): x = [0, 50, 100] y = [100, 100, 0] h = [0, 10, 20] wdirs = [0, 30] site = FlatSite(distance=distance) site.distance.setup(src_x_i=x, src_y_i=y, src_h_i=h, dst_xyh_j=(x, y, [1, 2, 3])) dw_ijl, hcw_ijl, dh_ijl = site.distance(wd_il=np.array(wdirs)[na]) dw_indices_l = distance.dw_order_indices(wdirs) if 0: distance.plot(wd_il=np.array(wdirs)[na]) plt.show() # check down wind distance wind from North and 30 deg npt.assert_array_almost_equal(dw_ijl[:, :, 0], [[0, 0, 100], [0, 0, 100], [-100, -100, 0]]) npt.assert_array_almost_equal(dw_ijl[:, :, 1], [[0, -25, 36.60254038], [25, 0, 61.60254038], [-36.60254038, -61.60254038, 0]]) # check cross wind distance wind from North and 30 deg npt.assert_array_almost_equal(hcw_ijl[:, :, 0], [[0, 50, 100], [-50, 0, 50], [-100, -50, 0]]) npt.assert_array_almost_equal(hcw_ijl[:, :, 1], [[0, 43.30127019, 136.60254038], [-43.30127019, 0., 93.30127019], [-136.60254038, -93.30127019, 0.]]) # check cross wind distance wind from North npt.assert_array_almost_equal(dh_ijl[:, :, 0], [[1, 2, 3], [-9, -8, -7], [-19, -18, -17]]) # check dw indices npt.assert_array_equal(dw_indices_l, [[1, 0, 2], [1, 0, 2]])
def test_interp(h, wd, ws, h_i, wd_l, ws_k): ds = xr.Dataset({ 'TI': 1, 'P': 1, 'XYHLK': (['x', 'y', 'h', 'wd', 'ws'], np.random.rand(10, 20, len(h), len(wd), len(ws))), 'XYHL': (['x', 'y', 'h', 'wd'], np.random.rand(10, 20, len(h), len(wd))), 'XYHK': (['x', 'y', 'h', 'ws'], np.random.rand(10, 20, len(h), len(ws))), 'K': (['ws'], np.random.rand(len(ws))), 'L': (['wd'], np.random.rand(len(wd))), 'KL': (['wd', 'ws'], np.random.rand(len(wd), len(ws))), 'XY': (['x', 'y'], np.random.rand(10, 20)), 'H': (['h'], np.random.rand(len(h))), 'XYH': (['x', 'y', 'h'], np.random.rand(10, 20, len(h))), 'XYL': (['x', 'y', 'wd'], np.random.rand(10, 20, len(wd))), 'XYK': (['x', 'y', 'ws'], np.random.rand(10, 20, len(ws))), 'I': (['i'], np.random.rand(2)), 'IL': (['i', 'wd'], np.random.rand(2, len(wd))), 'IK': (['i', 'ws'], np.random.rand(2, len(ws))), 'ILK': (['i', 'wd', 'ws'], np.random.rand(2, len(wd), len(ws))), }, coords={'x': np.linspace(0, 100, 10), 'y': np.linspace(200, 300, 20), 'h': h, 'wd': wd, 'ws': ws, 'i': [0, 1]} ) site = XRSite(ds) lw = LocalWind(x_i=[25, 50], y_i=[225, 250], h_i=h_i, wd=wd_l, ws=ws_k, time=False, wd_bin_size=1) for n in ['XYHLK', 'XYHL', 'XYHK', 'K', 'L', 'KL', 'XY', 'H', 'XYH', 'XYL', 'XYK', 'I', 'IL', 'IK', 'ILK']: ip1 = site.interp(site.ds[n], lw.coords) ip2 = ds[n].sel_interp_all(lw.coords) npt.assert_array_equal(ip1.shape, ip2.shape) if not np.isnan(ip2).sum(): npt.assert_array_almost_equal(ip1.data, ip2.data)
def test_DeprecatedWindTurbines(): for wts in [ V80Deprecated(), WindTurbines( names=['V80'], diameters=[80], hub_heights=[70], ct_funcs=[ lambda ws: np.interp(ws, hornsrev1.ct_curve[:, 0], hornsrev1.ct_curve[:, 1]) ], power_funcs=[ lambda ws: np.interp(ws, hornsrev1.power_curve[:, 0], hornsrev1.power_curve[:, 1]) ], power_unit='w') ]: types0 = [0] * 9 wfm = NOJ(Hornsrev1Site(), wts) npt.assert_array_equal(wts.types(), [0]) npt.assert_almost_equal(wfm.aep(wt9_x, wt9_y, type=types0), 81.2066072392765)
def test_local_wind(site): x_i = y_i = np.arange(5) wdir_lst = np.arange(0, 360, 90) wsp_lst = np.arange(3, 6) WD_ilk, WS_ilk, TI_ilk, P_lk = site.local_wind(x_i=x_i, y_i=y_i, wd=wdir_lst, ws=wsp_lst) npt.assert_array_equal(WS_ilk.shape, (5, 4, 3)) WD_ilk, WS_ilk, TI_ilk, P_lk = site.local_wind(x_i=x_i, y_i=y_i) npt.assert_array_equal(WS_ilk.shape, (5, 360, 23)) # check probability local_wind()[-1] npt.assert_equal( site.local_wind(x_i=x_i, y_i=y_i, wd=[0], ws=[10], wd_bin_size=1)[-1], site.local_wind(x_i=x_i, y_i=y_i, wd=[0], ws=[10], wd_bin_size=2)[-1] / 2) npt.assert_almost_equal( site.local_wind(x_i=x_i, y_i=y_i, wd=[0], ws=[9, 10, 11])[-1].sum( (1, 2)), site.local_wind(x_i=x_i, y_i=y_i, wd=[0], ws=[10], ws_bins=3)[-1][:, 0, 0], 5) z = np.arange(1, 100) zero = [0] * len(z) ws = site.local_wind(x_i=zero, y_i=zero, h_i=z, wd=[0], ws=[10])[1][:, 0, 0] site2 = UniformWeibullSite(f, A, k, ti, shear=PowerShear(70, alpha=np.zeros_like(f) + .3)) ws70 = site2.local_wind(x_i=zero, y_i=zero, h_i=z, wd=[0], ws=[10])[1][:, 0, 0] if 0: import matplotlib.pyplot as plt plt.plot(ws, z) plt.plot(ws70, z) plt.show() npt.assert_array_equal(10 * (z / 50)**.3, ws) npt.assert_array_equal(10 * (z / 70)**.3, ws70)
def test_time_series_override_WD(): d = np.load(os.path.dirname(examples.__file__) + "/data/time_series.npz") wd, ws = [d[k][:6 * 24] for k in ['wd', 'ws']] t = pd.date_range("2000-01-01", freq="10T", periods=24 * 6) WD_it = (np.arange(80) / 100)[:, na] + wd[na] wt = V80() site = Hornsrev1Site() x, y = site.initial_position.T wfm = NOJ(site, wt) sim_res = wfm(x, y, ws=ws, wd=wd, time=t, WD=WD_it, verbose=False) npt.assert_array_equal(sim_res.WS, ws) npt.assert_array_equal(sim_res.WD, WD_it) npt.assert_array_equal(sim_res.time, t)