Esempio n. 1
0
 def test_locator_given_time_pressure_format(self):
     pattern = self.path
     reference_time = dt.datetime(2019, 1, 1)
     times = [dt.datetime(2019, 1, 2), dt.datetime(2019, 1, 2, 3)]
     pressures = [1000, 950, 850]
     with netCDF4.Dataset(self.path, "w") as dataset:
         um = forest.tutorial.core.UM(dataset)
         dataset.createDimension("longitude", 1)
         dataset.createDimension("latitude", 1)
         var = um.times("time", length=len(times))
         var[:] = netCDF4.date2num(times, units=var.units)
         um.forecast_reference_time(reference_time)
         var = um.pressures("pressure", length=len(pressures))
         var[:] = pressures
         dims = ("time", "pressure", "longitude", "latitude")
         coordinates = "forecast_period_1 forecast_reference_time"
         var = um.relative_humidity(dims, coordinates=coordinates)
         var[:] = 100.0
     variable = "relative_humidity"
     initial_time = reference_time
     valid_time = times[1]
     pressure = pressures[2]
     locator = unified_model.Locator([self.path])
     _, result = locator.locate(pattern, variable, initial_time, valid_time,
                                pressure)
     expect = (1, 2)
     self.assertEqual(expect, result)
Esempio n. 2
0
 def test_locator_given_dim0_format(self):
     pattern = self.path
     times = [dt.datetime(2019, 1, 1), dt.datetime(2019, 1, 2)]
     with netCDF4.Dataset(self.path, "w") as dataset:
         um = forest.tutorial.core.UM(dataset)
         dataset.createDimension("longitude", 1)
         dataset.createDimension("latitude", 1)
         var = um.times("time", length=len(times), dim_name="dim0")
         var[:] = netCDF4.date2num(times, units=var.units)
         um.forecast_reference_time(times[0])
         var = um.pressures("pressure", length=len(times), dim_name="dim0")
         var[:] = 1000.0
         dims = ("dim0", "longitude", "latitude")
         coordinates = (
             "forecast_period_1 forecast_reference_time pressure time")
         var = um.relative_humidity(dims, coordinates=coordinates)
         var[:] = 100.0
     variable = "relative_humidity"
     initial_time = dt.datetime(2019, 1, 1)
     valid_time = dt.datetime(2019, 1, 2)
     locator = unified_model.Locator([self.path])
     _, result = locator.locate(pattern,
                                variable,
                                initial_time,
                                valid_time,
                                pressure=1000.0001)
     expect = (1, )
     self.assertEqual(expect, result)
 def test_locator_given_time_outside_time_axis(self):
     pattern = self.path
     reference_time = dt.datetime(2019, 1, 1)
     times = [dt.datetime(2019, 1, 2), dt.datetime(2019, 1, 2, 3)]
     future = dt.datetime(2019, 1, 4)
     pressures = [1000, 950, 850]
     with netCDF4.Dataset(self.path, "w") as dataset:
         um = tutorial.UM(dataset)
         dataset.createDimension("longitude", 1)
         dataset.createDimension("latitude", 1)
         var = um.times("time", length=len(times))
         var[:] = netCDF4.date2num(times, units=var.units)
         um.forecast_reference_time(reference_time)
         var = um.pressures("pressure", length=len(pressures))
         var[:] = pressures
         dims = ("time", "pressure", "longitude", "latitude")
         coordinates = "forecast_period_1 forecast_reference_time"
         var = um.relative_humidity(dims, coordinates=coordinates)
         var[:] = 100.
     variable = "relative_humidity"
     initial_time = reference_time
     valid_time = future
     pressure = pressures[2]
     locator = unified_model.Locator([self.path])
     with self.assertRaises(SearchFail):
         locator.locate(pattern, variable, initial_time, valid_time,
                        pressure)
Esempio n. 4
0
 def test_locator_given_empty_file_raises_exception(self):
     pattern = self.path
     with netCDF4.Dataset(self.path, "w") as dataset:
         pass
     variable = "relative_humidity"
     initial_time = dt.datetime(2019, 1, 1)
     valid_time = dt.datetime(2019, 1, 1)
     locator = unified_model.Locator([self.path])
     with self.assertRaises(SearchFail):
         locator.locate(pattern, variable, initial_time, valid_time)
Esempio n. 5
0
 def test_locate_given_one_thousand_files(self):
     N = 10**4
     k = np.random.randint(N)
     start = dt.datetime(2019, 1, 10)
     times = [start + dt.timedelta(hours=i) for i in range(N)]
     paths = [
         "test-locate-{:%Y%m%dT%H%MZ}.nc".format(time) for time in times
     ]
     locator = unified_model.Locator(paths)
     result = locator.find_paths(times[k])
     expect = [paths[k]]
     self.assertEqual(expect, result)