def test_lat_lon(self):
     """Test coordinates created for a lat-lon grid"""
     y_coord, x_coord = construct_xy_coords(4, 3, 'latlon')
     self.assertEqual(y_coord.name(), "latitude")
     self.assertEqual(x_coord.name(), "longitude")
     for crd in [y_coord, x_coord]:
         self.assertEqual(crd.units, "degrees")
         self.assertEqual(crd.dtype, np.float32)
         self.assertEqual(crd.coord_system, GLOBAL_GRID_CCRS)
     self.assertEqual(len(y_coord.points), 4)
     self.assertEqual(len(x_coord.points), 3)
 def test_proj_xy(self):
     """Test coordinates created for an equal area grid"""
     y_coord, x_coord = construct_xy_coords(4, 3, 'equalarea')
     self.assertEqual(y_coord.name(), "projection_y_coordinate")
     self.assertEqual(x_coord.name(), "projection_x_coordinate")
     for crd in [y_coord, x_coord]:
         self.assertEqual(crd.units, "metres")
         self.assertEqual(crd.dtype, np.float32)
         self.assertEqual(crd.coord_system, STANDARD_GRID_CCRS)
     self.assertEqual(len(y_coord.points), 4)
     self.assertEqual(len(x_coord.points), 3)
    def setUp(self):
        """
        Set up cubes for use in testing SpotLapseRateAdjust. Inputs are
        envisaged as follows:

        Gridded

         Lapse rate  Orography  Temperatures (not used directly)
          (x DALR)

            A B C      A B C        A   B   C

        a   2 1 1      1 1 1       270 270 270
        b   1 2 1      1 4 1       270 280 270
        c   1 1 2      1 1 1       270 270 270

        Spot
        (note the neighbours are identified with the A-C, a-c indices above)

         Site  Temperature Altitude  Nearest    DZ   MinDZ      DZ
                                     neighbour       neighbour

          0        280        3      Ac         2    Bb         -1
          1        270        4      Bb         0    Bb          0
          2        280        0      Ca        -1    Ca         -1


        """
        # Set up lapse rate cube
        lapse_rate_data = np.ones(9).reshape(3, 3).astype(np.float32) * DALR
        lapse_rate_data[0, 2] = 2 * DALR
        lapse_rate_data[1, 1] = 2 * DALR
        lapse_rate_data[2, 0] = 2 * DALR
        self.lapse_rate_cube = set_up_variable_cube(lapse_rate_data,
                                                    name="lapse_rate",
                                                    units="K m-1",
                                                    spatial_grid="equalarea")
        diagnostic_cube_hash = create_coordinate_hash(self.lapse_rate_cube)

        # Set up neighbour and spot diagnostic cubes
        y_coord, x_coord = construct_xy_coords(3, 3, "equalarea")
        y_coord = y_coord.points
        x_coord = x_coord.points

        # neighbours, each group is for a point under two methods, e.g.
        # [ 0.  0.  0.] is the nearest point to the first spot site, whilst
        # [ 1.  1. -1.] is the nearest point with minimum height difference.
        neighbours = np.array([[[0., 0., 2.], [1., 1., -1.]],
                               [[1., 1., 0.], [1., 1., 0.]],
                               [[2., 2., -1.], [2., 2., -1.]]])
        altitudes = np.array([3, 4, 0])
        latitudes = np.array([y_coord[0], y_coord[1], y_coord[2]])
        longitudes = np.array([x_coord[0], x_coord[1], x_coord[2]])
        wmo_ids = np.arange(3)
        grid_attributes = ['x_index', 'y_index', 'vertical_displacement']
        neighbour_methods = ['nearest', 'nearest_minimum_dz']
        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'] = (
            diagnostic_cube_hash)

        time, = iris_time_to_datetime(self.lapse_rate_cube.coord("time"))
        frt, = iris_time_to_datetime(
            self.lapse_rate_cube.coord("forecast_reference_time"))
        time_bounds = None

        time_coords = construct_scalar_time_coords(time, time_bounds, frt)
        time_coords = [item[0] for item in time_coords]

        # This temperature cube is set up with the spot sites having obtained
        # their temperature values from the nearest grid sites.
        temperatures_nearest = np.array([280, 270, 280])
        self.spot_temperature_nearest = build_spotdata_cube(
            temperatures_nearest,
            'air_temperature',
            'K',
            altitudes,
            latitudes,
            longitudes,
            wmo_ids,
            scalar_coords=time_coords)
        self.spot_temperature_nearest.attributes['model_grid_hash'] = (
            diagnostic_cube_hash)

        # This temperature cube is set up with the spot sites having obtained
        # their temperature values from the nearest minimum vertical
        # displacment grid sites. The only difference here is for site 0, which
        # now gets its temperature from Bb (see doc-string above).
        temperatures_mindz = np.array([270, 270, 280])
        self.spot_temperature_mindz = build_spotdata_cube(
            temperatures_mindz,
            'air_temperature',
            'K',
            altitudes,
            latitudes,
            longitudes,
            wmo_ids,
            scalar_coords=time_coords)
        self.spot_temperature_mindz.attributes['model_grid_hash'] = (
            diagnostic_cube_hash)
Example #4
0
 def test_lat_lon_values(self):
     """Test latitude and longitude point values are as expected"""
     y_coord, x_coord = construct_xy_coords(3, 3, 'latlon')
     self.assertArrayAlmostEqual(x_coord.points, [-20., 0., 20.])
     self.assertArrayAlmostEqual(y_coord.points, [40., 60., 80.])