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

[PI] Aligning save behaviour of cube with units "unknown" and "no-unit" #3394

Closed
bjlittle opened this issue Sep 9, 2019 · 4 comments
Closed

Comments

@bjlittle
Copy link
Member

bjlittle commented Sep 9, 2019

Consider the following treatment of the cube units for the value unknown and no-unit.

First, create come appropriate cubes, and save them (using the latest upstream/master pre 2.3.0):

>>> import iris
>>> nounit = iris.cube.Cube(1, 'air_temp', units='no unit')
>>> nounit = iris.cube.Cube(1, 'air_temperature', units='no unit')
>>> iris.save(nounit, 'nounit.nc')
>>> unknown = iris.cube.Cube(1, 'air_temperature', units='unknown')
>>> iris.save(unknown, 'unknown.nc')

Now, let's look at the resultant NetCDF files:

$ ncdump -h nounit.nc
netcdf nounit {
variables:
	int64 air_temperature ;
		air_temperature:standard_name = "air_temperature" ;
		air_temperature:units = "no_unit" ;

// global attributes:
		:Conventions = "CF-1.5" ;
}

$ ncdump -h unknown.nc 
netcdf unknown {
variables:
	int64 air_temperature ;
		air_temperature:standard_name = "air_temperature" ;

// global attributes:
		:Conventions = "CF-1.5" ;

We created the no_unit unit (the aliases in cf-units for no_unit are -, no unit, no-unit, and nounit) for convenience, and doesn't actually map to an valid UDUNITS unit. This is also true for the unknown unit.

The difference here is that iris doesn't explicitly save to NetCDF any units of unknown, and I argue this should also be the case for the no_unit unit e.g.,

$ cfchecker nounit.nc
...
------------------
Checking variable: air_temperature
------------------
ERROR: (3.1): Invalid units: no_unit

ERRORS detected: 1
WARNINGS given: 1
INFORMATION messages: 0

Both the unknown and no_unit units should have the same behaviour and should not be saved to NetCDF.

Plus, NetCDF with units containing no_unit may break upstream tools, as it's clearly not CF compliant.

@bjlittle
Copy link
Member Author

bjlittle commented Sep 9, 2019

Ping @lbdreyer, what do you think?

@stephenworsley
Copy link
Contributor

For reference, it's probably just this line which needs changing in order to make this change:

if dimensional_metadata.units != "unknown":

@rcomer
Copy link
Member

rcomer commented Dec 16, 2019

Does the cfchecker complain about no_units in general, or is it specifically because you attached it to air_temperature? air_temperature is a standard name so units should be convertible to Kelvin.

It seems to me that no_unit is a valid option to say “units aren’t meaningful here”. E.g. it’s used for all the string coords in iris.coord_categorisation. So it makes sense to me to continue saving it.

@abooton abooton changed the title Aligning save behaviour of cube with units "unknown" and "no-unit" PI-3713: Aligning save behaviour of cube with units "unknown" and "no-unit" Jun 3, 2020
@abooton abooton changed the title PI-3713: Aligning save behaviour of cube with units "unknown" and "no-unit" Aligning save behaviour of cube with units "unknown" and "no-unit" Jun 3, 2020
@abooton abooton changed the title Aligning save behaviour of cube with units "unknown" and "no-unit" [PI] Aligning save behaviour of cube with units "unknown" and "no-unit" Jun 10, 2020
@stephenworsley
Copy link
Contributor

Closed by #3711.

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

No branches or pull requests

4 participants