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

Module PhysicalQuantities



Physical quantities with units.

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 is 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 values of physical constants are taken from the 1986 recommended values from CODATA. Other conversion factors (e.g. for British units) come from various sources. I can't guarantee for the correctness of all entries in the unit table, so use this at your own risk.

Classes [hide private]
  PhysicalQuantity
Physical quantity with units
  PhysicalUnit
Physical unit

Functions [hide private]
  _addPrefixed(unit)
  _addUnit(name, unit)
  _convertValue(value, src_unit, target_unit)
  _findUnit(unit)
  _round(x)
bool isPhysicalQuantity(x)
Returns True if x is a PhysicalQuantity
bool isPhysicalUnit(x)
Returns True if x is a PhysicalUnit

Variables [hide private]
  _base_names = ['m', 'kg', 's', 'A', 'K', 'mol', 'cd', 'rad', 'sr']
  _base_units = [('m', <PhysicalUnit m>), ('g', <PhysicalUnit g>), (...
  _prefixes = [('Y', 9.9999999999999998e+23), ('Z', 1e+21), ('E', ...
  _unit_table = {'alm': <PhysicalUnit alm>, 'aohm': <PhysicalUnit ao...

Function Details [hide private]

_addPrefixed(unit)

 

_addUnit(name, unit)

 

_convertValue(value, src_unit, target_unit)

 

_findUnit(unit)

 

_round(x)

 

isPhysicalQuantity(x)

 
Parameters:
  • x (any) - an object
Returns: bool
True if x is a PhysicalQuantity

isPhysicalUnit(x)

 
Parameters:
  • x (any) - an object
Returns: bool
True if x is a PhysicalUnit

Variables Details [hide private]

_base_names

Value:
['m', 'kg', 's', 'A', 'K', 'mol', 'cd', 'rad', 'sr']                   
      

_base_units

Value:
[('m', <PhysicalUnit m>),
 ('g', <PhysicalUnit g>),
 ('s', <PhysicalUnit s>),
 ('A', <PhysicalUnit A>),
 ('K', <PhysicalUnit K>),
 ('mol', <PhysicalUnit mol>),
 ('cd', <PhysicalUnit cd>),
 ('rad', <PhysicalUnit rad>),
...                                                                    
      

_prefixes

Value:
[('Y', 9.9999999999999998e+23),
 ('Z', 1e+21),
 ('E', 1e+18),
 ('P', 1000000000000000.0),
 ('T', 1000000000000.0),
 ('G', 1000000000.0),
 ('M', 1000000.0),
 ('k', 1000.0),
...                                                                    
      

_unit_table

Value:
{'Pcd': <PhysicalUnit Pcd>,
 'Tsr': <PhysicalUnit Tsr>,
 'alm': <PhysicalUnit alm>,
 'alx': <PhysicalUnit alx>,
 'aohm': <PhysicalUnit aohm>,
 'cBq': <PhysicalUnit cBq>,
 'fHz': <PhysicalUnit fHz>,
 'ym': <PhysicalUnit ym>,
...