Package Scientific :: Package Physics :: Module PhysicalQuantities :: Class PhysicalQuantity
[hide private]
[frames] | no frames]

Class PhysicalQuantity



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. A limited set of mathematical functions (from module Numeric) is applicable as well:

Instance Methods [hide private]
  __abs__(self)
  __add__(self, other)
  __cmp__(self, other)
  __div__(self, other)
  __init__(self, *args)
There are two constructor calling patterns:
  __mul__(self, other)
  __neg__(self)
  __nonzero__(self)
  __pos__(self)
  __pow__(self, other)
  __radd__(self, other)
  __rdiv__(self, other)
  __repr__(self)
  __rmul__(self, other)
  __rpow__(self, other)
  __rsub__(self, other)
  __str__(self)
  __sub__(self, other)
  _sum(self, other, sign1, sign2)
  convertToUnit(self, unit)
Change the unit and adjust the value such that the combination is equivalent to the original one.
  cos(self)
PhysicalQuantity inBaseUnits(self)
Returns the same quantity converted to base units, i.e.
PhysicalQuantity or tuple of PhysicalQuantity inUnitsOf(self, *units)
Express the quantity in different units.
bool isCompatible(self, unit)
Returns True if the specified unit is compatible with the one of the quantity
  sin(self)
  sqrt(self)
  tan(self)

Class Variables [hide private]
  _number = <_sre.SRE_Pattern object at 0x572aa0>

Method Details [hide private]

__abs__(self)

 

__add__(self, other)
(Addition operator)

 

__cmp__(self, other)
(Comparison operator)

 

__div__(self, other)

 

__init__(self, *args)
(Constructor)

 

There are two constructor calling patterns:
  • PhysicalQuantity(value, unit), where value is any number and unit is a string defining the unit
  • PhysicalQuantity(value_with_unit), where value_with_unit is a string that contains both the value and the unit, i.e. '1.5 m/s'. This form is provided for more convenient interactive use.
  • Parameters:
    • args ((number, str) or (str,)) - either (value, unit) or (value_with_unit,)

    __mul__(self, other)

     

    __neg__(self)

     

    __nonzero__(self)
    (Boolean test operator)

     

    __pos__(self)

     

    __pow__(self, other)

     

    __radd__(self, other)
    (Right-side addition operator)

     

    __rdiv__(self, other)

     

    __repr__(self)
    (Representation operator)

     

    __rmul__(self, other)

     

    __rpow__(self, other)

     

    __rsub__(self, other)

     

    __str__(self)
    (Informal representation operator)

     

    __sub__(self, other)
    (Subtraction operator)

     

    _sum(self, other, sign1, sign2)

     

    convertToUnit(self, unit)

     

    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.
    Parameters:
    • unit (str) - a unit
    Raises:
    • TypeError - if the unit string is not a know unit or a unit incompatible with the current one

    cos(self)

     

    inBaseUnits(self)

     
    Returns: PhysicalQuantity
    the same quantity converted to base units, i.e. SI units in most cases

    inUnitsOf(self, *units)

     

    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.
    Parameters:
    • units (str or sequence of str) - one or several units
    Returns: PhysicalQuantity or tuple of PhysicalQuantity
    one or more physical quantities
    Raises:
    • TypeError - if any of the specified units are not compatible with the original unit

    isCompatible(self, unit)

     
    Parameters:
    • unit (str) - a unit
    Returns: bool
    True if the specified unit is compatible with the one of the quantity

    sin(self)

     

    sqrt(self)

     

    tan(self)

     

    Class Variable Details [hide private]

    _number

    Value:
    [\+-]?[0-9]+(\.[0-9]*)?([eE][\+-]?[0-9]+)?