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

CF Conventions for NetCDF saving, regarding units #5

Open
natgeo-wong opened this issue Feb 1, 2020 · 5 comments
Open

CF Conventions for NetCDF saving, regarding units #5

natgeo-wong opened this issue Feb 1, 2020 · 5 comments

Comments

@natgeo-wong
Copy link
Member

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
Copy link

briochemc commented Feb 1, 2020

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
Copy link
Member

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
Copy link
Member

Balinus commented Feb 1, 2020

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
Copy link

I wanted to add two things.

  • If we want to stick to what's already existing, we could make a "UnitfulCF" package mapping all the CF units to Unitful units?
  • I just stumbled on https://github.com/rafaqz/UnitfulMoles.jl and submitted a PR to update it to Julia v1+. What about using this package, or maybe making a climate-units dedicated one? (UnitfulClimate.jl?)

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

@Balinus
Copy link
Member

Balinus commented Feb 3, 2020

I think it's a good idea!

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

No branches or pull requests

4 participants