Exemple #1
0
 def test_mismatching_number_of_coefficients(self):
     """Test that an exception is raised if the number of coefficients
     provided for creating the coefficients cube is not equal to the
     number of coefficient names."""
     distribution = "truncated_gaussian"
     desired_units = "Fahrenheit"
     predictor_of_mean_flag = "realizations"
     optimised_coeffs = [1, 2, 3, 4, 5]
     plugin = Plugin(distribution=distribution,
                     current_cycle=self.current_cycle,
                     desired_units=desired_units,
                     predictor_of_mean_flag=predictor_of_mean_flag)
     msg = "The number of coefficients in"
     with self.assertRaisesRegex(ValueError, msg):
         plugin.create_coefficients_cube(
             optimised_coeffs, self.historic_forecast_with_realizations)
    def test_coefficients_from_realizations(self):
        """Test that the expected coefficient cube is returned when the
        ensemble realizations are used as the predictor."""
        expected_coeff_names = ([
            "gamma", "delta", "alpha", "beta0", "beta1", "beta2"
        ])
        predictor_of_mean_flag = "realizations"
        optimised_coeffs = [0, 1, 2, 3, 4, 5]

        # Set up an expected cube.
        coefficient_index = iris.coords.DimCoord(optimised_coeffs,
                                                 long_name="coefficient_index",
                                                 units="1")
        dim_coords_and_dims = [(coefficient_index, 0)]

        coefficient_name = iris.coords.AuxCoord(expected_coeff_names,
                                                long_name="coefficient_name",
                                                units="no_unit")

        time_point = (np.max(self.historic_forecast.coord("time").points) +
                      60 * 60 * 24)
        time_coord = self.historic_forecast.coord("time").copy(time_point)

        frt_orig_coord = (
            self.historic_forecast.coord("forecast_reference_time"))
        frt_point = np.max(frt_orig_coord.points) + 60 * 60 * 24
        frt_coord = frt_orig_coord.copy(frt_point)

        aux_coords_and_dims = [
            (coefficient_name, 0), (time_coord, None), (frt_coord, None),
            (self.historic_forecast[-1].coord("forecast_period"), None),
            (self.x_coord, None), (self.y_coord, None)
        ]

        attributes = {
            "mosg__model_configuration": "uk_det",
            "diagnostic_standard_name": "air_temperature"
        }

        expected = iris.cube.Cube(optimised_coeffs,
                                  long_name="emos_coefficients",
                                  units="1",
                                  dim_coords_and_dims=dim_coords_and_dims,
                                  aux_coords_and_dims=aux_coords_and_dims,
                                  attributes=attributes)

        plugin = Plugin(distribution=self.distribution,
                        current_cycle=self.current_cycle,
                        desired_units=self.desired_units,
                        predictor_of_mean_flag=predictor_of_mean_flag)
        result = plugin.create_coefficients_cube(
            optimised_coeffs, self.historic_forecast_with_realizations)
        self.assertEqual(result, expected)
        self.assertArrayEqual(
            result.coord("coefficient_name").points, expected_coeff_names)