def test_negative_forecast_period(self, warning_list=None): """Test a warning is raised if the calculated forecast period is negative""" # default cube has a 4 hour forecast period, so add 5 hours to frt self.frt_coord.points = self.frt_coord.points + 5 * 3600 result = _calculate_forecast_period(self.time_coord, self.frt_coord) warning_msg = "The values for the time" result = _calculate_forecast_period(self.time_coord, self.frt_coord) self.assertTrue( any(item.category == UserWarning for item in warning_list)) self.assertTrue(any(warning_msg in str(item) for item in warning_list)) self.assertEqual(result.points, [-3600])
def test_check_time_unit_conversion(self): """Test correct values and units are returned when the input time and forecast reference time coordinates are in different units """ self.time_coord.convert_units("seconds since 1970-01-01 00:00:00") self.frt_coord.convert_units("hours since 1970-01-01 00:00:00") result = _calculate_forecast_period(self.time_coord, self.frt_coord) self.assertEqual(result, self.fp_coord)
def test_multiple_time_points(self): """Test a multi-valued forecast period coordinate can be created""" time_point = self.time_coord.points[0] new_time_points = [time_point, time_point + 3600, time_point + 7200] new_time_coord = self.time_coord.copy(new_time_points) fp_point = self.fp_coord.points[0] expected_fp_points = [fp_point, fp_point + 3600, fp_point + 7200] result = _calculate_forecast_period(new_time_coord, self.frt_coord) self.assertArrayAlmostEqual(result.points, expected_fp_points)
def test_bounds(self): """Test that the forecast_period coord has bounds where appropriate""" time_point = self.time_coord.points[0] self.time_coord.bounds = [[time_point - 3600, time_point]] fp_point = self.fp_coord.points[0] expected_fp_bounds = [[fp_point - 3600, fp_point]] result = _calculate_forecast_period(self.time_coord, self.frt_coord) self.assertArrayAlmostEqual(result.points, [fp_point]) self.assertArrayAlmostEqual(result.bounds, expected_fp_bounds)
def test_changing_mandatory_types(self): """Test that the data within the coord is as expected with the expected units, when mandatory standards for the forecast_period coordinate are changed. """ local_spec = TimeSpec(calendar=None, dtype=np.float64, units="hours") result = _calculate_forecast_period(self.time_coord, self.frt_coord, coord_spec=local_spec) self.assertEqual(result.units, "hours") self.assertArrayAlmostEqual(result.points * 3600.0, self.fp_coord.points) self.assertEqual(result.dtype, np.float64)
def test_values(self): """Test correct values are returned""" result = _calculate_forecast_period(self.time_coord, self.frt_coord) self.assertArrayAlmostEqual(result.points, self.fp_coord.points) self.assertEqual(result.units, self.fp_coord.units) self.assertEqual(result.dtype, self.fp_coord.dtype)
def test_dim_coord(self): """Test it is possible to create a dimension coordinate""" result = _calculate_forecast_period(self.time_coord, self.frt_coord, dim_coord=True) self.assertIsInstance(result, iris.coords.DimCoord)
def test_basic(self): """Test correct coordinate type is returned""" result = _calculate_forecast_period(self.time_coord, self.frt_coord) self.assertIsInstance(result, iris.coords.AuxCoord)