Package Scientific :: Package Physics :: Module PhysicalQuantities :: Class PhysicalUnit
[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
 
__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

__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)

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

isCompatible(self, other)

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