I have a pint registry that already defines many climate specific units, but I struggle to add a new one for cloud coverage.
I would like to add "okta"[0] as a new unit.
- Oktas are an integer scale from 0 to 9.
- A conversion from percent to oktas is possible with the formula
oktas = round(percent_value * 8 / 100)
[1]
I added okta as a new unit in pint with:
my_registry.define(
pint.unit.UnitDefinition("okta", "okta", ("octa", "octas",), pint.converters.ScaleConverter(0.01)
))
But my question is how do I add an auto-conversion from percent
to oktas
and vice-versa ?
I tried
units.define("okta = percent * 8 / 100")
; it works when using theunits.Quantity(10, "okta").to("percent")
, but the result is (obviously) not rounded.units.define("okta = round(percent * 8 / 100)")
; it throws an "UndefinedUnitError: 'round' is not defined in the unit registry" when callingunits.Quantity(10, "okta").to("percent")
.
I also tried to create a "cloudiness" Context and add an add_transformation
to it, but without success.
References:
- [0] https://en.wikipedia.org/wiki/Okta
- [1] at Chapter 2.1.2, on variable "CC" https://knmi-ecad-assets-prd.s3.amazonaws.com/documents/atbd.pdf