def test_thetao_fix_metadata(thetao_cubes): """Test ``fix_metadata`` for ``thetao``.""" vardef = get_var_info('CMIP6', 'Omon', 'thetao') fix_omon = Omon(vardef) fix_allvars = AllVars(vardef) out_cubes = fix_omon.fix_metadata(thetao_cubes) out_cubes = fix_allvars.fix_metadata(out_cubes) assert out_cubes is thetao_cubes assert len(out_cubes) == 1 out_cube = out_cubes[0] # Check data of cube np.testing.assert_allclose(out_cube.data, [[[[1, 0], [3, 2]], [[5, 4], [7, 6]]], [[[9, 8], [11, 10]], [[13, 12], [15, 14]]]]) # Check data of longitude lon_coord = out_cube.coord('longitude') np.testing.assert_allclose(lon_coord.points, [357.1875, 359.0625]) np.testing.assert_allclose(lon_coord.bounds, [[356.25, 358.125], [358.125, 360.0]]) # Check metadata of depth coordinate depth_coord = out_cube.coord('depth') assert depth_coord.standard_name == 'depth' assert depth_coord.var_name == 'lev' assert depth_coord.long_name == 'ocean depth coordinate' assert depth_coord.units == 'm' assert depth_coord.attributes == {'positive': 'down'}
def test_allvars_fix_metadata(cubes): fix = AllVars(None) out_cubes = fix.fix_metadata(cubes) assert cubes is out_cubes for cube in out_cubes: if cube.var_name == 'ps': assert cube.standard_name == 'air_pressure' assert cube.long_name == 'Air pressure' elif cube.var_name == 'tas' or cube.var_name == 'ta': assert cube.standard_name == 'air_temperature' assert cube.long_name == 'Air Temperature' else: assert False, "Invalid var_name" try: lat_coord = cube.coord('latitude') except iris.exceptions.CoordinateNotFoundError: assert cube.var_name == 'ps' else: assert lat_coord.var_name == 'lat' assert lat_coord.standard_name == 'latitude' assert lat_coord.long_name == 'latitude' try: lon_coord = cube.coord('longitude') except iris.exceptions.CoordinateNotFoundError: assert cube.var_name == 'ps' else: assert lon_coord.var_name == 'lon' assert lon_coord.standard_name == 'longitude' assert lon_coord.long_name == 'longitude' if 'parent_time_units' in cube.attributes: assert cube.attributes['parent_time_units'] == ( 'days since 0000-00-00')
def test_allvars_fix_lon_bounds(cubes_bounds): fix = AllVars(None) out_cubes = fix.fix_metadata(cubes_bounds) assert cubes_bounds is out_cubes for cube in out_cubes: try: lon_coord = cube.coord('longitude') except iris.exceptions.CoordinateNotFoundError: pass else: assert lon_coord.bounds[-1][-1] == 358.125
def test_allvars_fix_metadata(cubes): fix = AllVars(None) out_cubes = fix.fix_metadata(cubes) assert cubes is out_cubes for cube in out_cubes: try: lat_coord = cube.coord('latitude') except iris.exceptions.CoordinateNotFoundError: pass else: assert lat_coord.var_name == 'lat' assert lat_coord.standard_name == 'latitude' try: lon_coord = cube.coord('longitude') except iris.exceptions.CoordinateNotFoundError: pass else: assert lon_coord.var_name == 'lon' assert lon_coord.standard_name == 'longitude' if 'parent_time_units' in cube.attributes: assert cube.attributes['parent_time_units'] == ( 'days since 0000-00-00')
def test_get_tas_fix(): fix = Fix.get_fixes('CMIP6', 'MCM-UA-1-0', 'Amon', 'tas') assert fix == [Tas(None), AllVars(None)]
def test_get_allvars_fix(): fix = Fix.get_fixes('CMIP6', 'MCM-UA-1-0', 'Amon', 'arbitrary_var_name_and_wrong_lon_bnds') assert fix == [AllVars(None)]
def test_get_thetao_fix(): """Test getting of fix.""" fix = Fix.get_fixes('CMIP6', 'MCM-UA-1-0', 'Omon', 'thetao') assert fix == [Omon(None), AllVars(None)]
def test_get_tas_fix(): fix = Fix.get_fixes('CMIP6', 'MCM-UA-1-0', 'tas') assert fix == [AllVars(), Tas()]
def test_get_allvars_fix(): fix = Fix.get_fixes('CMIP6', 'MCM-UA-1-0', 'arbitrary_var_name') assert fix == [AllVars()]