コード例 #1
0
 def setUp(self):
     """Use temperature cube to test with."""
     self.cube = set_up_temperature_cube()
     self.cube_ukv = self.cube.extract(iris.Constraint(realization=1))
     self.cube_ukv.remove_coord('realization')
     self.cube_ukv.attributes.update({'grid_id': 'ukvx_standard_v1'})
     self.cube_ukv.attributes.update({'title':
                                      'Operational UKV Model Forecast'})
     self.cube_ukv_t1 = self.cube_ukv.copy()
     self.cube_ukv_t2 = self.cube_ukv.copy()
     add_forecast_reference_time_and_forecast_period(self.cube_ukv,
                                                     fp_point=4.0)
     add_forecast_reference_time_and_forecast_period(self.cube_ukv_t1,
                                                     fp_point=5.0)
     add_forecast_reference_time_and_forecast_period(self.cube_ukv_t2,
                                                     fp_point=6.0)
     add_forecast_reference_time_and_forecast_period(self.cube,
                                                     fp_point=7.0)
     self.cube.attributes.update({'grid_id': 'enukx_standard_v1'})
     self.cube.attributes.update({'title':
                                  'Operational Mogreps UK Model Forecast'})
     self.prob_ukv = set_up_probability_above_threshold_temperature_cube()
     self.prob_ukv.attributes.update({'grid_id': 'ukvx_standard_v1'})
     self.prob_ukv.attributes.update({'title':
                                      'Operational UKV Model Forecast'})
     self.prob_enuk = set_up_probability_above_threshold_temperature_cube()
     self.prob_enuk.attributes.update({'grid_id': 'enukx_standard_v1'})
     self.prob_enuk.attributes.update(
         {'title':
          'Operational Mogreps UK Model Forecast'})
コード例 #2
0
    def setUp(self):
        """Use temperature cube to test with."""
        self.cube = set_up_temperature_cube()
        self.cube_ukv = self.cube.extract(iris.Constraint(realization=1))
        self.cube_ukv.remove_coord('realization')
        self.cube_ukv.attributes['mosg__grid_type'] = 'standard'
        self.cube_ukv.attributes['mosg__model_configuration'] = 'uk_det'
        self.cube_ukv.attributes['mosg__grid_domain'] = 'uk_extended'
        self.cube_ukv.attributes['mosg__grid_version'] = '1.2.0'
        self.cube_ukv_t1 = self.cube_ukv.copy()
        self.cube_ukv_t2 = self.cube_ukv.copy()
        add_forecast_reference_time_and_forecast_period(self.cube_ukv,
                                                        fp_point=4.0)
        add_forecast_reference_time_and_forecast_period(self.cube_ukv_t1,
                                                        fp_point=5.0)
        add_forecast_reference_time_and_forecast_period(self.cube_ukv_t2,
                                                        fp_point=6.0)
        add_forecast_reference_time_and_forecast_period(self.cube,
                                                        fp_point=7.0)
        self.cube.attributes['mosg__grid_type'] = 'standard'
        self.cube.attributes['mosg__model_configuration'] = 'uk_ens'
        self.cube.attributes['mosg__grid_domain'] = 'uk_extended'
        self.cube.attributes['mosg__grid_version'] = '1.2.0'
        self.prob_ukv = set_up_probability_above_threshold_temperature_cube()
        self.prob_ukv.attributes['mosg__grid_type'] = 'standard'
        self.prob_ukv.attributes['mosg__model_configuration'] = 'uk_det'
        self.prob_ukv.attributes['mosg__grid_domain'] = 'uk_extended'
        self.prob_ukv.attributes['mosg__grid_version'] = '1.2.0'
        self.prob_enuk = set_up_probability_above_threshold_temperature_cube()
        self.prob_enuk.attributes.update({'mosg__grid_type': 'standard'})
        self.prob_enuk.attributes.update(
            {'mosg__model_configuration': 'uk_ens'})
        self.prob_enuk.attributes.update({'mosg__grid_domain': 'uk_extended'})
        self.prob_enuk.attributes.update({'mosg__grid_version': '1.2.0'})

        # Setup two non-Met Office model example configuration cubes.
        # Using a simple temperature data array, one cube set is setup
        # as a deterministic model, the other as an ensemble.
        self.data = (np.linspace(275.0, 284.0,
                                 12).reshape(3, 4).astype(np.float32))
        self.data_3d = np.array([self.data, self.data, self.data])

        self.cube_non_mo_det = set_up_variable_cube(self.data)

        self.cube_non_mo_ens = set_up_variable_cube(self.data_3d,
                                                    realizations=np.array(
                                                        [0, 3, 4]))

        self.cube_non_mo_det.attributes['non_mo_model_config'] = 'non_uk_det'
        self.cube_non_mo_ens.attributes['non_mo_model_config'] = 'non_uk_ens'
 def setUp(self):
     """Set up current_temperature_forecast_cube for testing."""
     self.current_temperature_forecast_cube = (
         add_forecast_reference_time_and_forecast_period(
             set_up_probability_above_threshold_temperature_cube()))
     self.threshold_points = find_threshold_coordinate(
         self.current_temperature_forecast_cube).points
コード例 #4
0
 def setUp(self):
     """Set up temperature cube."""
     self.current_temperature_forecast_cube = (
         add_forecast_reference_time_and_forecast_period(
             set_up_probability_above_threshold_temperature_cube()))
     self.current_temperature_spot_forecast_cube = (
         add_forecast_reference_time_and_forecast_period(
             set_up_probability_above_threshold_spot_temperature_cube()))
コード例 #5
0
 def setUp(self):
     """Set up temperature cube."""
     self.template_cube = (
         set_up_probability_above_threshold_temperature_cube())
     self.template_cube = iris.util.squeeze(self.template_cube)
     self.means = self.template_cube[0, :, :].copy()
     self.means.units = 'Celsius'
     self.variances = self.template_cube[0, :, :].copy()
     self.variances.units = 'Celsius2'
コード例 #6
0
 def test_threshold_exception(self):
     """Test that an exception is raised if a threshold coordinate is
     unmatched."""
     cube = set_up_probability_above_threshold_temperature_cube()
     cube1 = cube.copy()
     cube2 = cube.copy()
     cube2.remove_coord("threshold")
     cubes = iris.cube.CubeList([cube1, cube2])
     msg = "threshold coordinates must match to merge"
     with self.assertRaisesRegex(ValueError, msg):
         _equalise_cube_coords(cubes)
コード例 #7
0
ファイル: test_load.py プロジェクト: ellesmith88/improver
 def test_ordering_for_threshold_coordinate(self):
     """Test that the cube has been reordered, if it is originally in an
     undesirable order and the cube contains a "threshold" coordinate."""
     cube = set_up_probability_above_threshold_temperature_cube()
     cube.transpose([3, 2, 1, 0])
     save_netcdf(cube, self.filepath)
     result = load_cube(self.filepath)
     self.assertEqual(result.coord_dims("threshold")[0], 0)
     self.assertEqual(result.coord_dims("time")[0], 1)
     self.assertArrayAlmostEqual(result.coord_dims("latitude")[0], 2)
     self.assertArrayAlmostEqual(result.coord_dims("longitude")[0], 3)
コード例 #8
0
 def test_clipping_slices(self):
     """Test that the utility clips the processed cube to the same limits
     as the input cube, and that it does this when slicing over multiple
     x-y planes."""
     cube = set_up_probability_above_threshold_temperature_cube()
     minimum_value = cube.data.min()
     maximum_value = cube.data.max()
     processed_cube = cube.copy(data=cube.data * 2.0 - cube.data.mean())
     result = clip_cube_data(processed_cube, minimum_value, maximum_value)
     self.assertEqual(result.data.min(), minimum_value)
     self.assertEqual(result.data.max(), maximum_value)
     self.assertEqual(result.attributes, processed_cube.attributes)
     self.assertEqual(result.cell_methods, processed_cube.cell_methods)
コード例 #9
0
    def setUp(self):
        """Set up temperature cube."""
        self.template_cube = (
            set_up_probability_above_threshold_temperature_cube())
        self.template_cube = iris.util.squeeze(self.template_cube)

        self.template_cube.coord('threshold').points = [8.65105, 10., 11.34895]
        mean_values = np.ones((3, 3)) * 10
        variance_values = np.ones((3, 3)) * 4
        self.means = self.template_cube[0, :, :].copy(data=mean_values)
        self.means.units = 'Celsius'
        self.variances = self.template_cube[0, :, :].copy(data=variance_values)
        self.variances.units = 'Celsius2'
コード例 #10
0
    def setUp(self):
        """Set up temperature cube."""
        self.template_cube = (
            set_up_probability_above_threshold_temperature_cube())
        self.template_cube = iris.util.squeeze(self.template_cube)

        # Thresholds such that we obtain probabilities of 75%, 50%, and 25% for
        # the mean and variance values set here.
        self.template_cube.coord('threshold').points = [8.65105, 10., 11.34895]
        mean_values = np.ones((3, 3)) * 10
        variance_values = np.ones((3, 3)) * 4
        self.means = self.template_cube[0, :, :].copy(data=mean_values)
        self.means.units = 'Celsius'
        self.variances = self.template_cube[0, :, :].copy(data=variance_values)
        self.variances.units = 'Celsius2'
コード例 #11
0
    def setUp(self):
        """Set up temperature cube."""
        self.current_temperature_forecast_cube = (
            add_forecast_reference_time_and_forecast_period(
                set_up_probability_above_threshold_temperature_cube()))

        self.percentile_25 = np.array(
            [[[24., 8.75, 11.], [8.33333333, 8.75, -46.], [-46., -66.25, -73.]]
             ],
            dtype=np.float32)
        self.percentile_50 = np.array(
            [[[36., 10., 12.], [10., 10., 8.], [8., -32.5, -46.]]],
            dtype=np.float32)
        self.percentile_75 = np.array(
            [[[48., 11.66666667, 36.], [11.66666667, 11., 10.5],
              [9.66666667, 1.25, -19.]]],
            dtype=np.float32)
コード例 #12
0
ファイル: test_load.py プロジェクト: ellesmith88/improver
 def test_ordering_for_realization_threshold_percentile_over_coordinate(
         self):
     """Test that the cube has been reordered, if it is originally in an
     undesirable order and the cube contains a "threshold" coordinate,
     a "realization" coordinate and a "percentile_over" coordinate."""
     cube = set_up_probability_above_threshold_temperature_cube()
     cube = create_sample_cube_with_additional_coordinate(
         cube, "realization", [0, 1, 2])
     cube = create_sample_cube_with_additional_coordinate(
         cube, "percentile_over_neighbourhood", [10, 50, 90])
     cube.transpose([5, 4, 3, 2, 1, 0])
     save_netcdf(cube, self.filepath)
     result = load_cube(self.filepath)
     self.assertEqual(result.coord_dims("realization")[0], 0)
     self.assertEqual(
         result.coord_dims("percentile_over_neighbourhood")[0], 1)
     self.assertEqual(result.coord_dims("threshold")[0], 2)
     self.assertEqual(result.coord_dims("time")[0], 3)
     self.assertArrayAlmostEqual(result.coord_dims("latitude")[0], 4)
     self.assertArrayAlmostEqual(result.coord_dims("longitude")[0], 5)
コード例 #13
0
 def setUp(self):
     """Set up temperature cube."""
     self.cube = (set_up_probability_above_threshold_temperature_cube())