|
1 | 1 | """Tests for CESM1-BGC fixes.""" |
2 | 2 | import unittest |
3 | 3 |
|
| 4 | +import numpy as np |
4 | 5 | from cf_units import Unit |
5 | 6 | from iris.cube import Cube |
6 | 7 |
|
| 8 | +from esmvalcore.cmor._fixes.cmip5.cesm1_bgc import Co2, Gpp, Nbp |
7 | 9 | from esmvalcore.cmor.fix import Fix |
8 | | -from esmvalcore.cmor._fixes.cmip5.cesm1_bgc import Co2 |
9 | 10 |
|
10 | 11 |
|
11 | 12 | class TestCo2(unittest.TestCase): |
12 | 13 | """Tests for co2.""" |
13 | | - |
14 | 14 | def setUp(self): |
15 | 15 | """Prepare tests.""" |
16 | 16 | self.cube = Cube([1.0], var_name='co2', units='J') |
17 | 17 | self.fix = Co2() |
18 | 18 |
|
19 | 19 | def test_get(self): |
20 | 20 | """Test fix get""" |
21 | | - self.assertListEqual( |
22 | | - Fix.get_fixes('CMIP5', 'CESM1-BGC', 'co2'), [Co2()]) |
| 21 | + self.assertListEqual(Fix.get_fixes('CMIP5', 'CESM1-BGC', 'co2'), |
| 22 | + [Co2()]) |
23 | 23 |
|
24 | 24 | def test_fix_data(self): |
25 | 25 | """Test fix to set units correctly.""" |
26 | 26 | cube = self.fix.fix_data(self.cube) |
27 | 27 | self.assertEqual(cube.data[0], 28.966 / 44.0) |
28 | 28 | self.assertEqual(cube.units, Unit('J')) |
| 29 | + |
| 30 | + |
| 31 | +class TestGpp(unittest.TestCase): |
| 32 | + """Tests for gpp.""" |
| 33 | + def setUp(self): |
| 34 | + """Prepare tests.""" |
| 35 | + self.cube = Cube([1.0, 1.0e33, 2.0]) |
| 36 | + self.fix = Gpp() |
| 37 | + |
| 38 | + def test_get(self): |
| 39 | + """Test fix get""" |
| 40 | + self.assertListEqual(Fix.get_fixes('CMIP5', 'CESM1-BGC', 'gpp'), |
| 41 | + [Gpp()]) |
| 42 | + |
| 43 | + def test_fix_data(self): |
| 44 | + """Test fix to set missing values correctly.""" |
| 45 | + cube = self.fix.fix_data(self.cube) |
| 46 | + np.testing.assert_allclose(cube.data[0], 1.0) |
| 47 | + np.testing.assert_allclose(cube.data[2], 2.0) |
| 48 | + assert not np.ma.is_masked(cube.data[0]) |
| 49 | + assert np.ma.is_masked(cube.data[1]) |
| 50 | + assert not np.ma.is_masked(cube.data[2]) |
| 51 | + |
| 52 | + |
| 53 | +class TestNbp(TestGpp): |
| 54 | + """Tests for nbp.""" |
| 55 | + def setUp(self): |
| 56 | + """Prepare tests.""" |
| 57 | + self.cube = Cube([1.0, 1.0e33, 2.0]) |
| 58 | + self.fix = Nbp() |
| 59 | + |
| 60 | + def test_get(self): |
| 61 | + """Test fix get""" |
| 62 | + self.assertListEqual(Fix.get_fixes('CMIP5', 'CESM1-BGC', 'nbp'), |
| 63 | + [Nbp()]) |
0 commit comments