Repository: ioos/compliance-checker
Issue: Check is_reduced_horizontal_grid is wrong

The check for is_reduced_horizontal_grid is not properly discriminating against datasets that aren't reduced horizontal grids.  


Changed files:
tests/test_cf.py, compliance_checker/cf/cf.py

diff --git a/compliance_checker/cf/cf.py b/compliance_checker/cf/cf.py
index 4629962..3d71fbd 100644
--- a/compliance_checker/cf/cf.py
+++ b/compliance_checker/cf/cf.py
@@ -1629,40 +1629,45 @@ class CFBaseCheck(BaseCheck):
 
             valid = True
             reasoning = []
+            valid_in_variables = True
+            valid_dim = True
+            valid_coord = True
+            valid_cdim = True
 
             coords = var.coordinates.split(' ')
             for coord in coords:
+                is_reduced_horizontal_grid = True
                 if coord not in ds.dataset.variables:
-                    valid = False
+                    valid_in_variables = False
                     reasoning.append("Coordinate %s is not a proper variable" % coord)
                     continue
 
                 for dim_name in ds.dataset.variables[coord].dimensions:
 
                     if dim_name not in var.dimensions:
-                        valid = False
+                        valid_dim = False
                         reasoning.append("Coordinate %s's dimension, %s, is not a dimension of %s" %(coord, dim_name, name))
                         continue
 
                     if dim_name not in coord_vars:
-                        valid = False
+                        valid_coord = False
                         reasoning.append("Coordinate %s's dimension, %s, is not a coordinate variable" % (coord, dim_name))
                         continue
 
                     dim = ds.dataset.variables[dim_name]
                     if not hasattr(dim, 'compress'):
-                        valid = False
-                        reasoning.append("Coordinate %s's dimension, %s, does not define compress" % (coord, dim_name))
+                        is_reduced_horizontal_grid = False
                         continue
 
                     compress_dims = dim.compress.split(' ')
                     for cdim in compress_dims:
                         if cdim not in ds.dataset.dimensions:
-                            valid = False
+                            valid_cdim = False
                             reasoning.append("Dimension %s compresses non-existent dimension, %s" % (dim_name, cdim))
                             continue
-            result = Result(BaseCheck.MEDIUM,                            \\
-                            valid,                                       \\
+            if is_reduced_horizontal_grid == True:
+                result = Result(BaseCheck.MEDIUM,                            \\
+                            (valid_in_variables and valid_dim and valid_coord and valid_cdim),                                       \\
                             ('var', name, 'is_reduced_horizontal_grid'), \\
                             reasoning)
 
diff --git a/tests/test_cf.py b/tests/test_cf.py
index f8f35a0..ceb569e 100644
--- a/tests/test_cf.py
+++ b/tests/test_cf.py
@@ -583,7 +583,7 @@ class TestCF(unittest.TestCase):
 
         self.assertIn('Coordinate longitude is not a proper variable', rd['PSa'][1])
         self.assertIn("Coordinate latitude's dimension, latdim, is not a dimension of PSb", rd['PSb'][1])
-        self.assertIn("Coordinate lon_i's dimension, ijgrid, does not define compress", rd['PSc'][1])
+        assert 'PSc' not in rd.keys()
 
 
     def test_check_horz_crs_grid_mappings_projections(self):