Skip to content

More unit definitions from xclim #284

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

Merged
merged 3 commits into from
Jan 21, 2022
Merged

Conversation

dcherian
Copy link
Contributor

@dcherian dcherian commented Jan 12, 2022

I needed the "degC = celsius" aliases so I copied that and more from xclim.

cc @jthielen

xref #225

@dcherian dcherian requested review from keewis and aulemahal January 12, 2022 22:42
Copy link
Contributor

@keewis keewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me, although it feels a bit strange that the symbol of degrees_north should be degrees_north, I'd have assumed something like °N or ° (same for degrees_east). I can't find anything on that in the CF conventions (not that I looked very hard), so maybe that's intentional? Why this is important is because something like

u = ureg.Unit("degrees_north ** 2")
f"{u:~cf}"

would return "degrees_north2", which is weird (unless I'm missing something?)

Actually, this is not really the fault of this PR: right now it returns "degrees_N2" which is not that much better.

Edit: now that I'm thinking about it, "°N2" or "°2" also look strange, so maybe we don't have much of a choice?

Edit2: I just realized that this is actually a continuation of #284 (comment), I must have missed that.

@dcherian
Copy link
Contributor Author

dcherian commented Jan 18, 2022

I'd have assumed something like °N or ° (same for degrees_east)

I've realized that there are at least 2 distinct use-cases:

  1. units for plotting or reprs where "fancy" stuff like °N would be great (basically emacs' prettify-symbols-mode =) )
  2. .pint.dequantify("u:cf").to_netcdf where you want degrees_north to meet the standard.

* main:
  Add earthcube link (xarray-contrib#292)
  Fix np scaler warning in `_drop_missing_variables()` (xarray-contrib#291)
  explicitly use the short formatter in the docs (xarray-contrib#288)
  Set xincrease/yincrease in more cases. (xarray-contrib#287)
  Use mamba on RTD (xarray-contrib#286)
@dcherian
Copy link
Contributor Author

dcherian commented Jan 21, 2022

The funny exponent syntax is from UDUNITS

I see pint has a "pretty" formatting mode. Is there a way we can define the "pretty" string?

u = units.Unit("degrees_east")
f"{u:~P}"
degrees_east

EDIT: I see even pint doesn't do the pretty ° for "degrees"

u = units.Unit("degrees")
f"{u:P}"
degree

EDIT2: Should we define a Pcf formatter for our own pretty strings?

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

Successfully merging this pull request may close these issues.

3 participants