Esempio n. 1
0
 def setUp(self):
     """Prepare tests."""
     self.cube = Cube([1.0], var_name='areacello', units='m-2')
     self.vardef = get_var_info('CMIP5', 'fx', self.cube.var_name)
     self.fix = Areacello(self.vardef)
Esempio n. 2
0
def test_cl_hybrid_pressure_coord_fix_metadata_with_a(cl_file_with_a):
    """Test ``fix_metadata`` for ``cl``."""
    vardef = get_var_info('CMIP6', 'Amon', 'cl')
    var_names = hybrid_pressure_coord_fix_metadata(
        cl_file_with_a, 'cl', ClFixHybridPressureCoord(vardef))
    assert 'a_bnds' in var_names
Esempio n. 3
0
 def setUp(self):
     """Prepare tests."""
     self.cube = Cube([1.0], var_name='ch4', units='J')
     self.vardef = get_var_info('CMIP5', 'Amon', self.cube.var_name)
     self.fix = Ch4(self.vardef)
Esempio n. 4
0
 def setUp(self):
     """Prepare tests."""
     self.cube = Cube([1.0, 2.0], var_name='so', units='1.0')
     self.vardef = get_var_info('CMIP5', 'Omon', self.cube.var_name)
     self.fix = So(self.vardef)
Esempio n. 5
0
 def setUp(self):
     """Prepare tests."""
     self.cube = Cube([1.0], var_name='fgco2', units='J')
     self.vardef = get_var_info('CMIP5', 'Omon', self.cube.var_name)
     self.fix = FgCo2(self.vardef)
Esempio n. 6
0
def test_ocean_fix_grid_no_ij_bounds(tos_cubes_no_ij_bounds):
    """Test ``fix_metadata`` with cubes with no ij bounds."""
    cube_in = tos_cubes_no_ij_bounds.extract_cube('sea_surface_temperature')
    assert len(cube_in.coords('latitude')) == 1
    assert len(cube_in.coords('longitude')) == 1
    assert cube_in.coord('latitude').bounds is None
    assert cube_in.coord('longitude').bounds is None
    assert cube_in.coord('cell index along first dimension').var_name == 'i'
    assert cube_in.coord('cell index along second dimension').var_name == 'j'
    assert cube_in.coord('cell index along first dimension').bounds is None
    assert cube_in.coord('cell index along second dimension').bounds is None

    # Apply fix
    vardef = get_var_info('CMIP6', 'Omon', 'tos')
    fix = OceanFixGrid(vardef)
    fixed_cubes = fix.fix_metadata(tos_cubes_no_ij_bounds)
    assert len(fixed_cubes) == 1
    fixed_cube = fixed_cubes.extract_cube('sea_surface_temperature')
    assert fixed_cube is cube_in

    # Check ij names
    i_coord = fixed_cube.coord('cell index along first dimension')
    j_coord = fixed_cube.coord('cell index along second dimension')
    assert i_coord.var_name == 'i'
    assert i_coord.standard_name is None
    assert i_coord.long_name == 'cell index along first dimension'
    assert i_coord.units == '1'
    assert i_coord.circular is False
    assert j_coord.var_name == 'j'
    assert j_coord.standard_name is None
    assert j_coord.long_name == 'cell index along second dimension'
    assert j_coord.units == '1'

    # Check ij points and bounds
    np.testing.assert_allclose(i_coord.points, [0, 1, 2])
    np.testing.assert_allclose(i_coord.bounds,
                               [[-0.5, 0.5], [0.5, 1.5], [1.5, 2.5]])
    np.testing.assert_allclose(j_coord.points, [0, 1])
    np.testing.assert_allclose(j_coord.bounds, [[-0.5, 0.5], [0.5, 1.5]])

    # Check bounds of latitude and longitude
    assert len(fixed_cube.coords('latitude')) == 1
    assert len(fixed_cube.coords('longitude')) == 1
    assert fixed_cube.coord('latitude').bounds is not None
    assert fixed_cube.coord('longitude').bounds is not None
    latitude_bounds = np.array([[[-40, -33.75, -23.75, -30.0],
                                 [-33.75, -6.25, 3.75, -23.75],
                                 [-6.25, -1.02418074021670e-14, 10.0, 3.75]],
                                [[-30.0, -23.75, -13.75, -20.0],
                                 [-23.75, 3.75, 13.75, -13.75],
                                 [3.75, 10.0, 20.0, 13.75]]])
    np.testing.assert_allclose(
        fixed_cube.coord('latitude').bounds, latitude_bounds)
    longitude_bounds = np.array([[[140.625, 99.375, 99.375, 140.625],
                                  [99.375, 140.625, 140.625, 99.375],
                                  [140.625, 99.375, 99.375, 140.625]],
                                 [[140.625, 99.375, 99.375, 140.625],
                                  [99.375, 140.625, 140.625, 99.375],
                                  [140.625, 99.375, 99.375, 140.625]]])
    np.testing.assert_allclose(
        fixed_cube.coord('longitude').bounds, longitude_bounds)
Esempio n. 7
0
def test_cl_hybrid_height_coord_fix_metadata(test_data_path):
    """Test ``fix_metadata`` for ``cl``."""
    vardef = get_var_info('CMIP6', 'Amon', 'cl')
    nc_path = test_data_path / 'common_cl_hybrid_height.nc'
    hybrid_height_coord_fix_metadata(nc_path, 'cl',
                                     ClFixHybridHeightCoord(vardef))
Esempio n. 8
0
def test_tos_fix_metadata():
    """Test ``fix_metadata`` for ``tos``."""
    grid_lat = iris.coords.DimCoord(
        [20.0, 40.0],
        bounds=[[10.0, 30.0], [30.0, 50.0]],
        var_name='rlat',
        standard_name='grid_latitude',
    )
    grid_lon = iris.coords.DimCoord(
        [10.0, 20.0, 30.0],
        bounds=[[5.0, 15.0], [15.0, 25.0], [25.0, 35.0]],
        var_name='rlon',
        standard_name='grid_longitude',
    )
    latitude = iris.coords.AuxCoord(
        [[-40.0, -20.0, 0.0], [-20.0, 0.0, 20.0]],
        var_name='lat',
        standard_name='latitude',
        units='degrees_north',
    )
    longitude = iris.coords.AuxCoord(
        [[100.0, 140.0, 180.0], [80.0, 100.0, 120.0]],
        var_name='lon',
        standard_name='longitude',
        units='degrees_east',
    )
    time_coord = iris.coords.DimCoord(
        1.0,
        bounds=[0.0, 2.0],
        var_name='time',
        standard_name='time',
        long_name='time',
        units='days since 1950-01-01',
    )

    # Create cube without bounds
    cube = iris.cube.Cube(
        np.full((1, 2, 3), 300.0),
        var_name='tos',
        standard_name='sea_surface_temperature',
        units='K',
        dim_coords_and_dims=[(time_coord, 0), (grid_lat, 1), (grid_lon, 2)],
        aux_coords_and_dims=[(latitude, (1, 2)), (longitude, (1, 2))],
    )
    assert cube.coord('latitude').bounds is None
    assert cube.coord('longitude').bounds is None

    # Apply fix
    vardef = get_var_info('CMIP6', 'Omon', 'tos')
    fix = Tos(vardef)
    cubes = iris.cube.CubeList([cube])
    fixed_cubes = fix.fix_metadata(cubes)
    assert len(fixed_cubes) == 1
    fixed_cube = fixed_cubes.extract_cube('sea_surface_temperature')
    assert fixed_cube is cube
    i_coord = fixed_cube.coord('cell index along first dimension')
    j_coord = fixed_cube.coord('cell index along second dimension')
    assert i_coord.var_name == 'i'
    assert i_coord.standard_name is None
    assert i_coord.long_name == 'cell index along first dimension'
    assert i_coord.units == '1'
    assert i_coord.circular is False
    assert j_coord.var_name == 'j'
    assert j_coord.standard_name is None
    assert j_coord.long_name == 'cell index along second dimension'
    assert j_coord.units == '1'
    np.testing.assert_allclose(i_coord.points, [0, 1, 2])
    np.testing.assert_allclose(i_coord.bounds,
                               [[-0.5, 0.5], [0.5, 1.5], [1.5, 2.5]])
    np.testing.assert_allclose(j_coord.points, [0, 1])
    np.testing.assert_allclose(j_coord.bounds, [[-0.5, 0.5], [0.5, 1.5]])
    assert fixed_cube.coord('latitude').bounds is not None
    assert fixed_cube.coord('longitude').bounds is not None
    latitude_bounds = np.array([[[-40, -33.75, -23.75, -30.0],
                                 [-33.75, -6.25, 3.75, -23.75],
                                 [-6.25, -1.02418074021670e-14, 10.0, 3.75]],
                                [[-30.0, -23.75, -13.75, -20.0],
                                 [-23.75, 3.75, 13.75, -13.75],
                                 [3.75, 10.0, 20.0, 13.75]]])
    np.testing.assert_allclose(
        fixed_cube.coord('latitude').bounds, latitude_bounds)
    longitude_bounds = np.array([[[140.625, 99.375, 99.375, 140.625],
                                  [99.375, 140.625, 140.625, 99.375],
                                  [140.625, 99.375, 99.375, 140.625]],
                                 [[140.625, 99.375, 99.375, 140.625],
                                  [99.375, 140.625, 140.625, 99.375],
                                  [140.625, 99.375, 99.375, 140.625]]])
    np.testing.assert_allclose(
        fixed_cube.coord('longitude').bounds, longitude_bounds)
Esempio n. 9
0
def test_tas_fix_metadata(tas_cubes):
    """Test ``fix_metadata`` for ``tas``."""
    vardef = get_var_info('CMIP6', 'Amon', 'tas')
    fix = Tas(vardef)
    fixed_cubes = fix.fix_metadata(tas_cubes)
    assert fixed_cubes[0].coord('latitude') == fixed_cubes[1].coord('latitude')