def test_jonswap_scalar(self): dset = jonswap(tp=10, dp=90, alpha=0.01) hs = integrate_2d_hs(dset['freq'], dset['dir'], dset['efth']) assert hs == pytest.approx(self.hs(10, 0.01), rel=1e-3) if plot: plt.pcolormesh(dset['freq'], dset['dir'], dset['efth'].T) plt.show()
def test_jonswap_matrix(self): tp = 10 * np.random.random((5, 4, 3)) dp = 360 * np.random.random((5, 4, 3)) dset = jonswap(tp, dp, alpha=0.01, dspr=25, coordinates=[('time', np.arange(0, 5)), ('lat', np.arange(0, 4)), ('lon', np.arange(0, 3))]) if plot: plt.pcolormesh(dset['freq'][:], dset['dir'][:], dset['efth'][0, :, :].T) plt.show() plt.pcolormesh(dset['freq'][:], dset['dir'][:], dset['efth'][1, :, :].T) plt.show() i = np.random.randint(5) j = np.random.randint(4) k = np.random.randint(3) assert_array_almost_equal(integrate_2d_hs(dset['freq'][:], dset['dir'][:], dset['efth'][i, j, k, :, :]), self.hs(tp[i, j, k], 0.01), decimal=3)
def test_jonswap_scalar(self): dset = jonswap(tp=10, dp=90, alpha=0.01) if plot: plt.pcolormesh(dset['freq'][:], dset['dir'][:], dset['efth'][:, :].T) plt.show() assert_array_almost_equal(integrate_2d_hs(dset['freq'][:], dset['dir'][:], dset['efth'][:, :]), self.hs(10, 0.01), decimal=3)
def test_jonswap_series(self): tp = [10, 5] dp = [90, 180] dspr = [25, 40] dset = jonswap(tp, dp, alpha=0.01, dspr=dspr, coordinates=[("time", [0, 0])]) for i, spec in enumerate(dset["efth"]): hs = integrate_2d_hs(dset["freq"], dset["dir"], spec) assert hs == pytest.approx(self.hs(tp[i], 0.01), rel=1e-3) if plot: plt.pcolormesh(dset["freq"], dset["dir"], dset["efth"][0].T) plt.show() plt.pcolormesh(dset["freq"], dset["dir"], dset["efth"][1].T) plt.show()
def test_jonswap_series(self): tp = [10, 5] dp = [90, 180] dspr = [25, 40] dset = jonswap(tp, dp, alpha=0.01, dspr=dspr, coordinates=[('time', [0, 0])]) if plot: plt.pcolormesh(dset['freq'][:], dset['dir'][:], dset['efth'][0, :, :].T) plt.show() plt.pcolormesh(dset['freq'][:], dset['dir'][:], dset['efth'][1, :, :].T) plt.show() for i, spec in enumerate(dset['efth']): assert_array_almost_equal(integrate_2d_hs(dset['freq'][:], dset['dir'][:], spec[:, :]), self.hs(tp[i], 0.01), decimal=3)