Unit Converter#
Unit Converter is a static helper that converts a given value from and to internal units.
All values in Kappa-Automate are stored in the internal unit of their measure: mostly SI units, with a few
exceptions – an elapsed time is in hours, not seconds. The internal unit of each measure, and the units it can
be converted to, are listed in the Measures and Units references.
You cannot instantiate this class directly, but you can access it in two ways:
When writing a Python script with an established connection:
unit_converter = connection.unit_converter
When working in a user task environment, use the services variable:
unit_converter = services.unit_converter
Examples#
Before writing back some data to Kappa-Automate, use the kappa_sdk.UnitConverter.convert_to_internal() method to convert your data to SI units:
value_in_si_unit = unit_converter.convert_to_internal(ka.UnitEnum.pressure_psia, value)
Conversely, when reading data from Kappa-Automate, you may want to convert it to a specific unit using the kappa_sdk.UnitConverter.convert_from_internal() method:
value_in_specific_unit = unit_converter.convert_from_internal(ka.UnitEnum.pressure_psia, value)
Note
Most of the time, when you are writing or reading data, there is a unit parameter that lets you specify a kappa_sdk.UnitEnum object and performs the conversion for you.
Note
A kappa_sdk.UnitEnum value is only valid for the measure it belongs to: converting a
pressure with a length unit silently gives a meaningless result. The Units Reference lists the
units accepted by each measure, together with the a and b coefficients this class applies.