def test_unknown_calibration_method(self):
     """
     Test that the plugin raises an error if an unknown calibration method
     is requested.
     The ensemble mean is the predictor.
     """
     calibration_method = "unknown"
     distribution = "gaussian"
     desired_units = "degreesC"
     plugin = Plugin(calibration_method, distribution, desired_units)
     msg = "unknown"
     with self.assertRaisesRegexp(ValueError, msg):
         plugin.process(self.current_temperature_forecast_cube,
                        self.historic_temperature_forecast_cube,
                        self.temperature_truth_cube)
Ejemplo n.º 2
0
 def test_wind_speed_data_check(self):
     """
     Test that the plugin returns an iris.cube.CubeList
     of wind_speed cubes with the expected data, where the plugin
     returns a cubelist of, firstly, the predictor and, secondly the
     variance.
     The ensemble mean is the predictor.
     """
     predictor_data = np.array(
         [[2.9999862, 10.49998827, 17.99999034],
          [25.4999924, 32.99999447, 40.49999654],
          [47.99999861, 55.50000068, 63.00000275]])
     variance_data = np.array(
         [[0., 0., 0.],
          [0., 0., 0.],
          [0., 0., 0.]])
     calibration_method = "ensemble model output_statistics"
     distribution = "truncated gaussian"
     desired_units = "m s^-1"
     plugin = Plugin(calibration_method, distribution, desired_units)
     result = plugin.process(
         self.current_wind_speed_forecast_cube,
         self.historic_wind_speed_forecast_cube,
         self.wind_speed_truth_cube)
     self.assertArrayAlmostEqual(result[0][0].data, predictor_data)
     self.assertArrayAlmostEqual(result[1][0].data, variance_data)
Ejemplo n.º 3
0
 def test_temperature_data_check(self):
     """
     Test that the plugin returns an iris.cube.CubeList
     of temperature cubes with the expected data, where the plugin
     returns a cubelist of, firstly, the predictor and, secondly the
     variance.
     The ensemble mean is the predictor.
     """
     predictor_data = np.array(
         [[231.15002892, 242.40003015, 253.65003137],
          [264.9000326, 276.15003383, 287.40003505],
          [298.65003628, 309.90003751, 321.15003874]])
     variance_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]])
     calibration_method = "ensemble model output_statistics"
     distribution = "gaussian"
     desired_units = "degreesC"
     plugin = Plugin(calibration_method, distribution, desired_units)
     result = plugin.process(
         self.current_temperature_forecast_cube,
         self.historic_temperature_forecast_cube,
         self.temperature_truth_cube)
     self.assertArrayAlmostEqual(result[0][0].data, predictor_data)
     self.assertArrayAlmostEqual(result[1][0].data, variance_data)
 def test_truncated_gaussian_realizations_data_check(self):
     """
     Test that the plugin returns an iris.cube.CubeList
     of wind_speed cubes with the expected data, where the plugin
     returns a cubelist of, firstly, the predictor and, secondly the
     variance. The ensemble realizations are the predictor.
     """
     distribution = "truncated gaussian"
     predictor_of_mean_flag = "realizations"
     plugin = Plugin(distribution,
                     predictor_of_mean_flag=predictor_of_mean_flag)
     calibrated_predictor, calibrated_variance = plugin.process(
         self.current_wind_speed_forecast_cube,
         self.historic_wind_speed_forecast_cube, self.wind_speed_truth_cube)
     self.assertCalibratedVariablesAlmostEqual(
         calibrated_predictor.data,
         self.expected_truncated_gaussian_realization_no_statsmodels)
     self.assertCalibratedVariablesAlmostEqual(
         calibrated_variance.data,
         self.expected_truncated_gaussian_variance_no_statsmodels)
     # The assertions below are for comparison to the results
     # generated from using the ensemble mean as the predictor.
     # In this case, the expectation is for there to be broad agreement
     # between whether either the ensemble mean or the ensemble
     # realizations, but the results would not be expected to match exactly.
     self.assertArrayAlmostEqual(calibrated_predictor.data,
                                 self.expected_truncated_gaussian_mean_data,
                                 decimal=0)
     self.assertArrayAlmostEqual(
         calibrated_variance.data,
         self.expected_truncated_gaussian_variance_data,
         decimal=0)
 def test_basic_truncated_gaussian(self):
     """
     Test that the plugin returns an iris.cube.CubeList
     with the desired length. The ensemble mean is the predictor.
     """
     distribution = "truncated gaussian"
     plugin = Plugin(distribution)
     result = plugin.process(self.current_wind_speed_forecast_cube,
                             self.historic_wind_speed_forecast_cube,
                             self.wind_speed_truth_cube)
     self.assertIsInstance(result, tuple)
     self.assertEqual(len(result), 2)
Ejemplo n.º 6
0
 def test_temperature_realizations_data_check(self):
     """
     Test that the plugin returns an iris.cube.CubeList
     of temperature cubes with the expected data, where the plugin
     returns a cubelist of, firstly, the predictor and, secondly the
     variance.
     The ensemble realizations is the predictor.
     """
     import imp
     try:
         imp.find_module('statsmodels')
         statsmodels_found = True
         import statsmodels.api as sm
         self.sm = sm
     except ImportError:
         statsmodels_found = False
     if statsmodels_found:
         predictor_data = np.array(
             [[231.1493, 242.3992, 253.6492], [264.8991, 276.149, 287.399],
              [298.649, 309.8989, 321.1488]],
             dtype=np.float32)
         variance_data = np.array([[0.000001, 0.000001, 0.000001],
                                   [0.000001, 0.000001, 0.000001],
                                   [0.000001, 0.000001, 0.000001]],
                                  dtype=np.float32)
     else:
         predictor_data = np.array(
             [[230.53659896, 241.80363361, 253.07066826],
              [264.33770292, 275.60473757, 286.87177222],
              [298.13880687, 309.40584153, 320.67287618]],
             dtype=np.float32)
         variance_data = np.array([[18.04589231, 18.04589231, 18.04589231],
                                   [18.04589231, 18.04589231, 18.04589231],
                                   [18.04589231, 18.04589231, 18.04589231]],
                                  dtype=np.float32)
     calibration_method = "ensemble model output_statistics"
     distribution = "gaussian"
     desired_units = "degreesC"
     predictor_of_mean_flag = "realizations"
     plugin = Plugin(calibration_method,
                     distribution,
                     desired_units,
                     predictor_of_mean_flag=predictor_of_mean_flag)
     calibrated_predictor, calibrated_variance = plugin.process(
         self.current_temperature_forecast_cube,
         self.historic_temperature_forecast_cube,
         self.temperature_truth_cube)
     self.assertArrayAlmostEqual(calibrated_predictor.data,
                                 predictor_data,
                                 decimal=4)
     self.assertArrayAlmostEqual(calibrated_variance.data,
                                 variance_data,
                                 decimal=4)
 def test_alternative_calibration_name(self):
     """
     Test that the plugin returns an iris.cube.CubeList.
     The ensemble mean is the predictor.
     """
     calibration_method = "nonhomogeneous gaussian regression"
     distribution = "gaussian"
     desired_units = "degreesC"
     plugin = Plugin(calibration_method, distribution, desired_units)
     result = plugin.process(self.current_temperature_forecast_cube,
                             self.historic_temperature_forecast_cube,
                             self.temperature_truth_cube)
     self.assertIsInstance(result, CubeList)
 def test_basic_gaussian_realizations(self):
     """
     Test that the plugin returns an iris.cube.CubeList
     with the desired length. The ensemble realizations is the predictor.
     """
     distribution = "gaussian"
     predictor_of_mean_flag = "realizations"
     plugin = Plugin(distribution,
                     predictor_of_mean_flag=predictor_of_mean_flag)
     result = plugin.process(self.current_temperature_forecast_cube,
                             self.historic_temperature_forecast_cube,
                             self.temperature_truth_cube)
     self.assertIsInstance(result, tuple)
     self.assertEqual(len(result), 2)
 def test_basic_temperature(self):
     """
     Test that the plugin returns an iris.cube.CubeList
     with the desired length.
     The ensemble mean is the predictor.
     """
     calibration_method = "ensemble model output statistics"
     distribution = "gaussian"
     desired_units = "degreesC"
     plugin = Plugin(calibration_method, distribution, desired_units)
     result = plugin.process(self.current_temperature_forecast_cube,
                             self.historic_temperature_forecast_cube,
                             self.temperature_truth_cube)
     self.assertIsInstance(result, CubeList)
     self.assertEqual(len(result), 2)
Ejemplo n.º 10
0
 def test_basic_wind_speed(self):
     """
     Test that the plugin returns an iris.cube.CubeList
     with the desired length.
     The ensemble mean is the predictor.
     """
     calibration_method = "ensemble model output_statistics"
     distribution = "truncated gaussian"
     desired_units = "m s^-1"
     plugin = Plugin(calibration_method, distribution, desired_units)
     result = plugin.process(self.current_wind_speed_forecast_cube,
                             self.historic_wind_speed_forecast_cube,
                             self.wind_speed_truth_cube)
     self.assertIsInstance(result, tuple)
     self.assertEqual(len(result), 2)
Ejemplo n.º 11
0
 def test_alternative_calibration_name(self):
     """
     Test that the plugin returns the calibrated predictor and the
     calibrated variance if an alternative name for the calibration
     is provided. The ensemble mean is the predictor.
     """
     calibration_method = "nonhomogeneous gaussian regression"
     distribution = "gaussian"
     desired_units = "degreesC"
     plugin = Plugin(calibration_method, distribution, desired_units)
     calibrated_predictor, calibrated_variance = plugin.process(
         self.current_temperature_forecast_cube,
         self.historic_temperature_forecast_cube,
         self.temperature_truth_cube)
     self.assertIsInstance(calibrated_predictor, iris.cube.Cube)
     self.assertIsInstance(calibrated_variance, iris.cube.Cube)
Ejemplo n.º 12
0
 def test_wind_speed_members_data_check(self):
     """
     Test that the plugin returns an iris.cube.CubeList
     of wind_speed cubes with the expected data, where the plugin
     returns a cubelist of, firstly, the predictor and, secondly the
     variance.
     The ensemble members is the predictor.
     """
     import imp
     try:
         statsmodels_found = imp.find_module('statsmodels')
         statsmodels_found = True
         import statsmodels.api as sm
         self.sm = sm
     except ImportError:
         statsmodels_found = False
     if statsmodels_found:
         predictor_data = np.array(
             [[3.15758874, 10.63961216, 18.12163557],
              [25.60365899, 33.08568241, 40.56770583],
              [48.04972924, 55.53175266, 63.01377608]])
         variance_data = np.array(
             [[0.01406566, 0.01406566, 0.01406566],
              [0.01406566, 0.01406566, 0.01406566],
              [0.01406566, 0.01406566, 0.01406566]])
     else:
         predictor_data = np.array(
             [[2.05799912, 9.73470204, 17.41140496],
              [25.08810788, 32.7648108, 40.44151372],
              [48.11821664, 55.79491955, 63.47162247]])
         variance_data = np.array(
             [[4.26987243, 4.26987243, 4.26987243],
              [4.26987243, 4.26987243, 4.26987243],
              [4.26987243, 4.26987243, 4.26987243]])
     calibration_method = "ensemble model output_statistics"
     distribution = "truncated gaussian"
     desired_units = "m s^-1"
     predictor_of_mean_flag = "members"
     plugin = Plugin(
         calibration_method, distribution, desired_units,
         predictor_of_mean_flag=predictor_of_mean_flag)
     result = plugin.process(
         self.current_wind_speed_forecast_cube,
         self.historic_wind_speed_forecast_cube,
         self.wind_speed_truth_cube)
     self.assertArrayAlmostEqual(result[0][0].data, predictor_data)
     self.assertArrayAlmostEqual(result[1][0].data, variance_data)
Ejemplo n.º 13
0
 def test_temperature_members_data_check(self):
     """
     Test that the plugin returns an iris.cube.CubeList
     of temperature cubes with the expected data, where the plugin
     returns a cubelist of, firstly, the predictor and, secondly the
     variance.
     The ensemble members is the predictor.
     """
     import imp
     try:
         statsmodels_found = imp.find_module('statsmodels')
         statsmodels_found = True
         import statsmodels.api as sm
         self.sm = sm
     except ImportError:
         statsmodels_found = False
     if statsmodels_found:
         predictor_data = np.array(
             [[230.72248097, 241.94440325, 253.16632553],
              [264.38824782, 275.6101701, 286.83209238],
              [298.05401466, 309.27593695, 320.49785923]])
         variance_data = np.array(
             [[0.05635014, 0.05635014, 0.05635014],
              [0.05635014, 0.05635014, 0.05635014],
              [0.05635014, 0.05635014, 0.05635014]])
     else:
         predictor_data = np.array(
             [[230.53659896, 241.80363361, 253.07066826],
              [264.33770292, 275.60473757, 286.87177222],
              [298.13880687, 309.40584153, 320.67287618]])
         variance_data = np.array(
             [[18.04589231, 18.04589231, 18.04589231],
              [18.04589231, 18.04589231, 18.04589231],
              [18.04589231, 18.04589231, 18.04589231]])
     calibration_method = "ensemble model output_statistics"
     distribution = "gaussian"
     desired_units = "degreesC"
     predictor_of_mean_flag = "members"
     plugin = Plugin(
         calibration_method, distribution, desired_units,
         predictor_of_mean_flag=predictor_of_mean_flag)
     result = plugin.process(
         self.current_temperature_forecast_cube,
         self.historic_temperature_forecast_cube,
         self.temperature_truth_cube)
     self.assertArrayAlmostEqual(result[0][0].data, predictor_data)
     self.assertArrayAlmostEqual(result[1][0].data, variance_data)
 def test_truncated_gaussian_data_check(self):
     """
     Test that the plugin returns an iris.cube.CubeList
     of wind_speed cubes with the expected data, where the plugin
     returns a cubelist of, firstly, the predictor and, secondly the
     variance. The ensemble mean is the predictor.
     """
     distribution = "truncated gaussian"
     plugin = Plugin(distribution)
     calibrated_predictor, calibrated_variance = plugin.process(
         self.current_wind_speed_forecast_cube,
         self.historic_wind_speed_forecast_cube, self.wind_speed_truth_cube)
     self.assertCalibratedVariablesAlmostEqual(
         calibrated_predictor.data,
         self.expected_truncated_gaussian_mean_data)
     self.assertCalibratedVariablesAlmostEqual(
         calibrated_variance.data,
         self.expected_truncated_gaussian_variance_data)
 def test_gaussian_data_check_max_iterations(self):
     """
     Test that the plugin returns an iris.cube.CubeList
     of temperature cubes with the expected data, where the plugin
     returns a cubelist of, firstly, the predictor and, secondly the
     variance when the maximum number of iterations is specified.
     The ensemble mean is the predictor.
     """
     distribution = "gaussian"
     plugin = Plugin(distribution, max_iterations=10000)
     calibrated_predictor, calibrated_variance = plugin.process(
         self.current_temperature_forecast_cube,
         self.historic_temperature_forecast_cube,
         self.temperature_truth_cube)
     self.assertCalibratedVariablesAlmostEqual(
         calibrated_predictor.data, self.expected_gaussian_mean_data)
     self.assertCalibratedVariablesAlmostEqual(
         calibrated_variance.data, self.expected_gaussian_variance_data)
Ejemplo n.º 16
0
 def test_wind_speed_data_check(self):
     """
     Test that the plugin returns an iris.cube.CubeList
     of wind_speed cubes with the expected data, where the plugin
     returns a cubelist of, firstly, the predictor and, secondly the
     variance.
     The ensemble mean is the predictor.
     """
     predictor_data = np.array(
         [[2.9999862, 10.499988, 17.999989],
          [25.49999, 32.999992, 40.499992], [47.999996, 55.499996, 63.]],
         dtype=np.float32)
     variance_data = np.array([[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]],
                              dtype=np.float32)
     calibration_method = "ensemble model output_statistics"
     distribution = "truncated gaussian"
     desired_units = "m s^-1"
     plugin = Plugin(calibration_method, distribution, desired_units)
     calibrated_predictor, calibrated_variance = plugin.process(
         self.current_wind_speed_forecast_cube,
         self.historic_wind_speed_forecast_cube, self.wind_speed_truth_cube)
     self.assertArrayAlmostEqual(calibrated_predictor.data, predictor_data)
     self.assertArrayAlmostEqual(calibrated_variance.data, variance_data)