COSIMA / cosima-recipes

A cookbook of recipes (i.e., examples) for analysing ocean and sea ice model output
https://cosima-recipes.readthedocs.io
Apache License 2.0
46 stars 66 forks source link

Proper handling of units in examples #267

Open navidcy opened 1 year ago

navidcy commented 1 year ago

Often we see things like:

transport = ty_trans / 1034 / 1e5

to convert, e.g., ty_trans from kg/s to Sverdrup. (E.g. see https://cosima-recipes.readthedocs.io/en/latest/DocumentedExamples/Zonally_Averaged_Global_Meridional_Overturning_Circulation.html) But these conversions are ad hoc and one can easily make a mistake and forget a factor. A usual trick to see if we are missing a factor (e.g., forgot to divide by the depth of the fluid or by density) is to check the units. But if we are converting things like above there are no units attached.

pint and cf-xarray provide a way to attach units on variables.

Our aim is to have all documented examples use pint/cf-xarray for proper unit handling

The tutorial: https://cosima-recipes.readthedocs.io/en/latest/Tutorials/Model_Agnostic_Analysis.html

and the example: https://cosima-recipes.readthedocs.io/en/latest/DocumentedExamples/Transport_Through_Straits.html

are good starting points.

navidcy commented 1 year ago

If during Hackathon v3.0, you wanna tackle updating one of the documented examples to use pint/cf-xarray then:

navidcy commented 8 months ago

316, #322 move towards this direction