Ejemplo n.º 1
0
def test_DensityScaleFromSite():
    ds = Hornsrev1Site().ds
    ds['Air_density'] = 1.3

    u_p, p_c, ct_c = v80_upct.copy()

    for rho_ref in [1.225, 1.2]:
        curve = PowerCtTabular(ws=u_p,
                               power=p_c,
                               power_unit='w',
                               ct=ct_c,
                               ws_cutin=4,
                               ws_cutout=25,
                               method='linear',
                               additional_models=[DensityScale(rho_ref)])
        wfm = get_wfm(curve, site=XRSite(ds))
        ri, oi = wfm.windTurbines.function_inputs
        npt.assert_array_equal(ri, [])
        npt.assert_array_equal(oi, ['Air_density'])
        u = np.arange(4, 25, .1)
        sim_res = wfm(
            [0],
            [0],
            wd=0,
            ws=u,
        )
        p = sim_res.Power.values.squeeze()
        ct = sim_res.CT.values.squeeze()
        npt.assert_array_almost_equal(p,
                                      np.interp(u, u_p, p_c) * 1.3 / rho_ref)
        npt.assert_array_almost_equal(ct,
                                      np.interp(u, u_p, ct_c) * 1.3 / rho_ref)
Ejemplo n.º 2
0
def test_GCL_ex80():
    site = Hornsrev1Site()

    x, y = site.initial_position.T
    windTurbines = V80()
    wfm = PropagateDownwind(site,
                            windTurbines,
                            wake_deficitModel=GCLDeficit(),
                            superpositionModel=LinearSum())
    if 0:
        windTurbines.plot(x, y)
        plt.show()

    sim_res = timeit(wfm.__call__,
                     line_profile=0,
                     profile_funcs=[get_dU],
                     verbose=0)(x, y, ws=np.arange(10, 15))[0]

    # test that the result is equal to previuos runs (no evidens that  these number are correct)
    aep_ref = 1055.956615887197
    npt.assert_almost_equal(
        sim_res.aep_ilk(normalize_probabilities=True).sum(), aep_ref, 5)

    sim_res = wfm(x, y, ws=np.arange(3, 10))
    npt.assert_array_almost_equal(
        sim_res.aep_ilk(normalize_probabilities=True).sum(), 261.6143039016946,
        5)
Ejemplo n.º 3
0
def test_own_turbulence_is_zero(turbulenceModel):
    site = Hornsrev1Site()
    windTurbines = IEA37_WindTurbines()
    wf_model = All2AllIterative(site, windTurbines, wake_deficitModel=IEA37SimpleBastankhahGaussianDeficit(),
                                turbulenceModel=turbulenceModel())
    sim_res = wf_model([0], [0])
    npt.assert_array_equal(sim_res.TI_eff, sim_res.TI.broadcast_like(sim_res.TI_eff))
Ejemplo n.º 4
0
def test_twotype_windturbines():
    v80 = V80()

    def power(ws, types):
        power = v80.power(ws)
        # add 10% type 1 turbines
        power[types == 1] *= 1.1
        return power

    wts = WindTurbines(names=['V80', 'V88'],
                       diameters=[80, 88],
                       hub_heights=[70, 77],
                       ct_funcs=[v80.ct_funcs[0], v80.ct_funcs[0]],
                       power_funcs=[v80.power, lambda ws: v80.power(ws) * 1.1],
                       power_unit='w')

    import matplotlib.pyplot as plt
    types0 = [0] * 9
    types1 = [0, 0, 0, 1, 1, 1, 0, 0, 0]
    types2 = [1] * 9
    wts.plot(wt9_x, wt9_y, types1)
    wfm = NOJ(Hornsrev1Site(), wts)
    npt.assert_almost_equal(
        wfm(wt9_x, wt9_y, type=types0).aep(), 81.2066072392765)
    npt.assert_almost_equal(
        wfm(wt9_x, wt9_y, type=types1).aep(), 83.72420504573488)
    npt.assert_almost_equal(
        wfm(wt9_x, wt9_y, type=types2).aep(), 88.87227386796884)
    if 0:
        plt.show()
Ejemplo n.º 5
0
def test_wake_blockage_split(upstream_only, ref):
    class MyWakeModel(WakeDeficitModel):
        args4deficit = []

        def calc_deficit(self, dw_ijlk, **kwargs):
            return np.ones_like(dw_ijlk) * 2

    class MyBlockageModel(BlockageDeficitModel):
        args4deficit = []

        def calc_deficit(self, dw_ijlk, **kwargs):
            return np.ones_like(dw_ijlk)

    site = Hornsrev1Site()
    windTurbines = IEA37_WindTurbines()
    wf_model = All2AllIterative(
        site,
        windTurbines,
        wake_deficitModel=MyWakeModel(),
        blockage_deficitModel=MyBlockageModel(upstream_only=upstream_only))
    sim_res = wf_model([0], [0], ws=10, wd=270)
    fm = sim_res.flow_map(XYGrid(x=[-100, 100], y=[-100, 0, 100]))
    if 0:
        sim_res.flow_map().plot_wake_map()
        print(fm.WS_eff.values.squeeze().T)
        plt.show()

    npt.assert_array_equal(fm.WS_eff.values.squeeze().T, ref)
Ejemplo n.º 6
0
def test_from_flow_box_2wt():
    site = Hornsrev1Site()
    windTurbines = V80()

    # simulate current and neighbour wt
    wfm = BastankhahGaussian(site, windTurbines)
    wd = np.arange(30)
    sim_res = wfm([0, 0], [0, 500], wd=wd)
    ref_aep = sim_res.aep().sel(wt=0)

    wt_x, wt_y = [0], [0]
    neighbour_x, neighbour_y = [0], [500]

    # make site with effects of neighbour wt
    sim_res = wfm(neighbour_x, neighbour_y, wd=wd)
    e = 100
    box = sim_res.flow_box(x=np.linspace(min(wt_x) - e, max(wt_x) + e, 21),
                           y=np.linspace(min(wt_y) - e, max(wt_y) + e, 21),
                           h=windTurbines.hub_height(windTurbines.types()))
    site = XRSite.from_flow_box(box)

    # Simujlate current wt and compare aep
    wfm = BastankhahGaussian(site, windTurbines)
    sim_res = wfm(wt_x, wt_y, wd=wd)
    aep = sim_res.aep()

    if 0:
        site.ds.WS.sel(ws=10, wd=3).plot()
        windTurbines.plot(wt_x, wt_y)
        windTurbines.plot(neighbour_x, neighbour_y)
        plt.show()

    npt.assert_array_almost_equal(ref_aep, aep.sel(wt=0))
Ejemplo n.º 7
0
def check_speed_Hornsrev(WFModel):
    assert getattr(sys, 'gettrace')() is None, "Skipping speed check, In debug mode!!!"
    wt = HornsrevV80()
    site = Hornsrev1Site()
    wf_model = WFModel(site, wt)
    aep, t_lst = timeit(lambda x, y: wf_model(x, y).aep().sum())(wt_x, wt_y)

    fn = tfp + "speed_check/%s.txt" % WFModel.__name__
    if os.path.isfile(fn):
        with open(fn) as fid:
            lines = fid.readlines()

        # check aep
        npt.assert_almost_equal(float(lines[-1].split(";")[1]), aep)

        timings = np.array([(np.mean(eval(l.split(";")[2])), np.std(eval(l.split(";")[2]))) for l in lines])
        dates = [np.datetime64(l.split(";")[0]) for l in lines]
        dates = np.r_[dates, datetime.now()]
        y = np.r_[timings[:, 0], np.mean(t_lst)]

        error = np.r_[timings[:, 1], np.std(t_lst)]
        fig, axes = plt.subplots(2, 1)
        fig.suptitle(WFModel.__name__)
        for x, ax in zip([dates, np.arange(len(dates))], axes):
            ax.fill_between(x, y - 2 * error, y + 2 * error)
            ax.plot(x, y, '.-k')
            ax.axhline(y[:-1].mean() + 2 * error[:-1].mean(), ls='--', color='gray')

        if y[-1] > (y[:-1].mean() + 2 * error[:-1].mean()):
            raise Exception("Simulation time too slow, %f > %f" % (y[-1], (y[:-1].mean() + 2 * error[:-1].mean())))

    if getattr(sys, 'gettrace')() is None:
        with open(fn, 'a') as fid:
            fid.write("%s;%.10f;%s\n" % (datetime.now(), aep, t_lst))
Ejemplo n.º 8
0
def test_time_series_operating_wrong_shape():
    from py_wake.wind_turbines.power_ct_functions import PowerCtFunctionList, PowerCtTabular
    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']]
    ws += 3
    t = np.arange(6 * 24)
    wt = V80()
    site = Hornsrev1Site()

    # replace powerCtFunction
    wt.powerCtFunction = PowerCtFunctionList(
        key='operating',
        powerCtFunction_lst=[
            PowerCtTabular(ws=[0, 100],
                           power=[0, 0],
                           power_unit='w',
                           ct=[0, 0]),  # 0=No power and ct
            wt.powerCtFunction
        ],  # 1=Normal operation
        default_value=1)
    wfm = NOJ(site, wt)
    x, y = site.initial_position.T
    operating = (t < 48) | (t > 72)
    with pytest.raises(
            ValueError,
            match=
            r"Argument, operating\(shape=\(1, 144\)\), has unsupported shape."
    ):
        wfm(x, y, ws=ws, wd=wd, time=t, operating=[operating])
Ejemplo n.º 9
0
def test_time_series_operating():
    from py_wake.wind_turbines.power_ct_functions import PowerCtFunctionList, PowerCtTabular
    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']]
    ws += 3
    t = np.arange(6 * 24)
    wt = V80()
    site = Hornsrev1Site()

    # replace powerCtFunction
    wt.powerCtFunction = PowerCtFunctionList(
        key='operating',
        powerCtFunction_lst=[
            PowerCtTabular(ws=[0, 100],
                           power=[0, 0],
                           power_unit='w',
                           ct=[0, 0]),  # 0=No power and ct
            wt.powerCtFunction
        ],  # 1=Normal operation
        default_value=1)
    wfm = NOJ(site, wt)
    x, y = site.initial_position.T
    operating = (t < 48) | (t > 72)
    sim_res = wfm(x, y, ws=ws, wd=wd, time=t, operating=operating)
    npt.assert_array_equal(sim_res.operating[0], operating)
    npt.assert_array_equal(sim_res.Power[:, operating == 0], 0)
    npt.assert_array_equal(sim_res.Power[:, operating != 0] > 0, True)

    operating = np.ones((80, 6 * 24))
    operating[1] = (t < 48) | (t > 72)
    sim_res = wfm(x, y, ws=ws, wd=wd, time=t, operating=operating)
    npt.assert_array_equal(sim_res.operating, operating)
    npt.assert_array_equal(sim_res.Power.values[operating == 0], 0)
    npt.assert_array_equal(sim_res.Power.values[operating != 0] > 0, True)
Ejemplo n.º 10
0
def test_yaw_wrong_name():
    wfm = NOJ(Hornsrev1Site(), V80())
    for k in ['yaw_ilk', 'Yaw']:
        with pytest.raises(
                ValueError,
                match=r'Custom \*yaw\*\-keyword arguments not allowed'):
            wfm([0], [0], **{k: [[[30]]]})
Ejemplo n.º 11
0
def test_aep_wind_atlas_method():
    site = Hornsrev1Site()

    wt = IEA37_WindTurbines()
    wfm = IEA37SimpleBastankhahGaussian(site, wt)
    x, y = [0], [0]
    wd = np.arange(360)
    aep_lps = wfm(x, y, wd=wd,
                  ws=np.arange(3, 27)).aep(linear_power_segments=True)
    aep = wfm(x, y, wd=wd, ws=np.r_[3, np.arange(3.5, 27)]).aep()
    if 0:
        plt.plot(aep_lps.ws,
                 np.cumsum(aep_lps.sum(['wt', 'wd'])),
                 '.-',
                 label='Linear power segments')
        plt.plot(aep.ws,
                 np.cumsum(aep.sum(['wt', 'wd'])),
                 '.-',
                 label='Constant power segments')
        plt.ylabel('Cumulated AEP [GWh]')
        plt.xlabel('Wind speed [m/s]')
        plt.legend()
        plt.show()
    npt.assert_almost_equal(aep_lps.sum(), 16.73490444)
    npt.assert_almost_equal(aep.sum(), 16.69320343)
Ejemplo n.º 12
0
def main():
    if __name__ == '__main__':
        import matplotlib.pyplot as plt
        wt = HornsrevV80()
        wt.plot(wt_x, wt_y)
        aep_calculator = AEPCalculator(Hornsrev1Site(), wt, NOJ(wt))
        print('AEP', aep_calculator.calculate_AEP(wt_x, wt_y)[0].sum())
        plt.show()
Ejemplo n.º 13
0
def test_add_ilk_time_wrong_dim(shape):
    site = Hornsrev1Site()
    wt, wd, ws = np.arange(2), np.arange(100), np.arange(100) % 20 + 3
    t = pd.date_range("2000-01-01", freq="10T", periods=100)
    lw = site.local_wind(wt * 1000, wt * 0, wt * 0 + 70, wd, ws, time=t)

    with pytest.raises(ValueError):
        lw.add_ilk('TI', np.full(shape, 0.1))
Ejemplo n.º 14
0
def test_add_ilk_time(ti, dims):
    site = Hornsrev1Site()
    wt, wd, ws = np.arange(2), np.arange(100), np.arange(100) % 20 + 3
    t = pd.date_range("2000-01-01", freq="10T", periods=100)

    lw = site.local_wind(wt * 1000, wt * 0, wt * 0 + 70, wd, ws, time=t)
    lw.add_ilk('TI', ti)
    assert lw.TI.dims == dims
Ejemplo n.º 15
0
def test_time_series_aep():

    d = np.load(os.path.dirname(examples.__file__) + "/data/time_series.npz")
    wd, ws = [d[k][::100] for k in ['wd', 'ws']]
    wt = V80()
    site = Hornsrev1Site()
    x, y = site.initial_position.T
    wfm = NOJ(site, wt)
    sim_res = wfm(x, y, ws=ws, wd=wd, time=True, verbose=False)
    npt.assert_allclose(sim_res.aep().sum(), 545, atol=1)
Ejemplo n.º 16
0
def main():
    if __name__ == '__main__':
        import matplotlib.pyplot as plt
        wt = HornsrevV80()
        site = Hornsrev1Site()
        wt.plot(wt_x, wt_y)
        wf_model = NOJ(site, wt)
        aep = wf_model(wt_x, wt_y).aep()
        plt.title('AEP: %.1fGWh' % aep.sum())
        plt.show()
Ejemplo n.º 17
0
def main():
    if __name__ == '__main__':
        import matplotlib.pyplot as plt
        from py_wake.examples.data.hornsrev1 import Hornsrev1Site
        from py_wake.examples.data import hornsrev1
        from py_wake.superposition_models import LinearSum
        from py_wake.wind_farm_models import All2AllIterative

        site = Hornsrev1Site()
        windTurbines = hornsrev1.HornsrevV80()
        ws = 10
        D = 80
        R = D / 2
        WS_ilk = np.array([[[ws]]])
        D_src_il = np.array([[D]])
        ct_ilk = np.array([[[.8]]])
        ss = SelfSimilarityDeficit()

        x, y = -np.arange(200), np.array([0])
        deficit = ss.calc_deficit(WS_ilk=WS_ilk,
                                  D_src_il=D_src_il,
                                  dw_ijlk=x.reshape((1, len(x), 1, 1)),
                                  cw_ijlk=y.reshape((1, len(y), 1, 1)),
                                  ct_ilk=ct_ilk)
        plt.title('Fig 11 from [1]')
        plt.xlabel('x/R')
        plt.ylabel('a')
        plt.plot(x / R, deficit[0, :, 0, 0] / ws)

        plt.figure()
        x, y = np.array([-2 * R]), np.arange(200)
        deficit = ss.calc_deficit(WS_ilk=WS_ilk,
                                  D_src_il=D_src_il,
                                  dw_ijlk=x.reshape((1, len(x), 1, 1)),
                                  cw_ijlk=y.reshape((1, len(y), 1, 1)),
                                  ct_ilk=ct_ilk)
        plt.title('Fig 10 from [1]')
        r12 = np.sqrt(ss.lambda_ * (ss.eta + (x / R)**2))  # Eq. (13) from [1]
        print(x, r12)
        plt.xlabel('y/R12 (epsilon)')
        plt.ylabel('f')
        plt.plot((y / R) / r12, deficit[0, :, 0, 0] / deficit[0, 0, 0, 0])

        plt.figure()
        noj_ss = All2AllIterative(site,
                                  windTurbines,
                                  wake_deficitModel=NoWakeDeficit(),
                                  superpositionModel=LinearSum(),
                                  blockage_deficitModel=ss)
        flow_map = noj_ss(x=[0], y=[0], wd=[270], ws=[10]).flow_map()
        flow_map.plot_wake_map()
        flow_map.plot_windturbines()

        plt.show()
def test_deficit_symmetry(wake_deficitModel, blockage_deficitModel):
    site = Hornsrev1Site()
    windTurbines = IEA37_WindTurbines()

    wfm = All2AllIterative(site, windTurbines, wake_deficitModel=wake_deficitModel,
                           superpositionModel=LinearSum(),
                           blockage_deficitModel=blockage_deficitModel,
                           deflectionModel=None, turbulenceModel=None)

    power = wfm([0, 0, 500, 500], [0, 500, 0, 500], wd=[0], ws=[8]).power_ilk[:, 0, 0]
    npt.assert_array_almost_equal(power[:2], power[2:])
Ejemplo n.º 19
0
def test_own_deficit_is_zero():
    for deficitModel in get_models(WakeDeficitModel):
        site = Hornsrev1Site()
        windTurbines = IEA37_WindTurbines()
        wf_model = All2AllIterative(site,
                                    windTurbines,
                                    wake_deficitModel=deficitModel(),
                                    turbulenceModel=STF2017TurbulenceModel())
        sim_res = wf_model([0], [0])
        npt.assert_array_equal(sim_res.WS_eff,
                               sim_res.WS.broadcast_like(sim_res.WS_eff))
Ejemplo n.º 20
0
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)
def test_dAEP_2wt():
    site = Hornsrev1Site()
    iea37_site = IEA37Site(16)

    wt = IEA37_WindTurbines()
    wfm = IEA37SimpleBastankhahGaussian(site, wt)
    x, y = iea37_site.initial_position[np.array([0, 2, 5, 8, 14])].T

    # plot 2 wt case
    x, y = np.array([[0, 130 * 4], [0, 0]], dtype=np.float)
    x_lst = np.array([0., 1.]) * np.arange(1, 600, 10)[:, na]
    kwargs = {'ws': [10], 'wd': [270]}

    _, (ax1, ax2) = plt.subplots(1, 2, sharey=False)
    ax1.plot(x_lst[:, 1], [wfm.aep(x_, y, **kwargs) for x_ in x_lst])
    ax1.set_xlabel('Downwind distance [m]')
    ax1.set_ylabel('AEP [GWh]')

    x_ = x_lst[20]
    ax1.set_title("Center line")
    for grad in [fd, cs, autograd]:
        dAEPdx = wfm.dAEPdn(0, grad)(x_, y, **kwargs)[1]
        npt.assert_almost_equal(dAEPdx / 360, 3.976975605364392e-06,
                                (10, 5)[grad == fd])
        plot_gradients(wfm.aep(x_, y, **kwargs),
                       dAEPdx,
                       x_[1],
                       grad.__name__,
                       step=100,
                       ax=ax1)
    y_lst = np.array([0, 1.]) * np.arange(-100, 100, 5)[:, na]
    ax2.plot(y_lst[:, 1], [wfm.aep(x, y_, **kwargs) for y_ in y_lst])
    ax2.set_xlabel('Crosswind distance [m]')
    ax2.set_ylabel('AEP [GWh]')
    y_ = y_lst[25]
    ax2.set_title("%d m downstream" % x[1])
    for grad in [fd, cs, autograd]:
        dAEPdy = wfm.dAEPdn(1, grad)(x, y_, **kwargs)[1]
        plot_gradients(wfm.aep(x, y_, **kwargs),
                       dAEPdy,
                       y_[1],
                       grad.__name__,
                       step=50,
                       ax=ax2)
        npt.assert_almost_equal(dAEPdy / 360, 3.794435973860448e-05,
                                (10, 5)[grad == fd])

    if 0:
        plt.legend()
        plt.show()
    plt.close()
def test_dAEPdx():
    site = Hornsrev1Site()
    iea37_site = IEA37Site(16)

    wt = IEA37_WindTurbines()
    wfm = IEA37SimpleBastankhahGaussian(site, wt)
    x, y = iea37_site.initial_position[np.array([0, 2, 5, 8, 14])].T

    dAEPdxy_autograd = wfm.dAEPdxy(gradient_method=autograd)(x, y)
    dAEPdxy_cs = wfm.dAEPdxy(gradient_method=cs)(x, y)
    dAEPdxy_fd = wfm.dAEPdxy(gradient_method=fd)(x, y)

    npt.assert_array_almost_equal(dAEPdxy_autograd, dAEPdxy_cs, 15)
    npt.assert_array_almost_equal(dAEPdxy_autograd, dAEPdxy_fd, 6)
Ejemplo n.º 23
0
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)
Ejemplo n.º 24
0
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_two_wt_aep():
    site = Hornsrev1Site()
    windTurbines = IEA37_WindTurbines()
    wake_model = NOJ(site, windTurbines)
    sim_res1 = wake_model([0], [0], wd=270)
    sim_res2 = wake_model([0, 0], [0, 500], wd=270)

    # one wt, wind from west ~ 5845 hours of full load
    npt.assert_almost_equal(sim_res1.aep(normalize_probabilities=True).sum(), 3.35 * 5.845, 2)

    # No wake, two wt = 2 x one wt
    npt.assert_almost_equal(sim_res1.aep().sum() * 2, sim_res2.aep().sum())

    # same for normalized propabilities
    npt.assert_almost_equal(sim_res1.aep(normalize_probabilities=True).sum() * 2,
                            sim_res2.aep(normalize_probabilities=True).sum())
Ejemplo n.º 26
0
def main():
    if __name__ == '__main__':
        from py_wake import NOJ
        from py_wake import IEA37SimpleBastankhahGaussian, Fuga
        import py_wake
        import os
        import matplotlib.pyplot as plt
        from py_wake.examples.data.hornsrev1 import HornsrevV80, Hornsrev1Site
        from py_wake.examples.data.iea37._iea37 import IEA37Site

        LUT_path = os.path.dirname(
            py_wake.__file__
        ) + '/tests/test_files/fuga/2MW/Z0=0.03000000Zi=00401Zeta0=0.00E+00/'

        wt_x, wt_y = IEA37Site(16).initial_position.T

        windTurbines = HornsrevV80()
        site = Hornsrev1Site()

        wake_models = [
            NOJ(site, windTurbines),
            IEA37SimpleBastankhahGaussian(site, windTurbines),
            Fuga(LUT_path, site, windTurbines)
        ]

        for wake_model in wake_models:

            # Calculate AEP
            sim_res = wake_model(wt_x, wt_y)

            # Plot wake map
            plt.figure(wake_model.__class__.__name__)
            plt.title('AEP: %.2f GWh' % sim_res.aep().sum())

            flow_map = sim_res.flow_map(wd=[0], ws=[9])
            flow_map.plot_wake_map()
            flow_map.plot_windturbines()

        plt.show()
Ejemplo n.º 27
0
def test_GlobalWindAtlasSite():
    ref = Hornsrev1Site()
    lat, long = 55.52972, 7.906111  # hornsrev

    site = GlobalWindAtlasSite(lat, long, height=70, roughness=0.001, ti=0.075)
    ref_mean = weibull.mean(ref.ds.Weibull_A, ref.ds.Weibull_k)
    gwa_mean = weibull.mean(site.ds.Weibull_A, site.ds.Weibull_k)

    if 0:
        plt.figure()
        plt.plot(ref.ds.wd, ref_mean, label='HornsrevSite')
        plt.plot(site.ds.wd, gwa_mean, label='HornsrevSite')
        for r in [0, 1.5]:
            for h in [10, 200]:
                A, k = [site.gwc_ds[v].sel(roughness=r, height=h) for v in ['Weibull_A', 'Weibull_k']]
                plt.plot(site.gwc_ds.wd, weibull.mean(A, k), label=f'{h}, {r}')
        plt.legend()

        plt.show()

    npt.assert_allclose(gwa_mean, ref_mean, atol=1.4)
    for var, atol in [('Sector_frequency', 0.03), ('Weibull_A', 1.6), ('Weibull_k', 0.4)]:
        npt.assert_allclose(site.ds[var], ref.ds[var], atol=atol)
Ejemplo n.º 28
0
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)
Ejemplo n.º 29
0
import multiprocessing
from py_wake.examples.data.hornsrev1 import Hornsrev1Site, wt_x, wt_y
from py_wake import IEA37SimpleBastankhahGaussian
from py_wake.tests.check_speed import timeit
import numpy as np
from py_wake.tests import npt
from py_wake.wind_turbines import WindTurbines
from py_wake.examples.data import wtg_path


wt = WindTurbines.from_WAsP_wtg(wtg_path + "Vestas-V80.wtg")
site = Hornsrev1Site()
wf_model = IEA37SimpleBastankhahGaussian(site, wt)
wd_lst = np.arange(0, 360, 10)


def aep_wd(args):
    x, y, wd = args
    return wf_model(x, y, wd=wd, ws=None).aep().sum()


def aep_all_multiprocessing(pool, x, y):
    return np.sum(pool.map(aep_wd, [(x, y, i) for i in wd_lst]))


def aep_wfm_xy(args):
    wfm, x, y = args
    return wfm(x, y, wd=wd_lst).aep().sum()


def aep_xy(args):
Ejemplo n.º 30
0
def test_add_ilk_wrong_dim(shape):
    site = Hornsrev1Site()
    wt, wd, ws = np.arange(2), np.arange(360), np.arange(3, 26)
    lw = site.local_wind(wt * 1000, wt * 0, wt * 0 + 70, wd, ws, time=False)
    with pytest.raises(ValueError):
        lw.add_ilk('TI', np.full(shape, 0.1))