def test_truncated_normal_members_predictor_max_iterations(self): """ Test that the plugin returns a list of coefficients equal to specific values, when the ensemble members are the predictor assuming a truncated normal distribution and the value specified for the MAX_ITERATIONS is overriden. The coefficients are calculated by minimising the CRPS and using a set default value for the initial guess. """ initial_guess = [5, 1, 0, 1, 1, 1] initial_guess = np.array(initial_guess, dtype=np.float32) cube = set_up_temperature_cube() forecast_predictor = cube.copy() forecast_variance = cube.collapsed("realization", iris.analysis.VARIANCE) truth = cube.collapsed("realization", iris.analysis.MAX) predictor_of_mean_flag = "members" plugin = Plugin() plugin.MAX_ITERATIONS = 400 distribution = "truncated gaussian" result = plugin.crps_minimiser_wrapper(initial_guess, forecast_predictor, truth, forecast_variance, predictor_of_mean_flag, distribution) self.assertArrayAlmostEqual( result, [5.375955, 1.45785, 0.002567, 0.193423, 0.55406, 0.811599])
def test_truncated_normal_mean_predictor_max_iterations(self): """ Test that the plugin returns a list of coefficients equal to specific values, when the ensemble mean is the predictor assuming a truncated normal distribution and the value specified for the MAX_ITERATIONS is overriden. The coefficients are calculated by minimising the CRPS and using a set default value for the initial guess. """ warnings.simplefilter("always") initial_guess = [5, 1, 0, 1] initial_guess = np.array(initial_guess, dtype=np.float32) cube = set_up_temperature_cube() forecast_predictor = cube.collapsed("realization", iris.analysis.MEAN) forecast_variance = cube.collapsed( "realization", iris.analysis.VARIANCE) truth = cube.collapsed("realization", iris.analysis.MAX) predictor_of_mean_flag = "mean" plugin = Plugin() plugin.MAX_ITERATIONS = 400 distribution = "truncated gaussian" result = plugin.crps_minimiser_wrapper( initial_guess, forecast_predictor, truth, forecast_variance, predictor_of_mean_flag, distribution) self.assertArrayAlmostEqual( result, [-0.303343, -0.022553, 0.008502, 1.009565])