cmor icon indicating copy to clipboard operation
cmor copied to clipboard

Unit conversion of attributes

Open rqwa opened this issue 2 years ago • 5 comments

By setting attributes with cmor.set_cur_dataset_attribute the passed argument is converted and written as a string. Is this an intended behavior and exists a possibility to keep the initial datatype?

rqwa avatar Sep 14 '21 09:09 rqwa

@rqwa do you have an example? A netcdf variable or global attribute is generally a string, if you have an alternative example that would elucidate the issue that you're raising

@taylor13 @mauzey1

durack1 avatar Sep 14 '21 22:09 durack1

global attributes are sometimes integers (e.g., realization_index) or floating point numbers (e.g., branch_time_in_child). I think if it is not too difficult, some users would like to be able to use CMOR to define additional integer or float global attributes.

taylor13 avatar Sep 14 '21 23:09 taylor13

I am currently preparing satellite observations for obs4mips. As example you can use the HOAPS data, which contains the following floats as global attributes.

geospatial_lat_min = -80. ;
geospatial_lat_max = 80. ;
geospatial_lon_min = -180. ;
geospatial_lon_max = 180. ;

rqwa avatar Sep 15 '21 06:09 rqwa

I am trying to recall whether netcdf 4.x global attributes can have types other than char arrays. Is there some documentation that someone is familiar with that defines exactly that? If type recasting is being done, then maybe for a CMOR4 we might want to reconsider this behaviour in light of the latest netcdf-c 4.9.x functionality?

Note to self https://docs.unidata.ucar.edu/netcdf-c/current/group__attributes.html

durack1 avatar Feb 27 '24 18:02 durack1

Yes, they can. The CF conventions (within the netcdf constraints) has both numeric and string attributes, and the numeric values can be integers, single precision float, double precision float, and probably other types too. For the list and type of CF attributes, see: https://cfconventions.org/Data/cf-conventions/cf-conventions-1.11/cf-conventions.html#attribute-appendix .

I agree that we want CMOR to write attributes of the correct type. I think it worked o.k. at least in the past. For example, I think the missing_value was written as proper type. And the branch_times should have been written double precision. And things like "realization_index" should have been integers.

taylor13 avatar Feb 27 '24 21:02 taylor13