示例#1
0
    def setUp(self):
        """Set up a list of cubes from different models with some probability
        data in them."""

        # make a cube with a forecast reference time and period labelled as
        # coming from the UKV
        data = np.full((3, 3), 0.6, dtype=np.float32)
        self.ukv_cube = set_up_variable_cube(
            data,
            name='probability_of_air_temperature_above_threshold',
            units='1',
            time=dt(2017, 1, 10, 3, 0),
            frt=dt(2017, 1, 9, 23, 0),
            standard_grid_metadata='uk_det')

        # make a cube labelled as coming from MOGREPS-UK, with a different
        # forecast reference time from the UKV cube
        self.enuk_cube = set_up_variable_cube(
            data,
            name='probability_of_air_temperature_above_threshold',
            units='1',
            time=dt(2017, 1, 10, 3, 0),
            frt=dt(2017, 1, 10, 0, 0),
            standard_grid_metadata='uk_ens')

        # make a cube list and merged cube containing the two model cubes, for
        # use in defining reference coordinates for tests below
        self.cubelist = iris.cube.CubeList([self.ukv_cube, self.enuk_cube])

        # set up a plugin for multi-model blending
        self.plugin = MergeCubesForWeightedBlending(
            "model",
            weighting_coord="forecast_period",
            model_id_attr="mosg__model_configuration")
示例#2
0
    def setUp(self):
        """Set up the test inputs spanning sunrise."""
        self.time_0 = datetime.datetime(2017, 11, 1, 6)
        self.time_mid = datetime.datetime(2017, 11, 1, 8)
        self.npoints = 10
        self.daynight_mask = np.array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
                                       [0, 1, 1, 1, 1, 1, 1, 1, 1, 1],
                                       [0, 1, 1, 1, 1, 1, 1, 1, 1, 1],
                                       [0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
                                       [0, 0, 0, 1, 1, 1, 1, 1, 1, 1],
                                       [0, 0, 0, 0, 1, 1, 1, 1, 1, 1],
                                       [0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
                                       [0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
                                       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])

        data_time_mid = np.ones(
            (self.npoints, self.npoints), dtype=np.float32) * 4

        interp_cube = set_up_variable_cube(data_time_mid,
                                           time=self.time_mid,
                                           frt=self.time_0)
        self.interpolated_cube = iris.util.new_axis(interp_cube, 'time')

        data_time_mid_ens = np.ones(
            (3, self.npoints, self.npoints), dtype=np.float32) * 4
        interp_cube_ens = set_up_variable_cube(data_time_mid_ens,
                                               time=self.time_mid,
                                               frt=self.time_0,
                                               realizations=[0, 1, 2])
        self.interpolated_cube_ens = iris.util.new_axis(
            interp_cube_ens, 'time')
示例#3
0
    def setUp(self):
        """Create cubes with a single zero prob(precip) point.
        The cubes look like this:
        precipitation_amount / (kg m^-2)
        Dimension coordinates:
            projection_y_coordinate: 4;
            projection_x_coordinate: 4;
        Scalar coordinates:
            time: 2015-11-23 03:00:00
            forecast_reference_time: 2015-11-23 03:00:00
            forecast_period (on time coord): 0.0 hours
        Data:
            self.cube_a:
                All points contain float(1.)
            self.cube_b:
                All points contain float(1.)
        """
        self.cube_a = set_up_variable_cube(np.ones((4, 4), dtype=np.float32),
                                           time=datetime(2015, 11, 23, 3, 0),
                                           frt=datetime(2015, 11, 23, 3, 0))

        self.cube_b = set_up_variable_cube(np.ones((4, 4), dtype=np.float32),
                                           time=datetime(2015, 11, 23, 3, 0),
                                           frt=datetime(2015, 11, 23, 3, 0))

        self.thr_a = (0.1, 0.5, 0.8)
        self.thr_b = (0.0, 0.5, 0.9)
    def setUp(self):
        """Set up temperature and wind speed cubes for testing."""
        super().setUp()
        base_data = np.array(
            [[[0.3, 1.1, 2.6], [4.2, 5.3, 6.], [7.1, 8.2, 9.]],
             [[0.7, 2., 3], [4.3, 5.6, 6.4], [7., 8., 9.]],
             [[2.1, 3., 3.], [4.8, 5., 6.], [7.9, 8., 8.9]]],
            dtype=np.float32)
        temperature_data = base_data + 273.15
        self.current_temperature_forecast_cube = set_up_variable_cube(
            temperature_data, units="Kelvin", realizations=[0, 1, 2])

        self.historic_temperature_forecast_cube = (_create_historic_forecasts(
            self.current_temperature_forecast_cube))

        self.temperature_truth_cube = (_create_truth(
            self.current_temperature_forecast_cube))

        # Create a cube for testing wind speed.
        self.current_wind_speed_forecast_cube = set_up_variable_cube(
            base_data,
            name="wind_speed",
            units="m s-1",
            realizations=[0, 1, 2])

        self.historic_wind_speed_forecast_cube = (_create_historic_forecasts(
            self.current_wind_speed_forecast_cube))

        self.wind_speed_truth_cube = (_create_truth(
            self.current_wind_speed_forecast_cube))
    def setUp(self):
        """Set up the plugin and cubes for testing."""
        data = np.ones((3, 3), dtype=np.float32)
        self.historic_forecast = (_create_historic_forecasts(
            set_up_variable_cube(data, standard_grid_metadata="uk_det")))
        data_with_realizations = np.ones((3, 3, 3), dtype=np.float32)
        self.historic_forecast_with_realizations = (_create_historic_forecasts(
            set_up_variable_cube(data_with_realizations,
                                 realizations=[0, 1, 2],
                                 standard_grid_metadata="uk_det")))
        self.optimised_coeffs = np.array([0, 1, 2, 3], np.int32)

        coeff_names = ["gamma", "delta", "alpha", "beta"]
        self.expected, self.x_coord, self.y_coord = create_coefficients_cube(
            self.historic_forecast,
            coeff_names,
            self.optimised_coeffs,
            time_offset=60 * 60 * 24)

        self.distribution = "gaussian"
        self.current_cycle = "20171110T0000Z"
        self.desired_units = "degreesC"
        self.predictor_of_mean_flag = "mean"
        self.plugin = (Plugin(
            distribution=self.distribution,
            current_cycle=self.current_cycle,
            desired_units=self.desired_units,
            predictor_of_mean_flag=self.predictor_of_mean_flag))
示例#6
0
 def setUp(self):
     """Set up cubes for testing"""
     self.cube = set_up_variable_cube(np.ones((5, 5), dtype=np.float32),
                                      spatial_grid='equalarea')
     self.cube_non_integer_intervals = set_up_variable_cube(
         np.ones((5, 5), dtype=np.float32), spatial_grid='equalarea')
     self.cube_non_integer_intervals.data *= 1.5
示例#7
0
    def setUp(self):
        """Set up temperature and wind speed cubes for testing."""
        # Note: test_temperature_realizations_data_check produces ~0.5K
        # different results when the temperature forecast cube is float32
        # below. A bug?
        data = (np.tile(np.linspace(-45.0, 45.0, 9), 3).reshape(3, 3, 3) +
                273.15)
        data[0] -= 2
        data[1] += 2
        data[2] += 4
        data = data.astype(np.float32)
        self.current_temperature_forecast_cube = set_up_variable_cube(
            data, units="Kelvin", realizations=[0, 1, 2])

        self.historic_temperature_forecast_cube = (_create_historic_forecasts(
            self.current_temperature_forecast_cube))

        self.temperature_truth_cube = (_create_truth(
            self.current_temperature_forecast_cube))

        data = np.tile(np.linspace(0, 60, 9), 3).reshape(3, 3, 3)
        data[1] += 2
        data[2] += 4
        data = data.astype(np.float32)
        self.current_wind_speed_forecast_cube = set_up_variable_cube(
            data, name="wind_speed", units="m s-1", realizations=[0, 1, 2])

        self.historic_wind_speed_forecast_cube = (_create_historic_forecasts(
            self.current_wind_speed_forecast_cube))

        self.wind_speed_truth_cube = (_create_truth(
            self.current_wind_speed_forecast_cube))
示例#8
0
    def setUp(self):
        """Set up a cube to test."""
        original_units = {
            "time": {
                "unit": "seconds since 1970-01-01 00:00:00",
                "dtype": np.int64
            },
            "forecast_reference_time": {
                "unit": "seconds since 1970-01-01 00:00:00",
                "dtype": np.int64
            },
            "forecast_period": {
                "unit": "seconds",
                "dtype": np.int32
            },
            "projection_x_coordinate": {
                "unit": "m",
                "dtype": np.float32
            }
        }

        cube_units.DEFAULT_UNITS = original_units
        self.plugin = cube_units.enforce_coordinate_units_and_dtypes
        self.cube = set_up_variable_cube(np.ones((5, 5), dtype=np.float32),
                                         spatial_grid='equalarea')

        self.cube_non_integer_intervals = set_up_variable_cube(
            np.ones((5, 5), dtype=np.float32),
            spatial_grid='equalarea',
            time=datetime(2017, 11, 10, 4, 30))
        crd = self.cube_non_integer_intervals.coord('projection_x_coordinate')
        crd.points = crd.points * 1.0005
示例#9
0
    def setUp(self):
        """Set up cubes for use in testing."""

        data = np.ones(9).reshape(3, 3).astype(np.float32)
        self.reference_cube = set_up_variable_cube(data,
                                                   spatial_grid="equalarea")
        self.cube1 = self.reference_cube.copy()
        self.cube2 = self.reference_cube.copy()
        self.unmatched_cube = set_up_variable_cube(data, spatial_grid="latlon")

        self.diagnostic_cube_hash = create_coordinate_hash(self.reference_cube)

        neighbours = np.array([[[0., 0., 0.]]])
        altitudes = np.array([0])
        latitudes = np.array([0])
        longitudes = np.array([0])
        wmo_ids = np.array([0])
        grid_attributes = ['x_index', 'y_index', 'vertical_displacement']
        neighbour_methods = ['nearest']
        self.neighbour_cube = build_spotdata_cube(
            neighbours,
            'grid_neighbours',
            1,
            altitudes,
            latitudes,
            longitudes,
            wmo_ids,
            grid_attributes=grid_attributes,
            neighbour_methods=neighbour_methods)
        self.neighbour_cube.attributes['model_grid_hash'] = (
            self.diagnostic_cube_hash)
示例#10
0
    def setUp(self):
        """Set up plugin and input rainfall-like cubes"""
        self.plugin = OpticalFlow(iterations=20)
        self.plugin.data_smoothing_radius_km = np.float32(6.)

        coord_points = 2000 * np.arange(16, dtype=np.float32)  # in metres
        rainfall_block = np.array(
            [[1., 1., 1., 1., 1., 1., 1.], [1., 2., 2., 2., 2., 1., 1.],
             [1., 2., 3., 3., 2., 1., 1.], [1., 2., 3., 3., 2., 1., 1.],
             [1., 2., 2., 2., 2., 1., 1.], [1., 1., 1., 1., 1., 1., 1.],
             [1., 1., 1., 1., 1., 1., 1.]],
            dtype=np.float32)

        data1 = np.zeros((16, 16), dtype=np.float32)
        data1[1:8, 2:9] = rainfall_block
        self.cube1 = set_up_variable_cube(data1,
                                          name="rainfall_rate",
                                          units="mm h-1",
                                          spatial_grid="equalarea",
                                          time=datetime(2018, 2, 20, 4, 0),
                                          frt=datetime(2018, 2, 20, 4, 0))
        self.cube1.coord(axis='x').points = coord_points
        self.cube1.coord(axis='y').points = coord_points

        data2 = np.zeros((16, 16), dtype=np.float32)
        data2[2:9, 1:8] = rainfall_block
        self.cube2 = set_up_variable_cube(data2,
                                          name="rainfall_rate",
                                          units="mm h-1",
                                          spatial_grid="equalarea",
                                          time=datetime(2018, 2, 20, 4, 15),
                                          frt=datetime(2018, 2, 20, 4, 15))
        self.cube2.coord(axis='x').points = coord_points
        self.cube2.coord(axis='y').points = coord_points
示例#11
0
 def setUp(self):
     """Set up an equal area cube"""
     self.cube = set_up_variable_cube(np.ones((5, 5), dtype=np.float32),
                                      spatial_grid='equalarea')
     self.spacing = 200000.0
     self.unit = 'metres'
     self.lat_lon_cube = set_up_variable_cube(
         np.ones((5, 5), dtype=np.float32))
    def setUp(self):
        """Set up the plugin and cubes for testing."""
        data = np.ones((3, 3), dtype=np.float32)
        self.historic_forecast = (_create_historic_forecasts(
            set_up_variable_cube(data, standard_grid_metadata="uk_det")))
        data_with_realizations = np.ones((3, 3, 3), dtype=np.float32)
        self.historic_forecast_with_realizations = (_create_historic_forecasts(
            set_up_variable_cube(data_with_realizations,
                                 realizations=[0, 1, 2],
                                 standard_grid_metadata="uk_det")))
        self.optimised_coeffs = np.array([0, 1, 2, 3], np.int32)
        coeff_names = ["gamma", "delta", "alpha", "beta"]

        coefficient_index = iris.coords.DimCoord(self.optimised_coeffs,
                                                 long_name="coefficient_index",
                                                 units="1")
        dim_coords_and_dims = [(coefficient_index, 0)]

        coefficient_name = iris.coords.AuxCoord(coeff_names,
                                                long_name="coefficient_name",
                                                units="no_unit")

        time_point = (np.max(self.historic_forecast.coord("time").points) +
                      60 * 60 * 24)
        time_coord = self.historic_forecast.coord("time").copy(time_point)

        frt_orig_coord = (
            self.historic_forecast.coord("forecast_reference_time"))
        frt_point = np.max(frt_orig_coord.points) + 60 * 60 * 24
        frt_coord = frt_orig_coord.copy(frt_point)

        aux_coords_and_dims = [
            (coefficient_name, 0), (time_coord, None), (frt_coord, None),
            (self.historic_forecast[-1].coord("forecast_period"), None)
        ]

        attributes = {
            "mosg__model_configuration": "uk_det",
            "diagnostic_standard_name": "air_temperature"
        }

        self.expected = iris.cube.Cube(self.optimised_coeffs,
                                       long_name="emos_coefficients",
                                       units="1",
                                       dim_coords_and_dims=dim_coords_and_dims,
                                       aux_coords_and_dims=aux_coords_and_dims,
                                       attributes=attributes)

        self.distribution = "gaussian"
        self.current_cycle = "20171110T0000Z"
        self.desired_units = "degreesC"
        self.predictor_of_mean_flag = "mean"
        self.plugin = (Plugin(
            distribution=self.distribution,
            current_cycle=self.current_cycle,
            desired_units=self.desired_units,
            predictor_of_mean_flag=self.predictor_of_mean_flag))
示例#13
0
 def setUp(self):
     """Set up cubes for testing"""
     self.cube = set_up_variable_cube(np.ones((5, 5), dtype=np.float32),
                                      spatial_grid='equalarea')
     self.cube_non_integer_intervals = set_up_variable_cube(
         np.ones((5, 5), dtype=np.float32),
         spatial_grid='equalarea',
         time=datetime(2017, 11, 10, 4, 30))
     crd = self.cube_non_integer_intervals.coord('projection_x_coordinate')
     crd.points = crd.points * 1.0005
    def setUp(self):
        """Creates cubes to input"""

        temperature = np.array([[226.15, 237.4, 248.65]], dtype=np.float32)
        self.temperature_cube = set_up_variable_cube(temperature)

        wind_speed = np.array([[0., 7.5, 15.]], dtype=np.float32)
        self.wind_speed_cube = set_up_variable_cube(wind_speed,
                                                    name="wind_speed",
                                                    units="m s-1")
示例#15
0
 def setUp(self):
     """Use temperature cube to test with."""
     data = 275 * np.ones((3, 3, 3), dtype=np.float32)
     self.cube = set_up_variable_cube(
         data,
         standard_grid_metadata='uk_ens',
         attributes={'mosg__grid_version': '1.2.0'})
     self.cube_ukv = set_up_variable_cube(
         data[0],
         standard_grid_metadata='uk_det',
         attributes={'mosg__grid_version': '1.1.0'})
示例#16
0
 def setUp(self):
     """Set up a cube."""
     self.cube = set_up_variable_cube(np.ones((5, 5), dtype=np.float32),
                                      spatial_grid="equalarea")
     self.cube.data[2, 2] = 0
     self.large_cube = set_up_variable_cube(
         np.ones((10, 10), dtype=np.float32), spatial_grid="equalarea")
     # set equally-spaced coordinate points
     self.large_cube.coord(axis='y').points = np.linspace(
         0, 900000, 10, dtype=np.float32)
     self.large_cube.coord(axis='x').points = np.linspace(
         -300000, 600000, 10, dtype=np.float32)
     self.large_cube.data[5, 5] = 0
示例#17
0
    def setUp(self):
        """Set up temperature and wind speed cubes for testing."""
        super().setUp()
        frt_dt = datetime.datetime(2017, 11, 10, 0, 0)
        time_dt = datetime.datetime(2017, 11, 10, 4, 0)

        base_data = np.array(
            [[[0.3, 1.1, 2.6], [4.2, 5.3, 6.], [7.1, 8.2, 9.]],
             [[0.7, 2., 3], [4.3, 5.6, 6.4], [7., 8., 9.]],
             [[2.1, 3., 3.], [4.8, 5., 6.], [7.9, 8., 8.9]]],
            dtype=np.float32)
        temperature_data = base_data + 273.15
        self.current_temperature_forecast_cube = set_up_variable_cube(
            temperature_data,
            units="Kelvin",
            realizations=[0, 1, 2],
            time=time_dt,
            frt=frt_dt)

        # Create historic forecasts and truth
        self.historic_forecasts = _create_historic_forecasts(
            temperature_data, time_dt, frt_dt, realizations=[0, 1, 2])
        self.truth = _create_truth(temperature_data, time_dt)

        # Create a combined list of historic forecasts and truth
        self.combined = self.historic_forecasts + self.truth

        # Create the historic and truth cubes
        self.historic_temperature_forecast_cube = (
            self.historic_forecasts.merge_cube())
        self.temperature_truth_cube = self.truth.merge_cube()

        # Create a cube for testing wind speed.
        self.current_wind_speed_forecast_cube = set_up_variable_cube(
            base_data,
            name="wind_speed",
            units="m s-1",
            realizations=[0, 1, 2])

        self.historic_wind_speed_forecast_cube = _create_historic_forecasts(
            base_data,
            time_dt,
            frt_dt,
            realizations=[0, 1, 2],
            name="wind_speed",
            units="m s-1").merge_cube()

        self.wind_speed_truth_cube = _create_truth(base_data,
                                                   time_dt,
                                                   name="wind_speed",
                                                   units="m s-1").merge_cube()
示例#18
0
    def setUp(self):
        """Set up a realistic input cube with lots of metadata.  Input cube
        grid is 1000x1000 km with points spaced 100 km apart."""
        self.attrs = {'history': '2018-12-10Z: StaGE Decoupler',
                      'title': 'Temperature on UK 2 km Standard Grid',
                      'source': 'Met Office Unified Model'}
        self.cube = set_up_variable_cube(
            np.ones((3, 11, 11), dtype=np.float32), spatial_grid='equalarea',
            standard_grid_metadata='uk_det', attributes=self.attrs)

        self.cube_1d = set_up_variable_cube(
            np.ones((1, 11, 11), dtype=np.float32), spatial_grid='equalarea',
            standard_grid_metadata='uk_det', attributes=self.attrs)
        self.grid_spacing = 100000
示例#19
0
    def setUp(self):
        """Create a cube with a single non-zero point."""
        self.fuzzy_factor = 0.5
        data = np.zeros((1, 5, 5), dtype=np.float32)
        data[0][2][2] = 0.5  # ~2 mm/hr
        self.cube = set_up_variable_cube(data,
                                         name="precipitation_amount",
                                         units="kg m^-2 s^-1")

        rate_data = np.zeros((5, 5), dtype=np.float32)
        rate_data[2][2] = 1.39e-6  # 5.004 mm/hr
        self.rate_cube = set_up_variable_cube(rate_data,
                                              name="rainfall_rate",
                                              units="m s-1")
示例#20
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'
示例#21
0
 def test_blend_realizations(self):
     """Test processing works for merging over coordinates that don't
     require specific setup"""
     data = np.ones((1, 3, 3), dtype=np.float32)
     cube1 = set_up_variable_cube(data, realizations=np.array([0]))
     cube1 = iris.util.squeeze(cube1)
     cube2 = set_up_variable_cube(data, realizations=np.array([1]))
     cube2 = iris.util.squeeze(cube2)
     plugin = MergeCubesForWeightedBlending("realization")
     result = plugin.process([cube1, cube2])
     self.assertIsInstance(result, iris.cube.Cube)
     self.assertArrayEqual(
         result.coord("realization").points, np.array([0, 1]))
     self.assertEqual(result[0].metadata, cube1.metadata)
     self.assertEqual(result[1].metadata, cube2.metadata)
示例#22
0
 def setUp(self):
     """Set up the test inputs."""
     self.time_0 = datetime.datetime(2017, 11, 1, 3)
     self.time_extra = datetime.datetime(2017, 11, 1, 6)
     self.time_1 = datetime.datetime(2017, 11, 1, 9)
     self.npoints = 10
     data_time_0 = np.ones((self.npoints, self.npoints), dtype=np.float32)
     data_time_1 = np.ones(
         (self.npoints, self.npoints), dtype=np.float32) * 7
     self.cube_time_0 = set_up_variable_cube(data_time_0,
                                             time=self.time_0,
                                             frt=self.time_0)
     self.cube_time_1 = set_up_variable_cube(data_time_1,
                                             time=self.time_1,
                                             frt=self.time_0)
示例#23
0
 def test_validity_time_mismatch(self):
     """Test returns False when cubes validity times do not match."""
     cube_different_vt = set_up_variable_cube(self.data,
                                              time=datetime(
                                                  2017, 11, 10, 5, 0))
     result = time_coords_match(self.ref_cube, cube_different_vt)
     self.assertFalse(result)
    def setUp(self):
        """Create cubes to input."""
        temperature = np.array([[293.65, 304.9, 316.15]], dtype=np.float32)
        self.temperature_cube = set_up_variable_cube(temperature)

        wind_speed = np.array([[0., 7.5, 15.]], dtype=np.float32)
        self.wind_speed_cube = set_up_variable_cube(
            wind_speed, name="wind_speed", units="m s-1")

        pressure = np.array([[99998., 101248., 102498.]], dtype=np.float32)
        self.pressure_cube = set_up_variable_cube(
            pressure, name="air_pressure", units="Pa")

        relh = np.array([[0., 0.075, 0.15]], dtype=np.float32)
        self.relative_humidity_cube = set_up_variable_cube(
            relh, name="relative_humidity", units="1")
示例#25
0
def set_up_basic_model_config_cube(frt=None, time_points=None):
    """Set up cube with dimensions of realization x time x lat x lon, plus
     model id and configuration scalar coords

    Kwargs:
        frt (datetime):
            Forecast reference time point
        time_points (list):
            List of times as datetime instances to create a dim coord
    """
    if frt is None:
        frt = dt(2017, 1, 10, 3, 0)
    if time_points is None:
        time_points = [dt(2017, 1, 10, 9, 0), dt(2017, 1, 10, 10, 0),
                       dt(2017, 1, 10, 11, 0)]

    model_id_coord = AuxCoord([1000], long_name="model_id")
    model_config_coord = AuxCoord(["uk_det"], long_name="model_configuration")

    data = np.full((1, 2, 2), 275.15, dtype=np.float32)
    cube = set_up_variable_cube(
        data, time=frt, frt=frt, include_scalar_coords=[model_id_coord,
                                                        model_config_coord])
    cube = add_coordinate(
        cube, time_points, "time", is_datetime=True, order=[1, 0, 2, 3])

    return cube
示例#26
0
    def setUp(self):
        """Set up plugin with suitable parameters (used for dict only)"""
        self.plugin = ChooseWeightsLinear(
            "forecast_period", CONFIG_DICT_UKV)

        # create a cube with unnecessary realization coordinate (dimensions:
        # model_id: 2; realization: 1; latitude: 2; longitude: 2)
        cube = set_up_variable_cube(278.*np.ones((1, 2, 2), dtype=np.float32))
        self.cube = add_coordinate(
            cube, [1000, 2000], "model_id", dtype=np.int32)
        self.cube.add_aux_coord(
            AuxCoord(["uk_det", "uk_ens"], long_name="model_configuration"),
            data_dims=0)

        # create a reference cube as above WITHOUT realization
        new_data = self.cube.data[:, 0, :, :]
        dim_coords = [(self.cube.coord("model_id"), 0),
                      (self.cube.coord("latitude"), 1),
                      (self.cube.coord("longitude"), 2)]
        aux_coords = [(self.cube.coord("model_configuration"), 0),
                      (self.cube.coord("time"), None),
                      (self.cube.coord("forecast_period"), None),
                      (self.cube.coord("forecast_reference_time"), None)]
        self.reference_cube = iris.cube.Cube(
            new_data, "air_temperature", units="K",
            dim_coords_and_dims=dim_coords,
            aux_coords_and_dims=aux_coords)
        self.reference_cube.add_aux_coord(AuxCoord(0, "realization"))

        # split into a cubelist for each model
        self.reference_cubelist = iris.cube.CubeList([self.reference_cube[0],
                                                      self.reference_cube[1]])
示例#27
0
def _create_truth(data, time_dt, number_of_days=5, **kwargs):
    """
    Function to create truth cubes, based on the input cube, and assuming that
    there will be one forecast per day at the same hour of the day.

    Please see improver.tests.set_up_test_cubes.set_up_variable_cube for the
    other supported keyword arguments.

    Args:
        data (numpy.ndarray):
            Numpy array to define the data that will be used to fill the cube.
            This will be subtracted by 3 with the aim of giving a difference
            between the current forecast and the truths.
            Therefore, the current forecast would contain the unadjusted data.
        time_dt (datetime.datetime):
            Datetime to define the initial validity time. This will be
            incremented in days up to the defined number_of_days.
        standard_grid_metadata (str):
            Please see improver.tests.set_up_test_cubes.set_up_variable_cube.
        number_of_days(int):
            Number of days to increment when constructing a cubelist of the
            historic forecasts.
    """
    truth = iris.cube.CubeList([])
    for day in range(number_of_days):
        new_time_dt = time_dt + datetime.timedelta(days=day)
        truth.append(
            set_up_variable_cube(np.amax(data - 3, axis=0),
                                 time=new_time_dt,
                                 frt=new_time_dt,
                                 standard_grid_metadata="uk_det",
                                 **kwargs))
    return truth
示例#28
0
    def setUp(self):
        """Use temperature cube to test with."""
        data = (np.tile(np.linspace(-45.0, 45.0, 9), 3).reshape(3, 3, 3) +
                273.15)
        data[0] -= 2
        data[1] += 2
        data[2] += 4
        data = data.astype(np.float32)
        self.current_temperature_forecast_cube = set_up_variable_cube(
            data, units="Kelvin", realizations=[0, 1, 2])

        optimised_coeffs = [
            4.55819380e-06, -8.02401974e-09, 1.66667055e+00, 1.00000011e+00
        ]
        current_cycle = "20171110T0000Z"
        estimator = (EstimateCoefficientsForEnsembleCalibration(
            "gaussian", current_cycle, desired_units="Celsius"))
        self.coeffs_from_mean = (estimator.create_coefficients_cube(
            optimised_coeffs, self.current_temperature_forecast_cube))

        optimised_coeffs = np.array([5, 1, 0, 0.57, 0.6, 0.6])
        estimator = (EstimateCoefficientsForEnsembleCalibration(
            "gaussian",
            current_cycle,
            desired_units="Celsius",
            predictor_of_mean_flag="realizations"))
        self.coeffs_from_realizations = (estimator.create_coefficients_cube(
            optimised_coeffs, self.current_temperature_forecast_cube))
示例#29
0
    def setUp(self):
        """Use temperature cube to test with."""
        data = np.ones((3, 3, 3), dtype=np.float32)
        self.current_temperature_forecast_cube = set_up_variable_cube(
            data, realizations=[0, 1, 2])

        optimised_coeffs = [
            4.55819380e-06, -8.02401974e-09, 1.66667055e+00, 1.00000011e+00
        ]
        current_cycle = "20171110T0000Z"
        estimator = (EstimateCoefficientsForEnsembleCalibration(
            "gaussian", current_cycle, desired_units="Celsius"))
        self.coeffs_from_mean = (estimator.create_coefficients_cube(
            optimised_coeffs, self.current_temperature_forecast_cube))

        optimised_coeffs = np.array([
            4.55819380e-06, -8.02401974e-09, 1.66667055e+00, 1.00000011e+00,
            1.00000011e+00, 1.00000011e+00
        ])
        estimator = (EstimateCoefficientsForEnsembleCalibration(
            "gaussian",
            current_cycle,
            desired_units="Celsius",
            predictor_of_mean_flag="realizations"))
        self.coeffs_from_realizations = (estimator.create_coefficients_cube(
            optimised_coeffs, self.current_temperature_forecast_cube))
 def test_var_name(self):
     """Test ability to set data name and units"""
     result = set_up_variable_cube(
         self.data-273.15, name='wet_bulb_temperature', units='degC')
     self.assertArrayAlmostEqual(result.data, self.data-273.15)
     self.assertEqual(result.name(), 'wet_bulb_temperature')
     self.assertEqual(result.units, 'degC')