def test_pickle(self): wt = core.WaveTable(['O1', 'P1']) unfrozen = pickle.loads(pickle.dumps(wt)) self.assertTrue(isinstance(unfrozen, core.WaveTable)) self.assertEqual(len(wt), len(unfrozen)) self.assertListEqual([item.name() for item in wt], [item.name() for item in unfrozen])
def test_init(self): wt = core.WaveTable() self.assertEqual(len(wt), 67) self.assertEqual(len([item for item in wt]), 67) self.assertEqual(wt.wave("M2"), wt.wave(core.Wave.Ident.kM2)) self.assertNotEqual(wt.wave("M2"), wt.wave(core.Wave.Ident.kK1)) self.assertTrue(wt.wave("__M2__") is None) self.assertListEqual(sorted(wt.known_constituents()), sorted([item.name() for item in wt])) for item in wt: self.assertEqual(item.ident, getattr(core.Wave.Ident, "k" + item.name())) wt = core.WaveTable(["M2", "K1", "O1", "P1", "Q1", "S1"]) self.assertEqual(len(wt), 6) self.assertListEqual(sorted([item.name() for item in wt]), sorted(["M2", "K1", "O1", "P1", "Q1", "S1"]))
def test_wave(self): aa = core.AstronomicAngle(core.timestamp(datetime.datetime(2000, 1, 1))) wt = core.WaveTable(["M2"]) wave = wt.wave("M2") self.assertAlmostEqual(wave.freq * 86400, 12.140833182614747, delta=1e-6) self.assertEqual(wave.type, wave.TidalType.kShortPeriod)
def test_analysis(self): with netCDF4.Dataset(self.DATASET) as dataset: time = dataset['time'][:] * 1e-6 h = dataset['ocean'][:] * 1e-2 wt = core.WaveTable() f, vu = wt.compute_nodal_modulations(time) w = wt.harmonic_analysis(h, f, vu) delta = h - wt.tide_from_tide_series(time, w) self.assertAlmostEqual(delta.mean(), 0, delta=1e-16) self.assertAlmostEqual(delta.std(), 0, delta=1e-12)
def test_reentering(self): with netCDF4.Dataset(self.DATASET) as dataset: time = dataset['time'][:4096] * 1e-6 h = dataset['ocean'][:4096] * 1e-2 wt = core.WaveTable() f, vu = wt.compute_nodal_modulations(time) w = wt.harmonic_analysis(h, f, vu) result = [] with concurrent.futures.ThreadPoolExecutor() as client: futures = [] for item in range(50): futures.append(client.submit(wt.tide_from_tide_series, time, w)) for item in concurrent.futures.as_completed(futures): result.append(item.result()) first = result.pop() for item in result: self.assertTrue(numpy.all(first == item))