def test_endpoints_of_distribution_exceeded(self): """ Test that the plugin raises a ValueError when the constant end points of the distribution are exceeded by a threshold value used in the forecast. """ probabilities_for_cdf = np.array([[0.05, 0.7, 0.95]]) threshold_points = np.array([8, 10, 60]) bounds_pairing = (-40, 50) plugin = Plugin() msg = "The calculated threshold values" with self.assertRaisesRegex(ValueError, msg): plugin._add_bounds_to_thresholds_and_probabilities( threshold_points, probabilities_for_cdf, bounds_pairing)
def test_endpoints_of_distribution_exceeded_warning(self, warning_list=None): """ Test that the plugin raises a warning message when the constant end points of the distribution are exceeded by a threshold value used in the forecast and the ecc_bounds_warning keyword argument has been specified. """ probabilities_for_cdf = np.array([[0.05, 0.7, 0.95]]) threshold_points = np.array([8, 10, 60]) plugin = Plugin(ecc_bounds_warning=True) warning_msg = "The calculated threshold values" plugin._add_bounds_to_thresholds_and_probabilities( threshold_points, probabilities_for_cdf, self.bounds_pairing ) self.assertTrue(any(warning_msg in str(item) for item in warning_list))
def test_basic(self): """Test that the plugin returns two numpy arrays.""" cube = self.current_temperature_forecast_cube probabilities_for_cdf = cube.data.reshape(3, 9) bounds_pairing = (-40, 50) plugin = Plugin() result = plugin._add_bounds_to_thresholds_and_probabilities( self.threshold_points, probabilities_for_cdf, bounds_pairing) self.assertIsInstance(result[0], np.ndarray) self.assertIsInstance(result[1], np.ndarray)
def test_new_endpoints_generation(self): """Test that the plugin re-applies the threshold bounds using the maximum and minimum threshold points values when the original bounds have been exceeded and ecc_bounds_warning has been set.""" probabilities_for_cdf = np.array([[0.05, 0.7, 0.95]]) threshold_points = np.array([-50, 10, 60]) plugin = Plugin(ecc_bounds_warning=True) result = plugin._add_bounds_to_thresholds_and_probabilities( threshold_points, probabilities_for_cdf, self.bounds_pairing) self.assertEqual(max(result[0]), max(threshold_points)) self.assertEqual(min(result[0]), min(threshold_points))
def test_endpoints_of_distribution_exceeded_warning( self, warning_list=None): """ Test that the plugin raises a warning message when the constant end points of the distribution are exceeded by a threshold value used in the forecast and the ecc_bounds_warning keyword argument has been specified. """ probabilities_for_cdf = np.array([[0.05, 0.7, 0.95]]) threshold_points = np.array([8, 10, 60]) plugin = Plugin(ecc_bounds_warning=True) warning_msg = ( "The calculated threshold values [-40 8 10 60 50] are " "not in ascending order as required for the cumulative distribution " "function (CDF). This is due to the threshold values exceeding " "the range given by the ECC bounds (-40, 50). The threshold " "points that have exceeded the existing bounds will be used as " "new bounds.") plugin._add_bounds_to_thresholds_and_probabilities( threshold_points, probabilities_for_cdf, self.bounds_pairing) self.assertTrue(any(warning_msg in str(item) for item in warning_list))
def test_bounds_of_threshold_points(self): """ Test that the plugin returns the expected results for the threshold_points, where they've been padded with the values from the bounds_pairing. """ cube = self.current_temperature_forecast_cube probabilities_for_cdf = cube.data.reshape(3, 9) bounds_pairing = (-40, 50) plugin = Plugin() result = plugin._add_bounds_to_thresholds_and_probabilities( self.threshold_points, probabilities_for_cdf, bounds_pairing) self.assertArrayAlmostEqual(result[0][0], bounds_pairing[0]) self.assertArrayAlmostEqual(result[0][-1], bounds_pairing[1])
def test_probability_data(self): """ Test that the plugin returns the expected results for the probabilities, where they've been padded with zeros and ones to represent the extreme ends of the Cumulative Distribution Function. """ cube = self.current_temperature_forecast_cube probabilities_for_cdf = cube.data.reshape(3, 9) zero_array = np.zeros(probabilities_for_cdf[:, 0].shape) one_array = np.ones(probabilities_for_cdf[:, 0].shape) bounds_pairing = (-40, 50) plugin = Plugin() result = plugin._add_bounds_to_thresholds_and_probabilities( self.threshold_points, probabilities_for_cdf, bounds_pairing) self.assertArrayAlmostEqual(result[1][:, 0], zero_array) self.assertArrayAlmostEqual(result[1][:, -1], one_array)