JuliaClimate / meta

For discussions about JuliaClimate implementations
MIT License
6 stars 1 forks source link

CF Conventions for NetCDF saving, regarding units #5

Open natgeo-wong opened 4 years ago

natgeo-wong commented 4 years ago

Hey! Not sure if this was the right place to ask, but I just have a quick question regarding units when saving data for NetCDF.

For things like precipitation, I understand that the default CF convention is in m s-1, but sometimes it would make sense to save in terms of mm s-1 or even mm hr-1. Is it really of utmost necessity to follow the units listed on the CF Standard Names page in http://cfconventions.org/Data/cf-standard-names/70/build/cf-standard-name-table.html or are we allowed some degree of flexibility for units?

briochemc commented 4 years ago

Not sure this is really what you are asking but I love using Unitful.jl with every NetCDF file I use so that there is no unit confusion. So each time I deal with a new NetCDF file, I write a little dictionary mapping whatever strings are used in the unit attribute of variables in the NetCDF to Unitful units. E.g., I would map "micromoles_per_liter" to u"μmol/L", and generally I would convert it to SI with upreferred.

My points being that (i) there will always be someone creating data with a different unit than you would like, but that's not a problem for Julia users if you make sure you use something like Unitful while reading the data. And (ii) that maybe when we (Julia users) create NetCDF files, we should set the unit attribute of data to a Unitful.jl-parsable format (i.e., prefer "m / s" to "meters_per_second").

gaelforget commented 4 years ago

Units seem particularly important for coordinate variables (e.g. degrees_north). Not sure about common variables. We were talking about something related with @lmilechin earlier

My assumption would be that most software would be able to do these conversions on the fly when e.g. reading netcdf. Others in the org will have a deeper understanding of this than me though.

Balinus commented 4 years ago

I'd say that you should follow as much as possible the conventions. For precipitation, the convention definition is a flux. Hence, the units should be kg·m−2·s−1. For liquid at the usual temperature for liquid precipitation, it translates to mm·s-1. Hope this helps!

Totally agree with @briochemc comment. That's a robust way to go ahead, if you can use Unitful.

briochemc commented 4 years ago

I wanted to add two things.

(I'm just throwing ideas here...)

Balinus commented 4 years ago

I think it's a good idea!