def test_wrong_forecast(self): with self.assertRaises(AromeDataRepositoryError) as context: utc = api.Calendar() # No offset gives Utc t0 = api.YMDhms(2015, 12, 25, 18) period = api.UtcPeriod(utc.time(t0), utc.time(t0) + api.deltahours(30)) ar1 = AromeDataRepository(32632, shyftdata_dir, filename="plain_wrong_*.nc") ar1.get_forecast(("temperature",), period, utc.time(t0), None) self.assertTrue(all(x in context.exception.args[0] for x in ["No matches found for file_pattern = ", "and t_c = "]))
def test_get_forecast(self): # Period start year = 2015 month = 8 day = 24 hour = 6 n_hours = 65 utc = api.Calendar() # No offset gives Utc t0 = api.YMDhms(year, month, day, hour) period = api.UtcPeriod(utc.time(t0), utc.time(t0) + api.deltahours(n_hours)) t_c1 = utc.time(t0) + api.deltahours(1) t_c2 = utc.time(t0) + api.deltahours(7) base_dir = path.join(shyftdata_dir, "repository", "arome_data_repository") pattern = "arome_metcoop*default2_5km_*.nc" EPSG, bbox = self.arome_epsg_bbox repos = AromeDataRepository(EPSG, base_dir, filename=pattern, bounding_box=bbox) data_names = ("temperature", "wind_speed", "precipitation", "relative_humidity") tc1_sources = repos.get_forecast(data_names, period, t_c1, None) tc2_sources = repos.get_forecast(data_names, period, t_c2, None) self.assertTrue(len(tc1_sources) == len(tc2_sources)) self.assertTrue(set(tc1_sources) == set(data_names)) self.assertTrue(tc1_sources["temperature"][0].ts.size() == n_hours + 1) tc1_precip = tc1_sources["precipitation"][0].ts tc2_precip = tc2_sources["precipitation"][0].ts self.assertEqual(tc1_precip.size(), n_hours) self.assertTrue(tc1_precip.time(0) != tc2_precip.time(0))