Esempio n. 1
0
 def test_realization_for_greater_than_check_data(self):
     """
     Test to check the behaviour whether the number of percentiles is
     greater than the number of realizations. For when the length of the
     percentiles is greater than the length of the realizations, 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.]],
                       [[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_realizations = self.realization_cube
     # Slice number of raw forecast realizations, so that there are fewer
     # realizations than percentiles.
     raw_forecast_realizations = raw_forecast_realizations[:2, :, :, :]
     plu = Plugin()
     result = plu._recycle_raw_ensemble_realizations(
         post_processed_forecast_percentiles, raw_forecast_realizations,
         self.perc_coord)
     self.assertArrayAlmostEqual(data, result.data)
Esempio n. 2
0
    def test_realization_for_equal_check_data(self):
        """
        Test to check the behaviour whether the number of percentiles equals
        the number of realizations. For when the length of the percentiles
        equals the length of the realizations, check that the points of the
        realization coordinate is as expected.
        """
        data = [0, 1, 2]
        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.]]],
                         [[[8., 8.625, 9.25],
                           [9.875, 10.5, 11.125],
                           [11.75, 12.375, 13.]]]])

        post_processed_forecast_percentiles = self.percentile_cube
        raw_forecast_realizations = self.realization_cube
        plu = Plugin()
        result = plu._recycle_raw_ensemble_realizations(
            post_processed_forecast_percentiles, raw_forecast_realizations,
            self.perc_coord)
        self.assertArrayAlmostEqual(data, result.data)
Esempio n. 3
0
    def test_realization_for_greater_than_check_data_many_realizations(self):
        """
        Test to check the behaviour whether the number of percentiles is
        greater than the number of realizations. For when the length of the
        percentiles is greater than the length of the realizations, 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_realizations = self.realization_cube
        raw_forecast_realizations = raw_forecast_realizations[:2, :, :, :]
        plu = Plugin()
        result = plu._recycle_raw_ensemble_realizations(
            post_processed_forecast_percentiles, raw_forecast_realizations,
            self.perc_coord)
        self.assertArrayAlmostEqual(expected, result.data)
Esempio n. 4
0
 def test_realization_for_equal(self):
     """
     Test to check the behaviour whether the number of percentiles equals
     the number of realizations. For when the length of the percentiles
     equals the length of the realizations, check that the points of the
     realization coordinate is as expected.
     """
     data = [0, 1, 2]
     post_processed_forecast_percentiles = self.percentile_cube
     raw_forecast_realizations = self.realization_cube
     plu = Plugin()
     result = plu._recycle_raw_ensemble_realizations(
         post_processed_forecast_percentiles, raw_forecast_realizations,
         self.perc_coord)
     self.assertIsInstance(result, Cube)
     self.assertArrayAlmostEqual(data, result.coord("realization").points)