PCMDI / cmor

Climate Model Output Rewriter
BSD 3-Clause "New" or "Revised" License
51 stars 33 forks source link

Unit conversion of attributes #630

Open rqwa opened 3 years ago

rqwa commented 3 years ago

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?

durack1 commented 3 years ago

@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

taylor13 commented 3 years ago

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.

rqwa commented 2 years ago

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. ;
durack1 commented 6 months ago

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

taylor13 commented 6 months ago

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.