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)
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)
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.calculate_sleet_prob import calculate_sleet_probability result = calculate_sleet_probability(snow, rain) return result
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)