Clean and export the units registry #2040
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.