Quantity value

The term ‘quantity value’ refers to a measured value paired with the unit of measurement. QV provides several functions in the quantity_value module that support the notion of quantity values:

  • qvalue() creates a quantity-value,

  • qratio() creates a quantity-value that is a dimensionless ratio,

  • qresult() resolves the unit for an expression involving quantity-values.

More information is given in the Examples section.

qratio(value_unit_1, value_unit_2, unit=None)

Return a quantity value for value_unit_1/value_unit_2. If the signature of the associated units are in simplified form, signature information is retained in the quotient.

When unit is None, the reference unit is used.

Example

>>> context = Context( ("Current","I"),("Voltage","V") )
>>> ureg = UnitRegister("ureg",context)
>>> volt = ureg.unit( RatioScale(context['Voltage'],'volt','V') )
>>> voltage_ratio = context.declare('voltage_ratio','V/V','Voltage//Voltage')
>>> volt_per_volt = ureg.unit( RatioScale(context['voltage_ratio'],'volt_per_volt','V/V') )
>>> v1 = qvalue(1.23, volt)
>>> v2 = qvalue(9.51, volt)
>>> qratio( v2,v1 )
qvalue(7.73170731...,volt_per_volt)
qresult(value_unit, unit=None, simplify=True, value_result=<function <lambda>>, *arg, **kwarg)

Return a qvalue.

value_unit is a quantity-value or expression of quantity-values.

If a unit is supplied, it is used to report the measure. If not, the measure is reported in the reference unit for that quantity.

If simplify is True, unit signatures will be simplified.

The function value_result is applied to the value as a final processing step.

Example

>>> context = Context( ("Length","L"), ("Time","T") )
>>> Speed = context.declare('Speed','V','Length/Time')
>>> si =  UnitRegister("si",context)
>>> metre = si.unit( RatioScale(context['Length'],'metre','m') )
>>> second = si.unit( RatioScale(context['Time'],'second','s') )
>>> metre_per_second = si.unit( RatioScale(context['Speed'],'metre_per_second','m*s-1') )
>>> d = qvalue(0.5,metre)
>>> t = qvalue(1.0,second)
>>> v0 = qresult(d/t)
>>> print( "average speed =", v0 )
average speed = 0.5 m*s-1
>>> x0 = qvalue(.3,metre)
>>> print( "displacement =", x0 + v0*t )
displacement = 0.8 m
qvalue(value, unit)

Create a new quantity value object.

value is the measure, unit is the measurement scale

Example

>>> context = Context( ("Length","L"), ("Time","T") )
>>> si = UnitRegister("si",context)
>>> metre = si.unit( RatioScale(context['Length'],'metre','m') )
>>> qvalue( 1.84, metre )
qvalue(1.84,metre)
unit(quantity_value)

Return the unit (measurement scale)

value(quantity_value)

Return the value