-
Notifications
You must be signed in to change notification settings - Fork 468
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
Possibility of support for CF/UDUNITS-style powers of units #851
Comments
I would answer in different converging directions:
|
Thank you for bringing up the point about ambiguity, and after thinking about it more, I'm not sure if there is a way to avoid it given pint's existing behavior and UDUNITS behavior. While this is a contrived example, I think it demonstrates the ambiguity well: In pint: import pint
ureg = pint.UnitRegistry()
test_str = '1e6 Hz s-2'
print(ureg(test_str))
In cf_units (a python wrapper for UDUNITS): from cf_units import Unit
test_str = '1e6 Hz s-2'
print(Unit(test_str).definition)
Also, because of the expressions that CF/UDUNITS allows, it would likely require using With all that in mind, I think the best way forward will be building on the early discussions for an API to extend replacements and/or the pre-processor itself (#429 (comment))? I will try putting together an initial PR sometime soon. |
The CF Conventions are a common standard used in the atmospheric and oceanic sciences, and many NetCDF files follow these conventions. The unit conventions rely upon the UDUNITS package. While most CF/UDUNITS-compliant unit strings can be parsed properly by pint, I've run into some issues recently with powers of units in the default symbol notation, i.e., strings such as "m2 s-2" for meters squared per second squared.
Would support for powers of units in this style be welcome in pint?
If so, this should be fairly simple to implement by adding the following regex substitution pair
to
pint/pint/util.py
Lines 565 to 575 in 2afdc4b
If not, would it be possible to add something to the registry API in order to add regex substitution pairs for the string preprocessor? Even if pint itself doesn't wish to support this style of powers of units (which would be reasonable...this isn't the clearest syntax), having some officially supported way to add new regex substitutions would make it much easier for downstream libraries like MetPy to implement it if desired for CF/UDUNITS-compatibility.
Either way, I'd be glad to put in a PR to implement the desired functionality.
xref Unidata/MetPy#1134
The text was updated successfully, but these errors were encountered: