-
Notifications
You must be signed in to change notification settings - Fork 41
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
updates to unit support #225
Comments
I've run across this discussion and work now and am interested in using it! Is the pint unit stuff sort of separate from the other cf-xarray stuff? I am looking to interpret units in xarray Datasets but with units including psu and for example m s-1. |
indeed, the only thing it does for now is provide a special The documentation for this feature of |
Thanks @keewis! I haven't actually used |
if you're willing to take the time I'd also be interested in feedback on what you found difficult to understand: we didn't check the documentation of |
I've gotten a little bit into this and get something to work, so that has been exciting. I've immediately hit another unit problem though: salinity units as 1e-3. Is this one that can be added into the registry here? |
I don't know a lot about the units used in oceanography (for example, what is the difference between those and the In general, if you can provide a unit name and the dimensionality / scale I think that should be possible. |
Here is just a basic example I was able to cobble together from the import pint
# order apparently matters
from cf_xarray.units import units
import pint_xarray
ds = xr.open_dataset([your dataset])
ds = ds.pint.quantify() # to interpret units
# units like m s-1 will be interpretable by pint with the cf_xarray unit registry
ds['temp'] = ds['temp'].pint.to('degree_Celsius') # convert units
ds = ds.pint.dequantify() # to go back to normal use |
a tip: ds['temp'] = ds['temp'].pint.to('degree_Celsius') can also be written as ds = ds.pint.to({"temp": "degree_Celsius"}) and while right now most operations are supported, some of the most important ones (e.g. |
At first I was skeptical but it looks like this is widespread (Unidata/UDUNITS-2#27). So i think it's OK to have There are a few other aliases in this comment: PCMDI/pcmdi_metrics#162 (comment) @keewis if you want to waste some time on the history of salinity measurements see http://www.coastalwiki.org/wiki/Salinity I like the rant by frank Millero which ends with
|
Ok so should I change the line https://github.com/xarray-contrib/cf-xarray/blob/main/cf_xarray/units.py#L44 to be the following (not sure if I need the change in capitalization for "E")
|
If anyone has some time, I would like to move this forward but I am stuck on knowing where to start. I tried my suggestion above and that didn't work. |
May be easier if you open a PR and posted the error message. I assume you've looked at https://pint.readthedocs.io/en/stable/defining.html? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Folks. The amazing Phil Elson started https://github.com/pelson/pyudunits2 recently to cover all CF units by implementing udunits2 in pure Python. I'm not 100% if it is a best alternative to those already using pint. I'd love if you all could comment on https://github.com/pelson/pyudunits2/issues if you believe that pyudunits2 can be a unifying units library for those aiming at support CF units and if you believe that it can replace the many pint-cf-like units we have out there (xclim, metpy, cf-xarray, and my prototype in compliance-checker.) |
Current todo list remaining:
Instructing users to either import cf-xarray before pint-xarray or setnot necessary withpint>=0.18
Originally posted by @jthielen in #197 (comment)
The text was updated successfully, but these errors were encountered: