def test_speed_01(self): from_axis = DailyTimeAxisBuilder(start_date=date(2000, 1, 1), end_date=date(2020, 1, 1)).build() to_axis = MonthlyTimeAxisBuilder(start_year=2000, end_year=2019).build() tc = AxisRemapper(from_axis=from_axis, to_axis=to_axis) from_data = np.random.random((from_axis.nelem, 100, 100)) import time start = time.time() for i in range(1): tc.min(from_data) end = time.time() print(f"Took: %f [s]", end - start) import time start = time.time() for i in range(1): tc.min(from_data) end = time.time() print(f"Took: %f [s]", end - start)
def test_dask_min(self): from_axis = DailyTimeAxisBuilder(start_date=date(2019, 1, 1), n_interval=14).build() to_axis = WeeklyTimeAxisBuilder(start_date=date(2019, 1, 1), n_interval=3).build() tc = AxisRemapper(from_axis=from_axis, to_axis=to_axis, assure_no_bound_mismatch=False) from_data = da.arange(14, dtype='float64') to_data = tc.min(from_data).compute() np.testing.assert_almost_equal( to_data, np.array([0.0, 7.0, np.nan]).reshape(3, 1))
def test_min_01(self): from_axis = DailyTimeAxisBuilder(start_date=date(2019, 1, 1), n_interval=14).build() to_axis = WeeklyTimeAxisBuilder(start_date=date(2019, 1, 1), n_interval=2).build() tc = AxisRemapper(from_axis=from_axis, to_axis=to_axis) from_data = list(range(1, 15)) to_data = tc.min(from_data) self.assertAlmostEqual(1.0, to_data[0, 0], 0) self.assertAlmostEqual(8.0, to_data[1, 0], 0)
def test_min_05(self): from_axis = DailyTimeAxisBuilder(start_date=date(2019, 1, 1), n_interval=14).build() to_axis = WeeklyTimeAxisBuilder(start_date=date(2019, 1, 1), n_interval=3).build() tc = AxisRemapper(from_axis=from_axis, to_axis=to_axis, assure_no_bound_mismatch=False) from_data = list(range(1, 15)) to_data = tc.min(from_data) self.assertAlmostEqual(1.0, to_data[0, 0], 0) self.assertAlmostEqual(8.0, to_data[1, 0], 0) self.assertTrue(np.isnan(to_data[2, 0]))
def test_min_02(self): from_axis = DailyTimeAxisBuilder(start_date=date(2019, 1, 1), n_interval=14).build() to_axis = WeeklyTimeAxisBuilder(start_date=date(2019, 1, 1), n_interval=2).build() tc = AxisRemapper(from_axis=from_axis, to_axis=to_axis) from_data = np.moveaxis( np.asarray(list(range(1, 15)) * 12).reshape((3, 4, 14)), 2, 0).tolist() to_data = tc.min(from_data) self.assertTrue( np.all(np.ones((3, 4), dtype="int") - to_data[0].round() == 0.0)) self.assertTrue( np.all( np.ones((3, 4), dtype="int") * 8 - to_data[1].round() == 0.0))
def test_min_04(self): from_axis = DailyTimeAxisBuilder(start_date=date(2019, 1, 1), n_interval=14).build() to_axis = RollingWindowTimeAxisBuilder(start_date=date(2019, 1, 1), end_date=date(2019, 1, 15), window_size=7).build() tc = AxisRemapper(from_axis=from_axis, to_axis=to_axis) from_data = np.moveaxis( np.asarray(list(range(1, 15)) * 12).reshape((3, 4, 14)), 2, 1).tolist() to_data = tc.min(from_data, dimension=1) for i in range(tc.to_nelem): self.assertTrue( np.all( np.ones((3, 4), dtype="int") * (1 + i) - to_data[:, i, :].round() == 0.0))