def test_realization_for_equal(self): """ Test to check the behaviour whether the number of percentiles equals the number of members. For when the length of the percentiles equals the length of the members, check that the points of the realization coordinate is as expected. """ data = [0, 1, 2] post_processed_forecast_percentiles = self.percentile_cube raw_forecast_members = self.realization_cube plu = Plugin() result = plu._recycle_raw_ensemble_members( post_processed_forecast_percentiles, raw_forecast_members) self.assertIsInstance(result, Cube) self.assertArrayAlmostEqual(data, result.coord("realization").points)
def test_realization_for_greater_than_check_data_lots_of_members(self): """ Test to check the behaviour whether the number of percentiles is greater than the number of members. For when the length of the percentiles is greater than the length of the members, check that the points of the realization coordinate is as expected. """ data = np.tile(np.linspace(5, 10, 9), 9).reshape(9, 1, 3, 3) data[0] -= 1 data[1] += 1 data[2] += 3 cube = set_up_cube(data, "air_temperature", "degreesC", realizations=np.arange(0, 9)) self.realization_cube = ( add_forecast_reference_time_and_forecast_period(cube.copy())) cube.coord("realization").rename(self.perc_coord) self.percentile_cube = ( add_forecast_reference_time_and_forecast_period(cube)) expected = np.array([[[[4., 4.625, 5.25], [5.875, 6.5, 7.125], [7.75, 8.375, 9.]], [[6., 6.625, 7.25], [7.875, 8.5, 9.125], [9.75, 10.375, 11.]], [[4., 4.625, 5.25], [5.875, 6.5, 7.125], [7.75, 8.375, 9.]], [[6., 6.625, 7.25], [7.875, 8.5, 9.125], [9.75, 10.375, 11.]], [[4., 4.625, 5.25], [5.875, 6.5, 7.125], [7.75, 8.375, 9.]], [[6., 6.625, 7.25], [7.875, 8.5, 9.125], [9.75, 10.375, 11.]], [[4., 4.625, 5.25], [5.875, 6.5, 7.125], [7.75, 8.375, 9.]], [[6., 6.625, 7.25], [7.875, 8.5, 9.125], [9.75, 10.375, 11.]], [[4., 4.625, 5.25], [5.875, 6.5, 7.125], [7.75, 8.375, 9.]]]]) post_processed_forecast_percentiles = self.percentile_cube raw_forecast_members = self.realization_cube raw_forecast_members = raw_forecast_members[:2, :, :, :] plu = Plugin() result = plu._recycle_raw_ensemble_members( post_processed_forecast_percentiles, raw_forecast_members, self.perc_coord) self.assertArrayAlmostEqual(expected, result.data)
def test_realization_for_less_than_check_data(self): """ Test to check the behaviour whether the number of percentiles is less than the number of members. For when the length of the percentiles is less than the length of the members, check that the points of the realization coordinate is as expected. """ data = np.array([[[[4., 4.625, 5.25], [5.875, 6.5, 7.125], [7.75, 8.375, 9.]], [[6., 6.625, 7.25], [7.875, 8.5, 9.125], [9.75, 10.375, 11.]]]]) post_processed_forecast_percentiles = self.percentile_cube raw_forecast_members = self.realization_cube post_processed_forecast_percentiles = ( post_processed_forecast_percentiles[:2, :, :, :]) plu = Plugin() result = plu._recycle_raw_ensemble_members( post_processed_forecast_percentiles, raw_forecast_members) self.assertArrayAlmostEqual(data, result.data)