def test_too_many_coefficients(self):
        """
        Test that the plugin returns values for the coefficients,
        which match the expected values.
        """

        cube = self.current_temperature_forecast_cube
        cube1 = cube.copy()
        cube2 = cube.copy()

        cube2.coord("time").points = cube2.coord("time").points + 3
        cube2.data += 3

        cube = concatenate_cubes(CubeList([cube1, cube2]))

        optimised_coeffs = {}

        for time_slice in cube.slices_over("time"):
            the_date = datetime_from_timestamp(time_slice.coord("time").points)
            optimised_coeffs[the_date] = self.default_optimised_coeffs

        predictor_cube = cube.collapsed("realization", iris.analysis.MEAN)
        variance_cube = cube.collapsed("realization", iris.analysis.VARIANCE)

        coeff_names = ["cat", "dog", "elephant", "frog", "giraffe"]
        predictor_of_mean_flag = "mean"

        plugin = Plugin(self.cube, optimised_coeffs, coeff_names)
        msg = "Number of coefficient names"
        with self.assertRaisesRegex(ValueError, msg):
            dummy_result = plugin._apply_params(predictor_cube, variance_cube,
                                                optimised_coeffs, coeff_names,
                                                predictor_of_mean_flag)
    def test_coefficients_realizations(self):
        """
        Test that the plugin returns values for the calibrated forecasts,
        which match the expected values when the individual ensemble
        realizations are used as the predictor.
        """
        data = np.array([5.0])
        cube = self.current_temperature_forecast_cube
        cube1 = cube.copy()
        cube2 = cube.copy()

        cube2.coord("time").points = cube2.coord("time").points + 3
        cube2.data += 3

        cube = concatenate_cubes(CubeList([cube1, cube2]))

        optimised_coeffs = {}

        for time_slice in cube.slices_over("time"):
            the_date = datetime_from_timestamp(time_slice.coord("time").points)
            optimised_coeffs[the_date] = np.array([5, 1, 0, 0.57, 0.6, 0.6])
        self.coeff_names = ["gamma", "delta", "a", "beta"]

        predictor_cube = cube.copy()
        variance_cube = cube.collapsed("realization", iris.analysis.VARIANCE)

        predictor_of_mean_flag = "realizations"

        plugin = Plugin(self.cube, optimised_coeffs, self.coeff_names)
        _, _, coefficients = plugin._apply_params(predictor_cube,
                                                  variance_cube,
                                                  optimised_coeffs,
                                                  self.coeff_names,
                                                  predictor_of_mean_flag)
        self.assertArrayAlmostEqual(coefficients[0].data, data)
    def test_two_dates(self):
        """
        Test that the plugin returns a tuple when two dates are present
        within the input cube.
        """
        cube = self.current_temperature_forecast_cube
        cube1 = cube.copy()
        cube2 = cube.copy()

        cube2.coord("time").points = cube2.coord("time").points + 3
        cube2.data += 3

        cube = concatenate_cubes(CubeList([cube1, cube2]))

        optimised_coeffs = {}

        for time_slice in cube.slices_over("time"):
            the_date = datetime_from_timestamp(time_slice.coord("time").points)
            optimised_coeffs[the_date] = self.default_optimised_coeffs

        predictor_cube = cube.collapsed("realization", iris.analysis.MEAN)
        variance_cube = cube.collapsed("realization", iris.analysis.VARIANCE)

        predictor_of_mean_flag = "mean"

        plugin = Plugin(cube, optimised_coeffs, self.coeff_names)
        forecast_predictor, forecast_variance, coefficients = (
            plugin._apply_params(predictor_cube, variance_cube,
                                 optimised_coeffs, self.coeff_names,
                                 predictor_of_mean_flag))

        for result in [forecast_predictor, forecast_variance]:
            self.assertEqual(len(result), 2)
        self.assertEqual(len(coefficients), 8)
    def test_missing_date(self):
        """
        Test that the plugin returns values for the calibrated forecasts,
        if the date to be calibrated can not be found in the available
        dictionary of coefficients. In this situation, the raw forecasts are
        returned.
        """
        data = np.array([[229.48333333, 240.73333333, 251.98333333],
                         [263.23333333, 274.48333333, 285.73333333],
                         [296.98333333, 308.23333333, 319.48333333]])

        cube = self.current_temperature_forecast_cube
        optimised_coeffs = {}
        the_date = datetime_from_timestamp(cube.coord("time").points + 3)
        optimised_coeffs[the_date] = self.default_optimised_coeffs

        predictor_cube = cube.collapsed("realization", iris.analysis.MEAN)
        variance_cube = cube.collapsed("realization", iris.analysis.VARIANCE)

        predictor_of_mean_flag = "mean"

        plugin = Plugin(cube, optimised_coeffs, self.coeff_names)

        result = plugin._apply_params(predictor_cube, variance_cube,
                                      optimised_coeffs, self.coeff_names,
                                      predictor_of_mean_flag)

        self.assertArrayAlmostEqual(result[0][0].data, data)
Beispiel #5
0
 def test_basic(self):
     """Test that the plugin returns a tuple."""
     cube = self.current_temperature_forecast_cube
     plugin = Plugin(cube, self.coeffs_from_mean)
     result = plugin.process()
     self.assertIsInstance(result, tuple)
     self.assertEqual(len(result), 2)
    def test_coefficients(self):
        """
        Test that the plugin returns values for the coefficients,
        which match the expected values.
        """
        data = np.array([4.55819380e-06])

        cube = self.current_temperature_forecast_cube
        cube1 = cube.copy()
        cube2 = cube.copy()

        cube2.coord("time").points = cube2.coord("time").points + 3
        cube2.data += 3

        cube = concatenate_cubes(CubeList([cube1, cube2]))

        optimised_coeffs = {}

        for time_slice in cube.slices_over("time"):
            the_date = datetime_from_timestamp(time_slice.coord("time").points)
            optimised_coeffs[the_date] = self.default_optimised_coeffs

        predictor_cube = cube.collapsed("realization", iris.analysis.MEAN)
        variance_cube = cube.collapsed("realization", iris.analysis.VARIANCE)

        predictor_of_mean_flag = "mean"

        plugin = Plugin(self.cube, optimised_coeffs, self.coeff_names)
        _, _, coefficients = plugin._apply_params(predictor_cube,
                                                  variance_cube,
                                                  optimised_coeffs,
                                                  self.coeff_names,
                                                  predictor_of_mean_flag)
        self.assertArrayAlmostEqual(coefficients[0].data, data)
    def test_missing_date_catch_warning(self):
        """
        Test that the plugin returns values for the calibrated forecasts,
        if the date to be calibrated can not be found in the available
        dictionary of coefficients. In this situation, the raw forecasts are
        returned.
        """
        data = np.array([[229.48333333, 240.73333333, 251.98333333],
                         [263.23333333, 274.48333333, 285.73333333],
                         [296.98333333, 308.23333333, 319.48333333]])

        cube = self.current_temperature_forecast_cube
        optimised_coeffs = {}
        the_date = datetime_from_timestamp(cube.coord("time").points + 3)
        optimised_coeffs[the_date] = self.default_optimised_coeffs

        predictor_cube = cube.collapsed("realization", iris.analysis.MEAN)
        variance_cube = cube.collapsed("realization", iris.analysis.VARIANCE)

        predictor_of_mean_flag = "mean"

        plugin = Plugin(cube, optimised_coeffs, self.coeff_names)

        with warnings.catch_warnings(record=True) as warning_list:
            warnings.simplefilter("always")
            result = plugin._apply_params(predictor_cube, variance_cube,
                                          optimised_coeffs, self.coeff_names,
                                          predictor_of_mean_flag)
            self.assertTrue(len(warning_list) == 1)
            self.assertTrue(
                any(item.category == UserWarning for item in warning_list))
            self.assertTrue(
                "Ensemble calibration not available" in str(warning_list[0]))
    def test_calibrated_variance(self):
        """
        Test that the plugin returns the expected values for the calibrated
        ensemble variance when the ensemble mean is used as the predictor.
        Check that the calibrated variance is similar to when the ensemble
        realizations are used as the predictor.
        """
        cube = self.current_temperature_forecast_cube

        predictor_cube = cube.collapsed("realization", iris.analysis.MEAN)
        variance_cube = cube.collapsed("realization", iris.analysis.VARIANCE)

        plugin = Plugin(cube, self.coeffs_from_mean)
        _, forecast_variance = (
            plugin._apply_params(predictor_cube, variance_cube))
        self.assertCalibratedVariablesAlmostEqual(
            forecast_variance.data, self.expected_calibrated_variance_mean)
        self.assertArrayAlmostEqual(
            forecast_variance.data,
            self.expected_calibrated_variance_statsmodels_realizations,
            decimal=0)
        self.assertArrayAlmostEqual(
            forecast_variance.data,
            self.expected_calibrated_variance_no_statsmodels_realizations,
            decimal=0)
    def test_missing_date_catch_warning(self, warning_list=None):
        """
        Test that the plugin returns values for the calibrated forecasts,
        if the date to be calibrated can not be found in the available
        dictionary of coefficients. In this situation, the raw forecasts are
        returned.
        """

        cube = self.current_temperature_forecast_cube
        optimised_coeffs = {}
        the_date = datetime_from_timestamp(cube.coord("time").points + 3)
        optimised_coeffs[the_date] = self.default_optimised_coeffs

        predictor_cube = cube.collapsed("realization", iris.analysis.MEAN)
        variance_cube = cube.collapsed("realization", iris.analysis.VARIANCE)

        predictor_of_mean_flag = "mean"

        plugin = Plugin(cube, optimised_coeffs, self.coeff_names)

        dummy_result = plugin._apply_params(predictor_cube, variance_cube,
                                            optimised_coeffs, self.coeff_names,
                                            predictor_of_mean_flag)

        self.assertTrue(len(warning_list) == 1)
        self.assertTrue(
            any(item.category == UserWarning for item in warning_list))
        self.assertTrue(
            "Ensemble calibration not available" in str(warning_list[0]))
Beispiel #10
0
 def test_length_one_coords_list_of_coords(self):
     """Test that the plugin returns a DimCoord inside the list."""
     plugin = Plugin(self.cube, self.optimised_coeffs,
                     self.coeff_names)
     result = plugin._find_coords_of_length_one(
         self.cube, add_dimension=False)
     self.assertIsInstance(result[0], DimCoord)
    def test_calibrated_predictor(self):
        """
        Test that the plugin returns values for the calibrated predictor (the
        calibrated mean), which match the expected values.
        """
        data = np.array([[231.15002913, 242.40003036, 253.6500316],
                         [264.90003284, 276.15003408, 287.40003531],
                         [298.65003655, 309.90003779, 321.15003903]])

        cube = self.current_temperature_forecast_cube
        cube1 = cube.copy()
        cube2 = cube.copy()

        cube2.coord("time").points = cube2.coord("time").points + 3
        cube2.data += 3

        cube = concatenate_cubes(CubeList([cube1, cube2]))

        optimised_coeffs = {}

        for time_slice in cube.slices_over("time"):
            the_date = datetime_from_timestamp(time_slice.coord("time").points)
            optimised_coeffs[the_date] = self.default_optimised_coeffs

        predictor_cube = cube.collapsed("realization", iris.analysis.MEAN)
        variance_cube = cube.collapsed("realization", iris.analysis.VARIANCE)

        predictor_of_mean_flag = "mean"

        plugin = Plugin(self.cube, optimised_coeffs, self.coeff_names)
        forecast_predictor, _, _ = plugin._apply_params(
            predictor_cube, variance_cube, optimised_coeffs, self.coeff_names,
            predictor_of_mean_flag)
        self.assertArrayAlmostEqual(forecast_predictor[0].data, data)
class Test___create_coefficient_cube(IrisTest):
    """Test the __create_coefficient_cube method."""
    def setUp(self):
        """Use temperature cube to test with."""
        self.cube = set_up_temperature_cube()
        self.optimised_coeffs = [
            4.55819380e-06, -8.02401974e-09, 1.66667055e+00, 1.00000011e+00
        ]
        self.coeff_names = ["gamma", "delta", "a", "beta"]
        self.plugin = Plugin(self.cube, self.optimised_coeffs,
                             self.coeff_names)

    def test_basic(self):
        """Test that the plugin returns a CubeList."""
        result = self.plugin._create_coefficient_cube(self.cube,
                                                      self.optimised_coeffs,
                                                      self.coeff_names)
        self.assertIsInstance(result, CubeList)

    def test_number_of_coefficients(self):
        """
        Test that the plugin returns the expected number of coefficient names.
        """
        result = self.plugin._create_coefficient_cube(self.cube,
                                                      self.optimised_coeffs,
                                                      self.coeff_names)
        self.assertEqual(len(result), len(self.coeff_names))

    def test_coefficient_data_in_cube(self):
        """
        Test that the plugin returns the expected data for each coefficient.
        """
        self.optimised_coeffs = [
            4.55819380e-06, -8.02401974e-09, 1.66667055e+00
        ]
        self.coeff_names = ["cat", "dog", "elephant"]
        results = self.plugin._create_coefficient_cube(self.cube,
                                                       self.optimised_coeffs,
                                                       self.coeff_names)
        for result, coeff in zip(results, self.optimised_coeffs):
            self.assertEqual(result.data, coeff)

    def test_coefficient_name_in_cube(self):
        """
        Test that the plugin returns the expected coefficient name
        for each coefficient.
        """
        self.optimised_coeffs = [
            4.55819380e-06, -8.02401974e-09, 1.66667055e+00
        ]
        self.coeff_names = ["cat", "dog", "elephant"]
        results = self.plugin._create_coefficient_cube(self.cube,
                                                       self.optimised_coeffs,
                                                       self.coeff_names)
        for result, coeff_name in zip(results, self.coeff_names):
            self.assertEqual(result.long_name, coeff_name)
Beispiel #13
0
 def test_output_is_variance(self):
     """
     Test that the plugin returns a tuple containing cubes with a
     variance cell method.
     """
     cube = self.current_temperature_forecast_cube
     plugin = Plugin(cube, self.coeffs_from_mean)
     _, forecast_variance = plugin.process()
     for cell_method in forecast_variance[0].cell_methods:
         self.assertEqual(cell_method.method, "variance")
Beispiel #14
0
 def test_output_is_mean(self):
     """
     Test that the plugin returns a tuple containing cubes with a
     mean cell method.
     """
     cube = self.current_temperature_forecast_cube
     plugin = Plugin(cube, self.coeffs_from_mean)
     forecast_predictor, _ = plugin.process()
     for cell_method in forecast_predictor[0].cell_methods:
         self.assertEqual(cell_method.method, "mean")
 def test_basic_realizations(self):
     """
     Test that the plugin returns a tuple when using the ensemble
     realizations as the predictor of the mean.
     """
     cube = self.current_temperature_forecast_cube
     plugin = Plugin(cube, self.coeffs_from_statsmodels_realizations,
                     predictor_of_mean_flag="realizations")
     result = plugin.process()
     self.assertIsInstance(result, tuple)
     self.assertEqual(len(result), 2)
Beispiel #16
0
    def test_basic(self):
        """Test that the plugin returns a tuple."""
        cube = self.current_temperature_forecast_cube

        predictor_cube = cube.collapsed("realization", iris.analysis.MEAN)
        variance_cube = cube.collapsed("realization", iris.analysis.VARIANCE)

        plugin = Plugin(cube, self.coeffs_from_mean)
        result = plugin._apply_params(predictor_cube, variance_cube)
        self.assertIsInstance(result, tuple)
        self.assertEqual(len(result), 2)
 def test_basic(self):
     """Test that the plugin returns a tuple."""
     cube = self.current_temperature_forecast_cube
     optimised_coeffs = {}
     the_date = datetime_from_timestamp(cube.coord("time").points)
     optimised_coeffs[the_date] = [
         4.55819380e-06, -8.02401974e-09, 1.66667055e+00, 1.00000011e+00
     ]
     plugin = Plugin(cube, optimised_coeffs, self.coeff_names)
     result = plugin.apply_params_entry()
     self.assertIsInstance(result, tuple)
     self.assertEqual(len(result), 3)
 def test_output_is_variance(self):
     """
     Test that the plugin returns a tuple containing cubes with a
     variance cell method.
     """
     cube = self.current_temperature_forecast_cube
     optimised_coeffs = {}
     the_date = datetime_from_timestamp(cube.coord("time").points)
     optimised_coeffs[the_date] = [
         4.55819380e-06, -8.02401974e-09, 1.66667055e+00, 1.00000011e+00
     ]
     plugin = Plugin(cube, optimised_coeffs, self.coeff_names)
     _, forecast_variance, _ = plugin.apply_params_entry()
     for cell_method in forecast_variance[0].cell_methods:
         self.assertEqual(cell_method.method, "variance")
Beispiel #19
0
class Test__calculate_location_parameter_from_mean(
        SetupCoefficientsCubes, EnsembleCalibrationAssertions):
    """Test the __calculate_location_parameter_from_mean method."""
    def setUp(self):
        """Set-up coefficients and plugin for testing."""
        super().setUp()

        self.optimised_coeffs = (dict(
            zip(
                self.coeffs_from_mean.coord("coefficient_name").points,
                self.coeffs_from_mean.data)))
        self.plugin = Plugin()
        self.plugin.current_forecast = self.current_temperature_forecast_cube

    @ManageWarnings(
        ignored_messages=["Collapsing a non-contiguous coordinate."])
    def test_basic(self):
        """Test that the expected values for the location parameter are
        calculated when using the ensemble mean. These expected values are
        compared to the results when using the ensemble realizations to ensure
        that the results are similar."""
        location_parameter = (
            self.plugin._calculate_location_parameter_from_mean(
                self.optimised_coeffs))
        self.assertCalibratedVariablesAlmostEqual(location_parameter,
                                                  self.expected_loc_param_mean)
        assert_array_almost_equal(
            location_parameter,
            self.expected_loc_param_statsmodels_realizations,
            decimal=0)
        assert_array_almost_equal(
            location_parameter,
            self.expected_loc_param_no_statsmodels_realizations,
            decimal=0)
Beispiel #20
0
 def setUp(self):
     """Set up some simple data for testing the merging functionality."""
     self.original_data = np.ones((5, 5), dtype=np.float32)
     self.calibrated_data = np.ones((5, 5), dtype=np.float32) * 2
     self.mask = np.ones((5, 5))
     self.mask[1:-1, 1:-1] = 0
     self.plugin = Plugin()
Beispiel #21
0
    def test_calibrated_predictor(self):
        """
        Test that the plugin returns values for the calibrated predictor (the
        calibrated mean), which match the expected values.
        """
        data = np.array([[231.15001794, 242.40001917, 253.65002041],
                         [264.90000639, 276.15000763, 287.40000887],
                         [298.6500101, 309.90001134, 321.15001258]])
        cube = self.current_temperature_forecast_cube
        predictor_cube = cube.collapsed("realization", iris.analysis.MEAN)
        variance_cube = cube.collapsed("realization", iris.analysis.VARIANCE)

        plugin = Plugin(cube, self.coeffs_from_mean)
        forecast_predictor, _ = (plugin._apply_params(predictor_cube,
                                                      variance_cube))
        self.assertArrayAlmostEqual(forecast_predictor.data, data)
 def test_check_all_coords(self):
     """Test that the plugin returns a DimCoord inside the list."""
     current_temperature_forecast_cube = (
         add_forecast_reference_time_and_forecast_period(
             set_up_temperature_cube()))
     plugin = Plugin(current_temperature_forecast_cube,
                     self.optimised_coeffs, self.coeff_names)
     results = plugin._find_coords_of_length_one(
         current_temperature_forecast_cube, add_dimension=False)
     coord_names = [result.name() for result in results]
     for coord_name in [
             "time", "forecast_period", "forecast_reference_time"
     ]:
         self.assertIn(coord_name, coord_names)
     for result in results:
         self.assertIsInstance(result, DimCoord)
Beispiel #23
0
class Test__get_calibrated_forecast_predictors_mean(
        SetupCoefficientsCubes, EnsembleCalibrationAssertions):
    """Test the _get_calibrated_forecast_predictors_mean method."""
    def setUp(self):
        """Setup cubes and sundries for testing calibration of mean."""
        super().setUp()
        self.optimised_coeffs = (dict(
            zip(
                self.coeffs_from_mean.coord("coefficient_name").points,
                self.coeffs_from_mean.data)))
        self.plugin = Plugin()
        self.plugin.current_forecast = self.current_temperature_forecast_cube

        self.expected_calibrated_predictor_mean = (
            self.expected_calibrated_predictor_mean.flatten())

    @ManageWarnings(
        ignored_messages=["Collapsing a non-contiguous coordinate."])
    def test_basic(self):
        """
        Test that the expected values are returned by this function.
        """
        expected_forecast_predictors = (
            self.current_temperature_forecast_cube.collapsed(
                "realization", iris.analysis.MEAN))
        predicted_mean, forecast_predictors = (
            self.plugin._get_calibrated_forecast_predictors_mean(
                self.optimised_coeffs))
        self.assertCalibratedVariablesAlmostEqual(
            predicted_mean, self.expected_calibrated_predictor_mean)
        self.assertCalibratedVariablesAlmostEqual(
            forecast_predictors.data, expected_forecast_predictors.data)
Beispiel #24
0
 def setUp(self):
     """Use temperature cube to test with."""
     self.cube = set_up_temperature_cube()
     self.optimised_coeffs = [4.55819380e-06, -8.02401974e-09,
                              1.66667055e+00, 1.00000011e+00]
     self.coeff_names = ["gamma", "delta", "a", "beta"]
     self.plugin = Plugin(self.cube, self.optimised_coeffs,
                          self.coeff_names)
Beispiel #25
0
 def test_basic_realizations(self):
     """
     Test that the plugin returns a tuple when using the ensemble
     realizations as the predictor of the mean.
     """
     cube = self.current_temperature_forecast_cube
     optimised_coeffs = {}
     the_date = datetime_from_timestamp(cube.coord("time").points)
     optimised_coeffs[the_date] = np.array([
         4.55819380e-06, -8.02401974e-09, 1.66667055e+00, 1.00000011e+00,
         1.00000011e+00, 1.00000011e+00])
     plugin = Plugin(cube, optimised_coeffs,
                     self.coeff_names,
                     predictor_of_mean_flag="realizations")
     result = plugin.apply_params_entry()
     self.assertIsInstance(result, tuple)
     self.assertEqual(len(result), 3)
 def test_output_coefficients(self):
     """
     Test that the plugin returns a tuple containing cubes with the
     expected coefficient names.
     """
     cube = self.current_temperature_forecast_cube
     optimised_coeffs = {}
     the_date = datetime_from_timestamp(cube.coord("time").points)
     optimised_coeffs[the_date] = [
         4.55819380e-06, -8.02401974e-09, 1.66667055e+00, 1.00000011e+00
     ]
     plugin = Plugin(cube, optimised_coeffs, self.coeff_names)
     _, _, coefficients = plugin.apply_params_entry()
     for result, coeff_name, coeff in zip(coefficients, self.coeff_names,
                                          optimised_coeffs[the_date]):
         self.assertEqual(result.long_name, coeff_name)
         self.assertArrayAlmostEqual(result.data, coeff)
Beispiel #27
0
    def test_calibrated_variance(self):
        """
        Test that the plugin returns values for the calibrated variance,
        which match the expected values.
        """
        data = np.array([[2.07777316e-11, 2.07777316e-11, 2.07777316e-11],
                         [2.07777316e-11, 2.07777316e-11, 2.07777316e-11],
                         [2.07777316e-11, 2.07777316e-11, 2.07777316e-11]])

        cube = self.current_temperature_forecast_cube

        predictor_cube = cube.collapsed("realization", iris.analysis.MEAN)
        variance_cube = cube.collapsed("realization", iris.analysis.VARIANCE)

        plugin = Plugin(cube, self.coeffs_from_mean)
        _, forecast_variance = (plugin._apply_params(predictor_cube,
                                                     variance_cube))
        self.assertArrayAlmostEqual(forecast_variance.data, data)
    def test_basic(self):
        """Test that the plugin returns a tuple."""
        optimised_coeffs = {}
        cube = self.current_temperature_forecast_cube
        the_date = datetime_from_timestamp(cube.coord("time").points)
        optimised_coeffs[the_date] = self.default_optimised_coeffs

        predictor_cube = cube.collapsed("realization", iris.analysis.MEAN)
        variance_cube = cube.collapsed("realization", iris.analysis.VARIANCE)

        predictor_of_mean_flag = "mean"

        plugin = Plugin(cube, optimised_coeffs, self.coeff_names)
        result = plugin._apply_params(predictor_cube, variance_cube,
                                      optimised_coeffs, self.coeff_names,
                                      predictor_of_mean_flag)
        self.assertIsInstance(result, tuple)
        self.assertEqual(len(result), 3)
Beispiel #29
0
    def setUp(self):
        """Set-up coefficients and plugin for testing."""
        super().setUp()

        self.optimised_coeffs = (dict(
            zip(
                self.coeffs_from_mean.coord("coefficient_name").points,
                self.coeffs_from_mean.data)))
        self.plugin = Plugin()
        self.plugin.current_forecast = self.current_temperature_forecast_cube
Beispiel #30
0
 def test_output_coefficients_realizations(self):
     """
     Test that the plugin returns a tuple containing cubes with the
     expected coefficient names when using ensemble realizations as the
     predictor of the mean.
     """
     cube = self.current_temperature_forecast_cube
     optimised_coeffs = {}
     the_date = datetime_from_timestamp(cube.coord("time").points)
     optimised_coeffs[the_date] = np.array([
         4.55819380e-06, -8.02401974e-09, 1.66667055e+00, 1.00000011e+00,
         1.00000011e+00, 1.00000011e+00])
     plugin = Plugin(cube, optimised_coeffs,
                     self.coeff_names,
                     predictor_of_mean_flag="realizations")
     _, _, coefficients = plugin.apply_params_entry()
     for result, coeff_name, coeff in zip(
             coefficients, self.coeff_names, optimised_coeffs[the_date]):
         self.assertEqual(result.long_name, coeff_name)
         self.assertArrayAlmostEqual(result.data, coeff)