예제 #1
0
 def test_percentile_length_too_short(self):
     """
     Test that the plugin raises the default ValueError, if the number
     of percentiles is fewer than the length of the zeroth dimension of the
     required cube data.
     """
     cube_data = self.cube_data + 2
     percentiles = [10, 50]
     msg = "Require data with shape"
     with self.assertRaisesRegex(ValueError, msg):
         create_cube_with_percentiles(percentiles, self.cube, cube_data)
예제 #2
0
 def test_percentile_length_too_long(self):
     """
     Test that the plugin raises the default ValueError, if the number
     of percentiles exceeds the length of the zeroth dimension of the
     required data.
     """
     cube_data = self.cube_data[0, :, :] + 2
     percentiles = [10, 50, 90]
     msg = "Require data with shape"
     with self.assertRaisesRegex(ValueError, msg):
         create_cube_with_percentiles(percentiles, self.cube, cube_data)
예제 #3
0
 def test_percentile_length_too_short(self):
     """
     Test that the plugin raises the default ValueError, if the number
     of percentiles is fewer than the length of the zeroth dimension within
     the cube.
     """
     cube = self.current_temperature_forecast_cube
     cube_data = self.cube_data + 2
     percentiles = [10, 50]
     msg = "Unequal lengths"
     with self.assertRaisesRegex(ValueError, msg):
         create_cube_with_percentiles(percentiles, cube, cube_data)
예제 #4
0
 def test_incompatible_percentiles(self):
     """
     Test that the plugin fails if the percentile values requested
     are not numbers.
     """
     cube = self.current_temperature_forecast_cube
     percentiles = ["cat", "dog", "elephant"]
     cube_data = np.zeros(
         [len(percentiles), len(cube.coord("time").points),
          len(cube.coord("latitude").points),
          len(cube.coord("longitude").points)])
     msg = "could not convert string to float"
     with self.assertRaisesRegex(ValueError, msg):
         create_cube_with_percentiles(percentiles, cube, cube_data)
예제 #5
0
 def test_resulting_cube_units(self):
     """Test that the plugin returns a cube of suitable units."""
     cube = self.current_temperature_forecast_cube
     cube_data = self.cube_data + 2
     percentiles = [10, 50, 90]
     result = create_cube_with_percentiles(percentiles, cube, cube_data)
     self.assertEqual(result.units, cube.units)
예제 #6
0
 def test_basic(self):
     """Test that the plugin returns an Iris.cube.Cube."""
     cube = self.current_temperature_forecast_cube
     cube_data = self.cube_data + 2
     percentiles = [10, 50, 90]
     result = create_cube_with_percentiles(percentiles, cube, cube_data)
     self.assertIsInstance(result, Cube)
예제 #7
0
 def test_basic(self):
     """Test that the plugin returns an Iris.cube.Cube with suitable units."""
     cube_data = self.cube_data + 2
     percentiles = [10, 50, 90]
     result = create_cube_with_percentiles(percentiles, self.cube, cube_data)
     self.assertIsInstance(result, Cube)
     self.assertEqual(result.units, self.cube.units)
예제 #8
0
 def test_changed_cube_units(self):
     """Test that the plugin returns a cube with chosen units."""
     cube = self.current_temperature_forecast_cube
     cube_data = self.cube_data + 2
     percentiles = [10, 50, 90]
     result = create_cube_with_percentiles(
         percentiles, cube, cube_data, cube_unit='1')
     self.assertEqual(result.units, Unit('1'))
예제 #9
0
 def test_changed_cube_units(self):
     """Test that the plugin returns a cube with chosen units."""
     cube_data = self.cube_data + 2
     percentiles = [10, 50, 90]
     result = create_cube_with_percentiles(
         percentiles, self.cube, cube_data, cube_unit="1"
     )
     self.assertEqual(result.units, Unit("1"))
예제 #10
0
 def test_metadata_copy(self):
     """
     Test that the metadata dictionaries within the input cube, are
     also present on the output cube.
     """
     self.cube.attributes = {"source": "ukv"}
     cube_data = self.cube_data + 2
     percentiles = [10, 50, 90]
     result = create_cube_with_percentiles(percentiles, self.cube, cube_data)
     self.assertDictEqual(self.cube.metadata._asdict(), result.metadata._asdict())
예제 #11
0
 def test_percentile_points(self):
     """
     Test that the plugin returns an Iris.cube.Cube
     with a percentile coordinate with the desired points.
     """
     cube_data = self.cube_data + 2
     percentiles = [10, 50, 90]
     result = create_cube_with_percentiles(percentiles, self.cube, cube_data)
     self.assertIsInstance(result.coord("percentile"), DimCoord)
     self.assertArrayAlmostEqual(result.coord("percentile").points, percentiles)
예제 #12
0
 def test_many_percentiles(self):
     """Test that the plugin returns an Iris.cube.Cube with many percentiles.
     """
     percentiles = np.linspace(0, 100, 100)
     cube_data = np.zeros([
         len(percentiles),
         len(self.cube.coord("latitude").points),
         len(self.cube.coord("longitude").points),
     ])
     result = create_cube_with_percentiles(percentiles, self.cube,
                                           cube_data)
     self.assertEqual(cube_data.shape, result.data.shape)
예제 #13
0
 def test_coordinate_copy(self):
     """
     Test that the coordinates within the input cube, are
     also present on the output cube.
     """
     cube_data = self.cube_data + 2
     percentiles = [10, 50, 90]
     result = create_cube_with_percentiles(percentiles, self.cube, cube_data)
     for coord in self.cube.coords():
         if coord not in result.coords():
             msg = "Coordinate: {} not found in cube {}".format(coord, result)
             raise CoordinateNotFoundError(msg)
예제 #14
0
 def test_spot_forecasts_percentile_points(self):
     """
     Test that the plugin returns a Cube with a percentile dimension
     coordinate and that the percentile dimension has the expected points
     for an input spot forecast.
     """
     cube = self.current_temperature_spot_forecast_cube
     cube_data = self.cube_spot_data + 2
     percentiles = [10, 50, 90]
     result = create_cube_with_percentiles(percentiles, cube, cube_data)
     self.assertIsInstance(result, Cube)
     self.assertIsInstance(result.coord("percentile"), DimCoord)
     self.assertArrayAlmostEqual(
         result.coord("percentile").points, percentiles)
예제 #15
0
 def test_coordinate_copy(self):
     """
     Test that the coordinates within the input cube, are
     also present on the output cube.
     """
     cube = self.current_temperature_forecast_cube
     cube.attributes = {"source": "ukv"}
     cube_data = self.cube_data + 2
     percentiles = [10, 50, 90]
     result = create_cube_with_percentiles(percentiles, cube, cube_data)
     for coord in cube.coords():
         if coord not in result.coords():
             msg = ("Coordinate: {} not found in cube {}".format(
                 coord, result))
             raise CoordinateNotFoundError(msg)
예제 #16
0
    def test_spot_forecasts_percentile_points(self):
        """
        Test that the plugin returns a Cube with a percentile dimension
        coordinate and that the percentile dimension has the expected points
        for an input spot forecast.
        """
        cube = set_up_spot_test_cube()
        spot_data = cube.data.copy() + 2
        spot_cube = next(cube.slices_over("realization"))
        spot_cube.remove_coord("realization")

        percentiles = [10, 50, 90]
        result = create_cube_with_percentiles(percentiles, spot_cube, spot_data)
        self.assertIsInstance(result, Cube)
        self.assertIsInstance(result.coord("percentile"), DimCoord)
        self.assertArrayAlmostEqual(result.coord("percentile").points, percentiles)