Skip to content

Commit 21f3d87

Browse files
authored
Merge pull request #353 from ESMValGroup/fix_gpp_cesm1_bgc
Added fix for GPP of CESM1-BGC
2 parents 56a4818 + 0f77554 commit 21f3d87

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

esmvalcore/cmor/_fixes/cmip5/cesm1_bgc.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def fix_data(self, cube):
2828
return cube
2929

3030

31-
class Nbp(Fix):
32-
"""Fixes for nbp variable."""
31+
class Gpp(Fix):
32+
"""Fixes for gpp variable."""
3333

3434
def fix_data(self, cube):
3535
"""Fix data.
@@ -47,3 +47,7 @@ def fix_data(self, cube):
4747
"""
4848
data = da.ma.masked_equal(cube.core_data(), 1.0e33)
4949
return cube.copy(data)
50+
51+
52+
class Nbp(Gpp):
53+
"""Fixes for nbp variable."""
Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,63 @@
11
"""Tests for CESM1-BGC fixes."""
22
import unittest
33

4+
import numpy as np
45
from cf_units import Unit
56
from iris.cube import Cube
67

8+
from esmvalcore.cmor._fixes.cmip5.cesm1_bgc import Co2, Gpp, Nbp
79
from esmvalcore.cmor.fix import Fix
8-
from esmvalcore.cmor._fixes.cmip5.cesm1_bgc import Co2
910

1011

1112
class TestCo2(unittest.TestCase):
1213
"""Tests for co2."""
13-
1414
def setUp(self):
1515
"""Prepare tests."""
1616
self.cube = Cube([1.0], var_name='co2', units='J')
1717
self.fix = Co2()
1818

1919
def test_get(self):
2020
"""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()])
2323

2424
def test_fix_data(self):
2525
"""Test fix to set units correctly."""
2626
cube = self.fix.fix_data(self.cube)
2727
self.assertEqual(cube.data[0], 28.966 / 44.0)
2828
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

Comments
 (0)