-
Notifications
You must be signed in to change notification settings - Fork 59
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
Clean and export the units registry #2040
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but some clarifications would be nice to have!
The non-standard units are stuff that we've seen in the wild. I suspect that removing them here will force us to make explicit unit changes in RavenPy and maybe xhydro. I'm not sure I see why we'd remove them if it doesn't cause us pain. I think our stance is "we'll make sure CF-compliant files work", not "non CF-compliant files will fail". |
I can put them back. |
Ahh, I see now. @Zeitsperre expect some breakage in notebooks and tests from ravenpy and pavics-sdi. |
I'm prepared for that if it means that things are improving overall. PAVICS pins xclim, so no current images should be impacted. |
Sorry, I skipped this conversation.
These are not anywhere in xHydro, so personally, I don't mind removing support for them. |
Co-authored-by: Trevor James Smith <[email protected]>
Pull Request Checklist:
number
) and pull request (:pull:number
) has been addedWhat kind of change does this PR introduce?
Remove support for non-CF aliases : "cms" (m3 s-1), "mmday" (mm d-1) and "pct" (%). These are not supported by
udunits2
and thus I don't see why we should support them ? @huard, @RondeauG what do you think ? I'm not strongly opinionated on this.Set the unit registry as pint's "application registry" to make it usable by non-xclim aware applications. To be obtained with
ureg = pint.get_application_registry()
.Units of quantities printed in indicator attributes are now formatted using the CF syntax (ex: "mm d-1" instead of "mm/d"). Not sure how I missed that earlier...
Clean up in the code of the registry declaration and addition of comments to explain what is happening.
A small change in
dataflags
that was actually unneeded at the end, but it felt cleaner to me, so I kept it.Does this PR introduce a breaking change?
Some units are not supported anymore (
cms
,pct
andmmday
).Some attributes will be different as the units are printed differently (for fractions mostly).
Other information:
The registry export allows an application/module that is units-agnostic in itself to be used with xclim. For those applications / usages, the import order might be significant though :
xclim
has to be the lastset_application_registry
done. Specifically in the climate case, asxclim.core.units
importscf_xarray.units
(which also sets the app registry), a subsequentimport cf_xarray.units
is not problematic as python will not actually execute it.@coxipi Incoming PR to
xsdba
to use exactly that.