def test_metadata_set(self):
     """Test that the metadata is set correctly."""
     result = add_wxcode_metadata(self.cube)
     self.assertEqual(result.name(), 'weather_code')
     self.assertEqual(result.units, Unit("1"))
     self.assertArrayEqual(result.attributes['weather_code'], self.wxcode)
     self.assertEqual(result.attributes['weather_code_meaning'],
                      self.wxmeaning)
 def test_metadata_saves(self):
     """Test that the metadata saves as NetCDF correctly."""
     cube = add_wxcode_metadata(self.cube)
     iris.save(cube, self.nc_file, unlimited_dimensions=[])
     result = iris.load_cube(self.nc_file)
     self.assertEqual(result.name(), 'weather_code')
     self.assertEqual(result.units, Unit("1"))
     self.assertArrayEqual(result.attributes['weather_code'], self.wxcode)
     self.assertEqual(result.attributes['weather_code_meaning'],
                      self.wxmeaning)
Esempio n. 3
0
 def test_metadata_saves(self):
     """Test that the metadata saves as NetCDF correctly."""
     cube = add_wxcode_metadata(self.cube)
     save_netcdf(cube, self.nc_file)
     result = load_cube(self.nc_file)
     self.assertEqual(result.name(), 'weather_code')
     self.assertEqual(result.units, Unit("1"))
     self.assertArrayEqual(result.attributes['weather_code'], self.wxcode)
     self.assertEqual(result.attributes['weather_code_meaning'],
                      self.wxmeaning)
Esempio n. 4
0
def set_up_wxcube(time_points=None):
    """
    Set up a wxcube

    Args:
        time_points (numpy.ndarray):
           Array of time points

    Returns:
        iris.cube.Cube:
            cube of weather codes set to 1
            data shape (time_points, 16, 16)
            grid covers 0 to 30km west of origin and
            0 to 30km north of origin. origin = 54.9N 2.5W
    """

    if time_points is None:
        time_points = np.array([datetime_to_numdateval()])

    num_grid_points = 16
    data = np.ones((len(time_points), num_grid_points, num_grid_points))

    cube = Cube(data, long_name="weather_code", units="1")
    cube = add_wxcode_metadata(cube)

    time_origin = "hours since 1970-01-01 00:00:00"
    calendar = "gregorian"
    tunit = Unit(time_origin, calendar)

    cube.add_dim_coord(
        DimCoord(time_points, standard_name="time", units=tunit), 0)

    step_size = 2000
    y_points = np.arange(0, step_size * num_grid_points, step_size)
    cube.add_dim_coord(
        DimCoord(y_points,
                 'projection_y_coordinate',
                 units='m',
                 coord_system=STANDARD_GRID_CCRS), 1)

    x_points = np.linspace(-30000, 0, num_grid_points)
    cube.add_dim_coord(
        DimCoord(x_points,
                 'projection_x_coordinate',
                 units='m',
                 coord_system=STANDARD_GRID_CCRS), 2)

    return cube
Esempio n. 5
0
def set_up_wxcube_lat_lon(time_points=None):
    """
    Set up a lat-lon wxcube

    Args:
        time_points (numpy.ndarray):
           Array of time points

    Returns:
        iris.cube.Cube:
            lat lon cube of weather codes set to 1
            data shape (time_points, 16, 16)
            grid covering 8W to 7E, 49N to 64N
    """

    if time_points is None:
        time_points = np.array([datetime_to_numdateval()])

    data = np.ones((len(time_points), 16, 16))
    cube = Cube(data, long_name="weather_code", units="1")
    cube = add_wxcode_metadata(cube)

    time_origin = "hours since 1970-01-01 00:00:00"
    calendar = "gregorian"
    tunit = Unit(time_origin, calendar)

    cube.add_dim_coord(DimCoord(time_points, "time", units=tunit), 0)

    lon_points = np.linspace(-8, 7, 16)
    lat_points = np.linspace(49, 64, 16)

    cube.add_dim_coord(
        DimCoord(lat_points,
                 'latitude',
                 units='degrees',
                 coord_system=ELLIPSOID), 1)
    cube.add_dim_coord(
        DimCoord(lon_points,
                 'longitude',
                 units='degrees',
                 coord_system=ELLIPSOID), 2)
    return cube
Esempio n. 6
0
    def create_symbol_cube(cube):
        """
        Create an empty weather_symbol cube initialised with -1 across the
        grid.

        Args:
            cube (iris.cube.Cube):
                An x-y slice of one of the input cubes, used to define the
                size of the weather symbol grid.
        Returns:
            symbols (iris.cube.Cube):
                A cube full of -1 values, with suitable metadata to describe
                the weather symbols that will fill it.
        """
        threshold_coord = find_threshold_coordinate(cube)
        cube_format = next(cube.slices_over([threshold_coord]))
        symbols = cube_format.copy(
            data=np.full(cube_format.data.shape, -1, dtype=np.int32))

        symbols.remove_coord(threshold_coord)
        symbols = add_wxcode_metadata(symbols)

        return symbols
 def test_basic(self):
     """Test that the function returns a cube."""
     result = add_wxcode_metadata(self.cube)
     self.assertIsInstance(result, Cube)