示例#1
0
def test_interpolation_speed():
    import xarray as xr
    da = xr.DataArray(np.sin(0.3 * np.arange(20).reshape(5, 4)),
                      [('x', np.arange(5)), ('y', [0.1, 0.2, 0.3, 0.4])])
    x = xr.DataArray([0.5, 1.5, 2.5], dims='z')
    y = xr.DataArray([0.15, 0.25, 0.35], dims='z')
    da.interp(x=x, y=y)

    site = ParqueFicticioSite()
    x, y = site.initial_position.T
    X, Y, x_j, y_j, h_j = HorizontalGrid()(x, y, 70)
    wd = [270]  # site.default_wd
    ws = site.default_ws
    res1, t_lst = timeit(site.interp_funcs['A'])(
        (x_j, y_j, h_j, x_j * 0 + 270))
    print(res1.shape)
    res2, t_lst = timeit(lambda x, y, z, sec: site._ds.A.interp(
        x=xr.DataArray(x, dims='z'),
        y=xr.DataArray(y, dims='z'),
        z=xr.DataArray(z, dims='z'),
        sec=xr.DataArray(sec, dims='z')).data)(x_j, y_j, h_j, x_j * 0 + 10)
    npt.assert_array_almost_equal(res1, res2)
    if 0:
        c = plt.contourf(X, Y, res1.reshape(X.shape))
        plt.colorbar(c)
        plt.figure()
        c = plt.contourf(X, Y, res2.reshape(X.shape))
        plt.colorbar(c)
        plt.show()
示例#2
0
def test_additional_input():
    site = ParqueFicticioSite()

    x, y = site.initial_position.T
    h = 70 * np.ones_like(x)

    lw = site.local_wind(x, y, h)
    ws_mean = site.interp(site.ds.ws_mean, lw.coords)
    npt.assert_array_almost_equal(
        ws_mean[0, :50],
        np.array([
            4.77080802, 4.77216214, 4.77351626, 4.77487037, 4.77622449,
            4.77757861, 4.77893273, 4.78028685, 4.78164097, 4.78299508,
            4.7843492, 4.78570332, 4.78705744, 4.78841156, 4.78976567,
            4.79111979, 4.79247391, 4.79382803, 4.79518215, 4.79653626,
            4.79789038, 4.7992445, 4.80059862, 4.80195274, 4.80330685,
            4.80466097, 4.80601509, 4.80736921, 4.80872333, 4.81007744,
            4.81143156, 4.87114138, 4.9308512, 4.99056102, 5.05027084,
            5.10998066, 5.16969047, 5.22940029, 5.28911011, 5.34881993,
            5.40852975, 5.46823957, 5.52794939, 5.5876592, 5.64736902,
            5.70707884, 5.76678866, 5.82649848, 5.8862083, 5.94591812
        ]))
示例#3
0
def test_additional_input():
    site = ParqueFicticioSite()
    wgs = WaspGridSite(site._ds, distance=TerrainFollowingDistance(distance_resolution=2000))
    wgs.interp_funcs_initialization(['ws_mean'])
    x, y = site.initial_position.T
    h = 70 * np.ones_like(x)
    ws_mean, = wgs.interpolate(['ws_mean'], x, y, h)
    npt.assert_array_almost_equal(ws_mean[0, :50],
                                  np.array([4.77080802, 4.77216214, 4.77351626, 4.77487037, 4.77622449,
                                            4.77757861, 4.77893273, 4.78028685, 4.78164097, 4.78299508,
                                            4.7843492, 4.78570332, 4.78705744, 4.78841156, 4.78976567,
                                            4.79111979, 4.79247391, 4.79382803, 4.79518215, 4.79653626,
                                            4.79789038, 4.7992445, 4.80059862, 4.80195274, 4.80330685,
                                            4.80466097, 4.80601509, 4.80736921, 4.80872333, 4.81007744,
                                            4.81143156, 4.87114138, 4.9308512, 4.99056102, 5.05027084,
                                            5.10998066, 5.16969047, 5.22940029, 5.28911011, 5.34881993,
                                            5.40852975, 5.46823957, 5.52794939, 5.5876592, 5.64736902,
                                            5.70707884, 5.76678866, 5.82649848, 5.8862083, 5.94591812]))
示例#4
0
def test_interp_funcs_initialization_missing_key(site):
    site = ParqueFicticioSite(distance=TerrainFollowingDistance2())
    site.interp_funcs_initialization(['missing'])
示例#5
0
def site2():
    site = ParqueFicticioSite(distance=TerrainFollowingDistance2())
    x, y = site.initial_position.T
    return site, x, y
示例#6
0
def site():
    return ParqueFicticioSite()
示例#7
0
        plt.plot(wasp_aep_no_density_correction / 1000, '.-', label='WAsP')
        plt.plot(AEP_ilk.sum((0, 2)) * 1e3, label='PyWake')
        plt.xlabel('Sector')
        plt.ylabel('AEP [MWh]')
        plt.legend()
        plt.show()
    npt.assert_array_less(
        np.abs(wasp_aep_no_density_correction - AEP_ilk.sum((0, 2)) * 1e6),
        300)
    npt.assert_almost_equal(AEP_ilk.sum(),
                            wasp_aep_no_density_correction_total, 3)


@pytest.mark.parametrize(
    'site,dw_ref',
    [(ParqueFicticioSite(distance=TerrainFollowingDistance2()), [
        0., 207.3842238, 484.3998264, 726.7130743, 1039.148129, 1263.1335982,
        1490.3841602, 1840.6508086
    ]),
     (ParqueFicticioSite(distance=TerrainFollowingDistance()), [
         0, 209.803579, 480.8335365, 715.6003233, 1026.9476322, 1249.5510034,
         1475.1467251, 1824.1317343
     ]),
     (ParqueFicticioSite(distance=StraightDistance()),
      [-0, 207, 477, 710, 1016, 1236, 1456, 1799])])
def test_distances(site, dw_ref):
    x, y = site.initial_position.T
    dw_ijl, cw_ijl, dh_ijl, _ = site.distances(src_x_i=x,
                                               src_y_i=y,
                                               src_h_i=np.array([70]),
                                               dst_x_j=x,
示例#8
0
 def __init__(self):
     ParqueFicticioSite.__init__(self, distance=TerrainFollowingDistance2())