Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing grib / amip in CF StandardNameTable 87 #1132

Open
Arnoques opened this issue Dec 12, 2024 · 3 comments
Open

Missing grib / amip in CF StandardNameTable 87 #1132

Arnoques opened this issue Dec 12, 2024 · 3 comments

Comments

@Arnoques
Copy link

Version of compliance checker running:
5.1.1

Describe the checker this affects:
CF checker

Attach a minimal CDL or NetCDF file which is able to reproduce the issue
Since I can't attach an actual file, this is a minimal python that generates a failing netCDF file

import netCDF4

root = netCDF4.Dataset('minimal.nc', 'w')
root.standard_name_vocabulary = 'CF Standard Name Table v87'  # Using older tables does not trigger the issue
scanline_var = root.createVariable(varname='latitude', datatype='i4')
scanline_var.standard_name = 'latitude'
scanline_var.units = 'degrees_north'
scanline_var[:] = 10

To Reproduce:

  1. Run the above python code
  2. compliance-checker --test cf:1.8 --verbose minimal.nc

Describe the issue below:
The tool outputs this internal error:

cf:1.8.check_units: list index out of range

The error arises in compliance_checker/cf/util.py line 209, when looking for grib and amip in the standards table. Version 87 does not include them, and the _get function fails for a missing non-required attribute.

I suggest adding the following fix in compliance_checker/cf/util.py::NameEntry:

        def _get(self, entrynode, attrname, required=False):
            vals = entrynode.xpath(attrname)
            if len(vals) > 1:
                raise Exception("Multiple attrs (%s) found" % attrname)
            elif required and len(vals) == 0:
                raise Exception("Required attr (%s) not found" % attrname)
+            elif len(vals) == 0:
+                return None

            return vals[0].text
@benjwadams
Copy link
Contributor

Please create a pull request and I'll review this.

@Unichronic
Copy link

Can I work on this? @benjwadams

@Arnoques
Copy link
Author

Thanks for working on it, @benjwadams!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants