Exemplo n.º 1
0
 def test_exception_raised(self):
     """
     Test that a CoordinateNotFoundError exception is raised if the
     forecast_period, or the time and forecast_reference_time,
     are not present.
     """
     cube = set_up_cube()
     msg = "The forecast period coordinate is not available"
     with self.assertRaisesRegexp(CoordinateNotFoundError, msg):
         Utilities.find_required_lead_times(cube)
Exemplo n.º 2
0
 def test_coord_promotion_missing_scalar(self):
     """Test case in which a scalar coordinate has been lost from new_cube,
     meaning the cube undergoing checking ends up with different dimension
     coordinates to the progenitor cube. This raises an error."""
     cube = set_up_cube()
     new_cube = iris.util.squeeze(cube)
     new_cube.remove_coord('realization')
     msg = 'Returned cube dimension coordinates'
     with self.assertRaisesRegexp(iris.exceptions.CoordinateNotFoundError,
                                  msg):
         Utilities.check_cube_coordinates(cube, new_cube)
Exemplo n.º 3
0
 def test_check_forecast_period_unit_conversion_exception(self):
     """
     Test that an exception is raised, when the input cube has a
     forecast_period coordinate with units that can not be converted
     into hours.
     """
     cube = add_forecast_reference_time_and_forecast_period(set_up_cube())
     cube.coord("forecast_period").units = Unit("Celsius")
     msg = "For forecast_period"
     with self.assertRaisesRegexp(ValueError, msg):
         Utilities.find_required_lead_times(cube)
Exemplo n.º 4
0
 def test_coord_promotion(self):
     """Test that scalar coordinates in new_cube are promoted to dimension
     coordinates to match the parent cube."""
     cube = set_up_cube()
     new_cube = iris.util.squeeze(cube)
     result = Utilities.check_cube_coordinates(cube, new_cube)
     self.assertEqual(result.dim_coords, cube.dim_coords)
Exemplo n.º 5
0
 def test_coord_promotion_and_reordering(self):
     """Test case in which a scalar coordinate are promoted but the order
     must be corrected to match the progenitor cube."""
     cube = set_up_cube()
     new_cube = iris.util.squeeze(cube)
     cube.transpose(new_order=[1, 0, 2, 3])
     result = Utilities.check_cube_coordinates(cube, new_cube)
     self.assertEqual(result.dim_coords, cube.dim_coords)
Exemplo n.º 6
0
 def test_check_coordinate(self):
     """
     Test that the data within the numpy array is as expected, when
     the input cube has a forecast_period coordinate.
     """
     cube = add_forecast_reference_time_and_forecast_period(set_up_cube())
     expected_result = cube.coord("forecast_period").points
     result = Utilities.find_required_lead_times(cube)
     self.assertArrayAlmostEqual(result, expected_result)
Exemplo n.º 7
0
 def test_coord_promotion_only_dim_coords_in_parent(self):
     """Test that only dimension coordinates in the parent cube are matched
     when promoting the scalar coordinates in new_cube. Here realization is
     made into a scalar coordinate on the parent, and so should remain a
     scalar in new_cube as well."""
     cube = set_up_cube()
     new_cube = iris.util.squeeze(cube)
     cube = cube[0]
     result = Utilities.check_cube_coordinates(cube, new_cube)
     self.assertEqual(result.dim_coords, cube.dim_coords)
Exemplo n.º 8
0
 def test_check_forecast_period_unit_conversion(self):
     """
     Test that the data within the numpy array is as expected, when
     the input cube has a forecast_period coordinate with units
     other than the desired units of hours.
     """
     cube = add_forecast_reference_time_and_forecast_period(set_up_cube())
     expected_result = cube.coord("forecast_period").points.copy()
     cube.coord("forecast_period").convert_units("seconds")
     result = Utilities.find_required_lead_times(cube)
     self.assertArrayAlmostEqual(result, expected_result)
Exemplo n.º 9
0
 def test_basic(self):
     """Test that a numpy array is returned."""
     cube = add_forecast_reference_time_and_forecast_period(set_up_cube())
     result = Utilities.find_required_lead_times(cube)
     self.assertIsInstance(result, np.ndarray)
Exemplo n.º 10
0
 def test_basic(self):
     """Test that the __repr__ returns the expected string."""
     result = str(Utilities())
     msg = '<Utilities>'
     self.assertEqual(result, msg)
Exemplo n.º 11
0
 def test_basic(self):
     """Test returns iris.cube.Cube."""
     cube = set_up_cube()
     result = Utilities.check_cube_coordinates(cube, cube)
     self.assertIsInstance(result, Cube)
Exemplo n.º 12
0
 def test_returns_adjusted_values(self):
     """Test returns the correct values."""
     result = Utilities().adjust_nsize_for_ens(0.8, 3.0, 20.0)
     self.assertAlmostEqual(result, 9.2376043070399998)
Exemplo n.º 13
0
 def test_returns_unchanged_for_ens1(self):
     """Test returns unchanged value when num_ens = 1.0."""
     result = Utilities().adjust_nsize_for_ens(0.8, 1.0, 20.0)
     self.assertAlmostEqual(result, 20.0)
Exemplo n.º 14
0
 def test_basic_returns_float(self):
     """Test returns float."""
     result = Utilities().adjust_nsize_for_ens(1.0, 3.0, 20.0)
     self.assertIsInstance(result, float)