temperatures — functions
The SDK's temperature unit, and converting one number yourself.
One switch for the whole SDK. set_temperature_unit chooses
the unit of the whole SDK for this process. Celsius is the default, so
a program that never calls it sees nothing change. With
TEMPERATURE_UNIT_FAHRENHEIT, every temperature the SDK takes or
returns is in degrees Fahrenheit and every temperature difference in
Fahrenheit degrees: frames, region statistics, alarm limits and events,
the colour range, camera settings, process-interface channels, values
read back from a recording or a snapshot. A name that says _c or
celsius (Frame.min_c, RegionStats.mean_c,
Frame.to_numpy(celsius=True)) follows the unit as well; the name is
older than the switch.
The SDK keeps storing and computing in Celsius and converts where a
value crosses the API, so a setting made in one unit keeps its meaning
after a switch and reads back in the new unit, and every file the SDK
writes stays Celsius, byte for byte the same in either unit. A CSV
snapshot keeps its own unit (optris_sdk.CsvOptions,
temperature_unit). optris_sdk.internal_to_celsius decodes
the raw samples, which are Celsius by definition. Set the unit once, at
start, before opening a camera::
import optris_sdk
optris_sdk.set_temperature_unit(optris_sdk.TEMPERATURE_UNIT_FAHRENHEIT)
The functions below convert one number for a program that does it itself.
A temperature and a difference convert differently
A temperature is a point on the scale: F = C x 9/5 + 32. A difference is a distance on it: F = K x 9/5, with no offset. An alarm's hysteresis, the limits of a rule with a reference (which are offsets), a standard deviation and a colour-scale span are differences. Converting 2 K like a temperature shows 35.6 F; the right answer is 3.6 F. So there are two pairs of functions, and the name says which one a number needs.
Converting never rounds; text is rounded once
The four conversions are plain arithmetic, so a value typed in one unit
survives the trip into Celsius and back: 70.1 F is stored as
21.1666... C and shown as 70.1 F again. format and
format_difference convert first and then round once, in the
unit shown, half away from zero: 21.25 becomes '21.3' and -21.25
becomes '-21.3' at one decimal. "Half" is judged on the decimal the
float stands for, the shortest decimal that reads back as the same
float, which is what repr() shows: 2.675 rounds to '2.68' at
two decimals although no float holds 2.675 exactly. (Python's own
round() and '%.2f' give 2.67 there, and round 0.125 to even.)
A result that rounds to zero has no sign.
Every function runs the SDK's own code, so Python, C, C++, C# and Rust show the same last digit for the same reading::
import optris_sdk
from optris_sdk import temperatures
unit = optris_sdk.TEMPERATURE_UNIT_FAHRENHEIT
# A reading: '70.3 °F'.
shown = temperatures.format(21.3, unit, 1) + ' ' + \
temperatures.symbol(unit)
# A hysteresis of 2 K: '3.6', not '35.6'.
band = temperatures.format_difference(2.0, unit, 1)
# What the user typed, stored in Celsius without rounding.
limit_c = temperatures.to_celsius(70.1, unit)
set_temperature_unit(unit)
Choose the temperature unit of the whole SDK, for this process.
Every temperature and temperature difference that crosses the API
afterwards is in unit (see the top of this module). Call it
once, at start, before opening a camera.
- Raises
InvalidArgumentError— ifunitis not one of the twoTEMPERATURE_UNIT_*values; the unit then stays what it was.
get_temperature_unit()
The SDK's temperature unit: what set_temperature_unit
last chose, TEMPERATURE_UNIT_CELSIUS until then.
from_celsius(celsius, unit)
A temperature (a point on the scale) from degrees Celsius into
unit. Does not round.
- Raises
InvalidArgumentError— ifunitis not one of the twoTEMPERATURE_UNIT_*values.
to_celsius(value, unit)
A temperature in unit back into degrees Celsius, for storing
what a person typed. Does not round.
- Raises
InvalidArgumentError— ifunitis not one of the two units.
from_kelvin_difference(kelvin, unit)
A temperature difference (a distance on the scale) from kelvin
into degrees of unit: K x 9/5 for Fahrenheit, with no offset.
Does not round.
- Raises
InvalidArgumentError— ifunitis not one of the two units.
to_kelvin_difference(value, unit)
A temperature difference in degrees of unit back into
kelvin. Does not round.
- Raises
InvalidArgumentError— ifunitis not one of the two units.
symbol(unit)
The unit's symbol: the degree sign (U+00B0) followed by C or
F.
- Raises
InvalidArgumentError— ifunitis not one of the two units.
format(celsius, unit, decimals, decimal_separator = '.')
A Celsius temperature as text in unit, without the symbol:
converted, then rounded once, half away from zero, to decimals
decimals.
- Parameter
celsius— the temperature, in degrees Celsius. - Parameter
unit—TEMPERATURE_UNIT_CELSIUSorTEMPERATURE_UNIT_FAHRENHEIT. - Parameter
decimals— how many decimals, 0 to 15. - Parameter
decimal_separator—'.'(the default) or','. There is never a group separator, and the process locale never reaches the text. - Returns — the text, or
''for NaN and the infinities, so the application decides how it shows a missing value. - Raises
InvalidArgumentError— for an unknown unit,decimalsoutside 0 to 15, or another separator.
format_difference(kelvin, unit, decimals, decimal_separator = '.')
A temperature difference in kelvin as text in degrees of
unit: converted with no offset, then rounded exactly as
format rounds. 2 K in Fahrenheit is '3.6', not
'35.6'.
Same parameters, result and errors as format.