Repository: ESMValGroup/ESMValCore

Issue:
Masking of CESM1-BGC's gpp wrong
The missing value for `gpp` of `CESM1-BGC` is not set correctly, just like `nbp`.

Discussion:

Patch:
diff --git a/esmvalcore/cmor/_fixes/cmip5/cesm1_bgc.py b/esmvalcore/cmor/_fixes/cmip5/cesm1_bgc.py
index 3bc2d3474..d213ea04d 100644
--- a/esmvalcore/cmor/_fixes/cmip5/cesm1_bgc.py
+++ b/esmvalcore/cmor/_fixes/cmip5/cesm1_bgc.py
@@ -28,8 +28,8 @@ class Co2(Fix):
         return cube
 
 
-class Nbp(Fix):
-    """Fixes for nbp variable."""
+class Gpp(Fix):
+    """Fixes for gpp variable."""
 
     def fix_data(self, cube):
         """Fix data.
@@ -47,3 +47,7 @@ class Nbp(Fix):
         """
         data = da.ma.masked_equal(cube.core_data(), 1.0e33)
         return cube.copy(data)
+
+
+class Nbp(Gpp):
+    """Fixes for nbp variable."""


Test patch:
diff --git a/tests/integration/cmor/_fixes/cmip5/test_cesm1_bgc.py b/tests/integration/cmor/_fixes/cmip5/test_cesm1_bgc.py
index 03fd313d8..a41e759fd 100644
--- a/tests/integration/cmor/_fixes/cmip5/test_cesm1_bgc.py
+++ b/tests/integration/cmor/_fixes/cmip5/test_cesm1_bgc.py
@@ -1,16 +1,16 @@
 """Tests for CESM1-BGC fixes."""
 import unittest
 
+import numpy as np
 from cf_units import Unit
 from iris.cube import Cube
 
+from esmvalcore.cmor._fixes.cmip5.cesm1_bgc import Co2, Gpp, Nbp
 from esmvalcore.cmor.fix import Fix
-from esmvalcore.cmor._fixes.cmip5.cesm1_bgc import Co2
 
 
 class TestCo2(unittest.TestCase):
     """Tests for co2."""
-
     def setUp(self):
         """Prepare tests."""
         self.cube = Cube([1.0], var_name='co2', units='J')
@@ -18,11 +18,46 @@ class TestCo2(unittest.TestCase):
 
     def test_get(self):
         """Test fix get"""
-        self.assertListEqual(
-            Fix.get_fixes('CMIP5', 'CESM1-BGC', 'co2'), [Co2()])
+        self.assertListEqual(Fix.get_fixes('CMIP5', 'CESM1-BGC', 'co2'),
+                             [Co2()])
 
     def test_fix_data(self):
         """Test fix to set units correctly."""
         cube = self.fix.fix_data(self.cube)
         self.assertEqual(cube.data[0], 28.966 / 44.0)
         self.assertEqual(cube.units, Unit('J'))
+
+
+class TestGpp(unittest.TestCase):
+    """Tests for gpp."""
+    def setUp(self):
+        """Prepare tests."""
+        self.cube = Cube([1.0, 1.0e33, 2.0])
+        self.fix = Gpp()
+
+    def test_get(self):
+        """Test fix get"""
+        self.assertListEqual(Fix.get_fixes('CMIP5', 'CESM1-BGC', 'gpp'),
+                             [Gpp()])
+
+    def test_fix_data(self):
+        """Test fix to set missing values correctly."""
+        cube = self.fix.fix_data(self.cube)
+        np.testing.assert_allclose(cube.data[0], 1.0)
+        np.testing.assert_allclose(cube.data[2], 2.0)
+        assert not np.ma.is_masked(cube.data[0])
+        assert np.ma.is_masked(cube.data[1])
+        assert not np.ma.is_masked(cube.data[2])
+
+
+class TestNbp(TestGpp):
+    """Tests for nbp."""
+    def setUp(self):
+        """Prepare tests."""
+        self.cube = Cube([1.0, 1.0e33, 2.0])
+        self.fix = Nbp()
+
+    def test_get(self):
+        """Test fix get"""
+        self.assertListEqual(Fix.get_fixes('CMIP5', 'CESM1-BGC', 'nbp'),
+                             [Nbp()])