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

Class PhysicalUnit



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.

Instance Methods [hide private]
  __cmp__(self, other)
  __div__(self, other)
  __init__(self, names, factor, powers, offset=0)
  __mul__(self, other)
  __pow__(self, other)
  __rdiv__(self, other)
  __repr__(self)
  __rmul__(self, other)
  __str__(self)
float conversionFactorTo(self, other)
Returns the conversion factor from this unit to another unit
(float, float) conversionTupleTo(self, other)
Returns the conversion factor and offset from this unit to another unit
  isAngle(self)
bool isCompatible(self, other)
Returns True if the units are compatible, i.e.
  isDimensionless(self)
  name(self)
  setName(self, name)

Method Details [hide private]

__cmp__(self, other)
(Comparison operator)

 

__div__(self, other)

 

__init__(self, names, factor, powers, offset=0)
(Constructor)

 
Parameters:
  • names (dict or str) - a dictionary mapping each name component to its associated integer power (e.g. {'m': 1, 's': -1}) for m/s). As a shorthand, a string may be passed which is assigned an implicit power 1.
  • factor (float) - a scaling factor
  • powers (list of int) - the integer powers for each of the nine base units
  • offset (float) - an additive offset to the base unit (used only for temperatures)

__mul__(self, other)

 

__pow__(self, other)

 

__rdiv__(self, other)

 

__repr__(self)
(Representation operator)

 

__rmul__(self, other)

 

__str__(self)
(Informal representation operator)

 

conversionFactorTo(self, other)

 
Parameters:
Returns: float
the conversion factor from this unit to another unit
Raises:
  • TypeError - if the units are not compatible

conversionTupleTo(self, other)

 
Parameters:
Returns: (float, float)
the conversion factor and offset from this unit to another unit
Raises:
  • TypeError - if the units are not compatible

isAngle(self)

 

isCompatible(self, other)

 
Parameters:
Returns: bool
True if the units are compatible, i.e. if the powers of the base units are the same

isDimensionless(self)

 

name(self)

 

setName(self, name)