示例#1
0
class TestAllVars(unittest.TestCase):
    """Tests for fixes of all variables."""
    def setUp(self):
        """Set up tests."""
        vardef = get_var_info('CMIP6', 'Omon', 'tos')
        self.fix = AllVars(vardef)
        self.cube = Cube(np.random.rand(2, 2, 2), var_name='tos')
        self.cube.add_aux_coord(
            AuxCoord(np.random.rand(2, 2),
                     var_name='nav_lat',
                     standard_name='latitude'), (1, 2))
        self.cube.add_aux_coord(
            AuxCoord(np.random.rand(2, 2),
                     var_name='nav_lon',
                     standard_name='longitude'), (1, 2))

    def test_fix_metadata_ocean_var(self):
        """Test ``fix_metadata`` for ocean variables."""
        cell_area = Cube(np.random.rand(2, 2), standard_name='cell_area')
        cubes = self.fix.fix_metadata(CubeList([self.cube, cell_area]))

        self.assertEqual(len(cubes), 1)
        cube = cubes[0]
        self.assertEqual(cube.var_name, 'tos')
        self.assertEqual(cube.coord('latitude').var_name, 'lat')
        self.assertEqual(cube.coord('longitude').var_name, 'lon')

    def test_fix_data_no_lat(self):
        """Test ``fix_metadata`` when no latitude is present."""
        self.cube.remove_coord('latitude')
        cubes = self.fix.fix_metadata(CubeList([self.cube]))

        self.assertEqual(len(cubes), 1)
        cube = cubes[0]
        self.assertEqual(cube.coord('longitude').var_name, 'lon')
        with self.assertRaises(CoordinateNotFoundError):
            self.cube.coord('latitude')

    def test_fix_data_no_lon(self):
        """Test ``fix_metadata`` when no longitude is present."""
        self.cube.remove_coord('longitude')
        cubes = self.fix.fix_metadata(CubeList([self.cube]))

        self.assertEqual(len(cubes), 1)
        cube = cubes[0]
        self.assertEqual(cube.coord('latitude').var_name, 'lat')
        with self.assertRaises(CoordinateNotFoundError):
            self.cube.coord('longitude')

    def test_fix_data_no_lat_lon(self):
        """Test ``fix_metadata`` for cubes with no latitude and longitude."""
        self.cube.remove_coord('latitude')
        self.cube.remove_coord('longitude')
        cubes = self.fix.fix_metadata(CubeList([self.cube]))

        self.assertEqual(len(cubes), 1)
        with self.assertRaises(CoordinateNotFoundError):
            self.cube.coord('latitude')
        with self.assertRaises(CoordinateNotFoundError):
            self.cube.coord('longitude')
示例#2
0
class TestAllVars(unittest.TestCase):
    def setUp(self):
        self.fix = AllVars()
        self.cube = Cube(np.random.rand(2, 2, 2), var_name='ch4')
        self.cube.add_aux_coord(
            AuxCoord(np.random.rand(2, 2),
                     var_name='nav_lat',
                     standard_name='latitude'), (1, 2))
        self.cube.add_aux_coord(
            AuxCoord(np.random.rand(2, 2),
                     var_name='nav_lon',
                     standard_name='longitude'), (1, 2))

    def test_fix_metadata_ocean_var(self):
        cell_area = Cube(np.random.rand(2, 2), standard_name='cell_area')
        cubes = self.fix.fix_metadata(CubeList([self.cube, cell_area]))

        self.assertEqual(len(cubes), 1)
        cube = cubes[0]
        self.assertEqual(cube.coord('latitude').var_name, 'lat')
        self.assertEqual(cube.coord('longitude').var_name, 'lon')
        self.cube.coord('cell_area')

    def test_fix_data_other_var(self):
        cubes = self.fix.fix_metadata(CubeList([self.cube]))

        self.assertEqual(len(cubes), 1)
        cube = cubes[0]
        self.assertEqual(cube.coord('latitude').var_name, 'nav_lat')
        self.assertEqual(cube.coord('longitude').var_name, 'nav_lon')
        with self.assertRaises(CoordinateNotFoundError):
            self.cube.coord('cell_area')
示例#3
0
 def setUp(self):
     self.fix = AllVars()
     self.cube = Cube(np.random.rand(2, 2, 2), var_name='ch4')
     self.cube.add_aux_coord(
         AuxCoord(np.random.rand(2, 2),
                  var_name='nav_lat',
                  standard_name='latitude'), (1, 2))
     self.cube.add_aux_coord(
         AuxCoord(np.random.rand(2, 2),
                  var_name='nav_lon',
                  standard_name='longitude'), (1, 2))
示例#4
0
 def setUp(self):
     """Set up tests."""
     vardef = get_var_info('CMIP6', 'Omon', 'tos')
     self.fix = AllVars(vardef)
     self.cube = Cube(np.random.rand(2, 2, 2), var_name='tos')
     self.cube.add_aux_coord(
         AuxCoord(np.random.rand(2, 2),
                  var_name='nav_lat',
                  standard_name='latitude'), (1, 2))
     self.cube.add_aux_coord(
         AuxCoord(np.random.rand(2, 2),
                  var_name='nav_lon',
                  standard_name='longitude'), (1, 2))
示例#5
0
def test_get_clcalipso_fix():
    """Test getting of fix."""
    fix = Fix.get_fixes('CMIP6', 'IPSL-CM6A-LR', 'CFmon', 'clcalipso')
    assert fix == [Clcalipso(None), AllVars(None)]
示例#6
0
def test_get_thetao_fix():
    """Test getting of fix."""
    fix = Fix.get_fixes('CMIP6', 'IPSL-CM6A-LR', 'Omon', 'thetao')
    assert fix == [Omon(None), AllVars(None)]