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

Error on reading files with conformant Conventions value 'CF-1.*-draft' #297

Closed
sadielbartholomew opened this issue May 21, 2024 · 1 comment · May be fixed by #296
Closed

Error on reading files with conformant Conventions value 'CF-1.*-draft' #297

sadielbartholomew opened this issue May 21, 2024 · 1 comment · May be fixed by #296
Labels
bug Something isn't working netCDF read Relating to reading netCDF datasets

Comments

@sadielbartholomew
Copy link
Member

The working CF Conformance document. i.e. the one in draft form, states that (using the example of the current working document i.e. v.1.12)

Files that conform to the CF version 1.12 draft conventions must indicate this by setting the global Conventions attribute to contain the CF string value "CF-1.12-draft".

This clearly gets changed to 'CF-1.12' when the version is released such that it is no longer draft form, but to me that implies that "CF-1.12-draft" and similarly any 'CF-<valid version string>-draft' value should strictly be a conformant value for the Conventions global attribute. However, when we use cfdm (current main branch, and same for 1.11.1.0/last release) to read in such a file, it errors:

>>> import cfdm
>>> import netCDF4
>>> f = cfdm.example_field(0)
>>> cfdm.write(f, "delme.nc")
>>> n = netCDF4.Dataset("delme.nc", "a")
>>> n.Conventions
'CF-1.11'
>>> n.Conventions = "CF-1.12-draft"
>>> n.Conventions
'CF-1.12-draft'
>>> n.close()
>>> g = cfdm.read("delme.nc")[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/slb93/git-repos/cfdm/cfdm/read_write/read.py", line 328, in read
    fields = netcdf.read(
             ^^^^^^^^^^^^
  File "/home/slb93/git-repos/cfdm/cfdm/decorators.py", line 171, in verbose_override_wrapper
    return method_with_verbose_kwarg(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/slb93/git-repos/cfdm/cfdm/read_write/netcdf/netcdfread.py", line 1056, in read
    g["file_version"] = Version(file_version)
                        ^^^^^^^^^^^^^^^^^^^^^
  File "/home/slb93/miniconda3/lib/python3.11/site-packages/packaging/version.py", line 198, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
packaging.version.InvalidVersion: Invalid version: '1.12-draft'

Whereas such a file should be able to be read in without issue. This can be addressed as part of my PR #296.

@sadielbartholomew sadielbartholomew added bug Something isn't working netCDF read Relating to reading netCDF datasets labels May 21, 2024
@sadielbartholomew
Copy link
Member Author

sadielbartholomew commented May 30, 2024

Closing, given I have checked regarding the validity of in 'CF-<vn>-draft' as a conformant value in https://github.com/orgs/cf-convention/discussions/321 and it has since been confirmed that it is not valid - the documentation is just unclear in that respect (and now the CF Conventions are aware, we are going to amend them in some way to remove that source of confusion/ambiguity).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working netCDF read Relating to reading netCDF datasets
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant