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
Parse CF/UDUNITS-style powers of units #1134
Comments
My preference would be to see if pint is interested in the modification, but otherwise we'll need to support it. |
Now that hgrecco/pint#911 has been merged, this (and percent signs) can be supported by specifying something like the following: units = pint.UnitRegistry(autoconvert_offset_to_baseunit=True,
preprocessors=[functools.partial(
re.sub, (r'(?<=[A-Za-z])(?![A-Za-z])'
r'(?<![0-9\-][eE])(?<![0-9\-])(?=[0-9\-])'),
'**'),
lambda string: string.replace('%', 'percent')]) I'd guess that I should wait for a PR until the next pint release? |
I mean, the PR is welcome, but it won’t pass or get merged until there’s a pint release. Which as fast as I’m getting 0.12 out the door, may actually beat the next MetPy release... 🤣 😭 |
For the record, MetPy 0.12 was out first, but about 3 hours. |
I'm not sure if this is something to implement in MetPy or upstream in pint, but as I was working through some of the dataset helper functionality along with xarray and pint integration, I realized that some CF/UDUNITS-compliant units are not handled by pint, specifically powers of units in the default symbol notation. For example, the CF standard name table lists the canonical units for "geopotential" as "m2 s-2", which pint cannot parse.
I would think a fix could be as simple as parsing the unit string to recognize patterns like
<unit><number>
and inserting "**" (which is valid in both pint and UDUNITS) in between. I think the following regex should do the trick?The text was updated successfully, but these errors were encountered: