Why units are important -- how to avoid mistakes using `pint`/`cf-xarray`

If you use pint /cf-xarray you avoid these sort of situations.

Some examples in the COSIMA recipes demonstrate the use of pint/cf-xarray. See:

2 Likes

Your transport example is very nice @navidcy. Very clean. The pint stuff is so easy that it almost disappears. I had to search to find where it was being used.

1 Like

Thanks.

But, it’s not my example. It belongs to the COSIMA community.

1 Like

Often in the COSIMA examples we see things like

variable / (1036 * 1e6) # convert to volume and sverdrups

or other seemingly ad-hoc conversions like that. We should strive to convert either via .pint.to('new unit') or by dividing with another variable that has units attached to it.

1 Like