This package is based on the PhysicalQuantity package that is part of ScientificPython. It performs unit conversions.
This module provides a data type that represents a physical quantity together with its unit. It is possible to add and subtract these quantities if the units are compatible and a quantity can be converted to another compatible unit. Multiplication, subtraction, and raising to integer powers are allowed without restriction, and the result will have the correct unit. A quantity can be raised to a non-integer power only if the result can be represented by integer powers of the base units.
The module provides a basic set of predefined physical quanitites in its built-in library; however, it also supports generation of personal libararies which can be saved and reused.
Bases: dict
Dictionary storing numerical values
Constructor: NumberDict()
An instance of this class acts like an array of numbers with generalized (non-integer) indices. A value of zero is assumed for undefined entries. NumberDict instances support addition and subtraction with other NumberDict instances, and multiplication and division by scalars.
Bases: object
Physical quantity with units
PhysicalQuantity instances allow addition, subtraction, multiplication, and division with each other as well as multiplication, division, and exponentiation with numbers. Addition and subtraction check that the units of the two operands are compatible and return the result in the units of the first operand.
Change the unit and adjust the value such that the combination is equivalent to the original one. The new unit must be compatible with the previous unit of the object.
@param unit: a unit @type unit: C{str} @raise TypeError: if the unit string is not a know unit or a unit incompatible with the current one
@returns: the same quantity converted to base units, i.e. SI units in most cases @rtype: L{PhysicalQuantity}
Express the quantity in different units. If one unit is specified, a new PhysicalQuantity object is returned that expresses the quantity in that unit. If several units are specified, the return value is a tuple of PhysicalObject instances with with one element per unit such that the sum of all quantities in the tuple equals the the original quantity and all the values except for the last one are integers. This is used to convert to irregular unit systems like hour/minute/second.
@param units: one or several units @type units: C{str} or sequence of C{str} @returns: one or more physical quantities @rtype: L{PhysicalQuantity} or C{tuple} of L{PhysicalQuantity} @raises TypeError: if any of the specified units are not compatible with the original unit
Bases: object
Physical unit
A physical unit is defined by a name (possibly composite), a scaling factor, and the exponentials of each of the SI base units that enter into it. Units can be multiplied, divided, and raised to integer powers.
@param other: another unit @type other: L{PhysicalUnit} @returns: the conversion factor from this unit to another unit @rtype: C{float} @raises TypeError: if the units are not compatible
@param other: another unit @type other: L{PhysicalUnit} @returns: the conversion factor and offset from this unit to another unit @rtype: (C{float}, C{float}) @raises TypeError: if the units are not compatible
Adding Offset Unit.