コード例 #1
0
 def test_negative_values(self):
     """Test that an exception is raised for negative values of
     probability_of_sleet in the cube."""
     rain = self.rain_prob_cube
     high_prob = self.high_prob_cube
     msg = "Negative values of sleet probability have been calculated."
     with self.assertRaisesRegex(ValueError, msg):
         calculate_sleet_probability(rain, high_prob)
コード例 #2
0
 def test_with_ints(self):
     """Test the basic sleet calculation works with int8 data."""
     rain_prob_cube = self.rain_prob_cube.copy(
         np.array(
             [
                 [[1, 0, 0], [0, 1, 1], [0, 0, 1]],
                 [[1, 0, 0], [0, 1, 1], [0, 0, 1]],
             ],
             dtype=np.int8,
         ))
     snow_prob_cube = self.snow_prob_cube.copy(
         np.array(
             [
                 [[0, 1, 0], [1, 0, 0], [0, 1, 0]],
                 [[0, 1, 0], [1, 0, 0], [0, 1, 0]],
             ],
             dtype=np.int8,
         ))
     expected_result = np.array(
         [
             [[0, 0, 1], [0, 0, 0], [1, 0, 0]],
             [[0, 0, 1], [0, 0, 0], [1, 0, 0]],
         ],
         dtype=np.int8,
     )
     result = calculate_sleet_probability(rain_prob_cube, snow_prob_cube)
     self.assertArrayAlmostEqual(result.data, expected_result)
     self.assertTrue(result.dtype == np.int8)
コード例 #3
0
 def test_basic_calculation(self):
     """Test the basic sleet calculation works."""
     expected_result = np.array(
         [
             [[0.5, 0.5, 0.0], [0.5, 0.5, 0.4], [0.9, 0.5, 0.4]],
             [[0.5, 0.5, 0.0], [0.5, 0.5, 0.4], [0.9, 0.5, 0.4]],
         ],
         dtype=np.float32,
     )
     result = calculate_sleet_probability(self.rain_prob_cube, self.snow_prob_cube)
     self.assertArrayAlmostEqual(result.data, expected_result)
     self.assertTrue(result.dtype == np.float32)
コード例 #4
0
def process(snow: cli.inputcube, rain: cli.inputcube):
    """Calculate sleet probability.

    Calculates the sleet probability using the
    calculate_sleet_probability plugin.

    Args:
        snow (iris.cube.Cube):
            An iris Cube of the probability of snow.
        rain (iris.cube.Cube):
            An iris Cube of the probability of rain.

    Returns:
        iris.cube.Cube:
            Returns a cube with the probability of sleet.
    """

    from improver.precipitation_type.calculate_sleet_prob import (
        calculate_sleet_probability, )

    result = calculate_sleet_probability(snow, rain)
    return result
コード例 #5
0
 def test_name_of_cube(self):
     """Test that the name has been changed to sleet_probability"""
     result = calculate_sleet_probability(self.snow_prob_cube,
                                          self.rain_prob_cube)
     name = "probability_of_sleet"
     self.assertEqual(result.long_name, name)