Unit register
The unit register holds a collection of RegisteredUnit
objects, which are a generalisation of the conventional notion of a measurement unit. Some RegisteredUnit
objects are considered as reference units, the others are called related units. There can be only one reference unit for each kind of quantity, but any number of related units. Each related unit has a multiplier that can be used to convert a measure expressed in the related unit to a measure expressed in the reference unit.
The unit_register
is associated with a Context
to allow the validity of unit expressions to be checked by quantity calculus.
Units are declared by providing the name of the kind of quantity, the name of a scale (unit) and a term symbol (short name for the unit), for example
from QV import *
context = Context(('Length','L'))
SI = UnitRegister("SI",context)
metre = SI.unit( RatioScale(context.Length,'metre','m') ) # reference unit
centimetre = SI.unit( prefix.centi(metre) ) # related unit
- class UnitRegister(name, context)
A UnitRegister holds mappings between a kind-of-quantity, a type of scale and a collection of units.
A distinction is made between a reference unit and other related units for the same kind of quantity. There can be only one reference unit in the register for each kind of quantity.
- conversion_from_A_to_B(A, B)
Return a conversion function for scale A to B
The function takes a single quantity-value argument x on A and returns a quantity-value result on B
- conversion_function_values(A, B, *args)
Register a function to convert from scale A to B
- get(koq, scale_type=<class 'QV.scale.RatioScale'>)
- reference_unit_for(expr)
Return the reference unit for expr
expr can be a product or quotient of registered-units or a product or quotient of kind-of-quantity objects or a registered-unit or a kind-of-quantity object.
- unit(scale)
Register a new scale as a unit
The associated kind of quantity must not already have a scale with the same name or symbol
- unit_dict_for(expr)
Return the units associated with the kind of quantity of expr
expr can be a product or quotient of registered-units, a product or quotient of kind-of-quantity objects, or a registered-unit or a kind-of-quantity object.
- proportional_unit(unit, name, symbol, conversion_factor)
Declare a scale proportional to a unit already registered