Skip to content

Commit

Permalink
cell_boundaries additional checks. Ticket #32
Browse files Browse the repository at this point in the history
  • Loading branch information
RosalynHatcher committed Feb 26, 2018
1 parent 12a3849 commit b7ed52f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
37 changes: 25 additions & 12 deletions src/cfchecker/cfchecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,14 +976,19 @@ def getCoordinateDataVars(self):
else:
self._add_error("Incorrect number of dimensions for boundary variable: %s" % bounds, bounds, code="7.1")

if hasattr(self.f.variables[bounds], 'units'):
if self.f.variables[bounds].units != self.f.variables[var].units:
self._add_error("Boundary var %s has inconsistent units to %s" % (bounds, var),
bounds, code="7.1")
if hasattr(self.f.variables[bounds], 'standard_name') and hasattr(self.f.variables[var], 'standard_name'):
if self.f.variables[bounds].standard_name != self.f.variables[var].standard_name:
self._add_error("Boundary var %s has inconsistent std_name to %s" % (bounds, var),
bounds, code="7.1")
l = ['units', 'standard_name']
if self.version >= vn1_7:
l[len(l):] = ['axis', 'positive', 'calendar', 'leap_month', 'leap_year', 'month_lengths']
for x in l:
if hasattr(self.f.variables[bounds], x):
if self.version >= vn1_7:
self._add_warn("Boundary var %s should not have attribute %s" % (bounds, x),
bounds, code="7.1")
if (hasattr(self.f.variables[var], x)
and self.f.variables[bounds].getncattr(x) != self.f.variables[var].getncattr(x)):
self._add_error("Boundary var %s has inconsistent %s to %s" % (bounds, x, var),
bounds, code="7.1")

else:
self._add_error("bounds attribute referencing non-existent variable %s" % bounds,
bounds, code="7.1")
Expand Down Expand Up @@ -1438,7 +1443,6 @@ def chkGlobalAttributes(self):
# External variables
if self.version >= vn1_7 and hasattr(self.f, 'external_variables'):
external_vars = self.f.external_variables

if not self.parseBlankSeparatedList(external_vars) :
self._add_error("external_variables attribute must be a blank separated list of variable names",
code="2.6.3")
Expand Down Expand Up @@ -1935,9 +1939,18 @@ def chkCellMeasures(self,varName):
variable=splitIter.next()

if variable not in self.f.variables:
self._add_warn("cell_measures refers to variable %s that doesn't exist in this netCDF file. " % variable +
"This is strictly an error if the cell_measures variable is not included in the dataset.",
varName, code="7.2")
if self.version >= vn1_7:
# Variable must exist in the file or be named by the external_variables attribute
msg = "cell_measures variable %s must either exist in this netCDF file " \
"or be named by the external_variables attribute" % variable
if not hasattr(self.f, 'external_variables'):
self._add_error(msg, varName, code="7.2")
elif variable not in string.split(self.f.external_variables):
self._add_error(msg, varName, code="7.2")
else:
self._add_warn("cell_measures refers to variable %s that doesn't exist in this netCDF file. " % variable +
"This is strictly an error if the cell_measures variable is not included in the dataset.",
varName, code="7.2")

else:
# Valid variable name in cell_measures so carry on with tests.
Expand Down
6 changes: 4 additions & 2 deletions test_files/stdName_test.check
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Using Area Type Table Version 6 (22 February 2017)
Using Standardized Region Name Table Version 2 (12 June 2013)

WARN: (2.6.1): Inconsistency - This netCDF file appears to contain CF-1.0 data, but you've requested a validity check against CF-1.7
ERROR: (7.1): Boundary var time_bnds has inconsistent std_name to time
WARN: (7.1): Boundary var time_bnds should not have attribute units
WARN: (7.1): Boundary var time_bnds should not have attribute standard_name
ERROR: (7.1): Boundary var time_bnds has inconsistent standard_name to time
WARN: (7.1): Data for variable time lies outside cell boundaries

------------------
Expand Down Expand Up @@ -39,5 +41,5 @@ Checking variable: time_bnds
------------------

ERRORS detected: 3
WARNINGS given: 4
WARNINGS given: 6
INFORMATION messages: 0

0 comments on commit b7ed52f

Please sign in to comment.