0

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

  1. units.define("okta = percent * 8 / 100") ; it works when using the units.Quantity(10, "okta").to("percent"), but the result is (obviously) not rounded.

  2. units.define("okta = round(percent * 8 / 100)") ; it throws an "UndefinedUnitError: 'round' is not defined in the unit registry" when calling units.Quantity(10, "okta").to("percent").

I also tried to create a "cloudiness" Context and add an add_transformation to it, but without success.


References:

Abel
  • 688
  • 6
  • 19

0 Answers0