Unit Conversion

Overview

Unit conversions are facilitated with three functions, register_voxel_unit, convert_value, get_conversion_factor. All of the functionality is build on top of pint with the functions acting as a basic layer of abstraction. Additionally the ‘micron’ unit which is equivalent to a micrometer is automatically defined. Access to the pint UnitRegistry instance is available through the unit_conversion.unit_registry attribute.

register_voxel_unit

register_voxel_unit(length, unit) is used as expected to define the ‘voxel’ unit in the registry because it is not a standard unit of measurement. Once registered conversions can be applied as usual. The unit describing the length must be a standard unit of measurement such as millimeters, inches, microns, etc.

convert_value

convert_value(value, unit_in, unit_out='SI') converts a value in the current unit to the unit specified by unit_out. If unit_out is not provided then the value is converted to the proper SI units.

get_conversion_factor

get_conversion_factor(unit_in, unit_out='SI') returns a conversion factor from the current unit to the unit specified by unit_out. If unit_out is not provided then a conversion factor to the SI unit is returned.