-
Notifications
You must be signed in to change notification settings - Fork 287
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
Iris incorrectly failing valid netcdf names #5929
Comments
Thanks @ScottWales for raising this. So, Iris generally follows CF conventions, and in many cases requires them. We consider "CF strictness" as generally quite an important feature of Iris, though we do also have quite a few workarounds for common violations (like invalid "standard_name" and "units" attributes, and dimension variables in "coordinates" attributes). The appropriate level of this has also been a subject of some considerable discussion in recent times. Unfortunately, we don't have a workaround for this problem. Obviously we can fix this error message to give the proper context, but it remains a fact that Iris is rather strict about this + it is hard to work around.
I tested that on your minimal example + it does work for me. Of course, in an actual case it may not be so simple, as you may need to correct references to the variable elsewhere, like e.g. Does this help at all @ScottWales ? |
Ok update on this -- I was a bit wrong... It seems that the current restrictions in Iris don't actually follow the CF rules, but something slightly similar, which is in fact the rules given for "Classic" NetCDF -- effectively NetCDF3. However, as also stated in that para, NetCDF4 removes most of those restrictions
Actually though, I would still say that ideally Iris probably should be enforcing the CF rules -- which would actually be more restrictive than what we currently have. In general , I'd suggest a reasonable goal that the cf-checker will not object to anything saved from Iris : As we don't currently have any special checks on save, that is just what we allow for setting a "cube.var_name", which is exactly the scope of the regexp and the error which you have noted. Just to confuse things further, though, the CF community are currently discussing the possibility of allowing basically any valid netcdf names after all (!) |
( But practically, that would be a painful journey involving breaking changes + deprecations ) |
🐛 Bug Report
Iris is incorrectly validating netcdf variable names, rejecting opening valid files
How To Reproduce
Steps to reproduce the behaviour:
Iris fails in iris/common/mixin.py", line 177 with error
ValueError: 'a(x)' is not a valid NetCDF variable name.
Expected behaviour
Iris should safely load the variable with a valid NetCDF name.
Iris matches names against a regex at https://github.com/SciTools/iris/blob/main/lib/iris/common/metadata.py#L41-L43, referencing an outdated link to netCDF documentation. If validation is performed on reading NetCDF files it should follow the current format rules:
Alternately validation could be performed only when writing out files, or left to the NetCDF library.
Unidata give this guidance on netcdf names in the file format documentation:
The netCDF4 library will give an error if you try to create a variable with an invalid name, e.g. one that ends with whitespace:
Environment
Additional context
Full stack trace
The text was updated successfully, but these errors were encountered: