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.plugin = Plugin()
        self.plugin.current_forecast = self.current_temperature_forecast_cube
        self.plugin.coefficients_cubelist = self.coeffs_from_mean

    @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.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,
        )
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.plugin = Plugin()
        self.plugin.current_forecast = self.current_temperature_forecast_cube
        self.plugin.coefficients_cubelist = self.coeffs_from_mean

    @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.assertCalibratedVariablesAlmostEqual(
            location_parameter, self.expected_loc_param_mean
        )
        assert_array_almost_equal(
            location_parameter, self.expected_loc_param_realizations, decimal=0,
        )

    @ManageWarnings(ignored_messages=["Collapsing a non-contiguous coordinate."])
    def test_missing_additional_predictor(self):
        """Test that an error is raised if an additional predictor is expected
        based on the contents of the coefficients cube."""
        self.plugin.coefficients_cubelist = self.coeffs_from_mean_alt
        msg = "The number of forecast predictors must equal the number"
        with self.assertRaisesRegex(ValueError, msg):
            self.plugin._calculate_location_parameter_from_mean()