Unit¶
PhysicalUnit class definition
Original author: Georg Brandl <georg@python.org>, https://bitbucket.org/birkenfeld/ipython-physics
- PhysicalQuantities.unit.add_composite_unit(name, factor, units, offset=0, verbosename='', prefixed=False, url='')[source]¶
Add new unit to the unit_table
Parameters¶
- name: str
Name of the unit
- factor: float
scaling factor
- units: str
Composed units of new unit
- offset: float
Offset factor
- verbosename: str
A more verbose name for the unit
- prefixed: bool
This is a prefixed unit
- url: str
A URL linking to more information about the unit
Returns¶
- str
Name of new unit
Raises¶
- KeyError
If unit already exists or if units string is invalid
- ValueError
If factor or offset is not numeric
- PhysicalQuantities.unit.addunit(unit)[source]¶
Add new PhysicalUnit entry to the unit_table
Parameters¶
- unit: Physicalunit
PhysicalUnit object
Raises¶
- KeyError
If unit already exists
- PhysicalQuantities.unit.convertvalue(value, src_unit, target_unit)[source]¶
Convert between units, if possible
Parameters¶
- value:
Value in source units
- src_unit: PhysicalUnit
Source unit
- target_unit: PhysicalUnit
Target unit
Returns¶
- any
Value scaled to target unit
Examples¶
>>> from PhysicalQuantities import q >>> convertvalue(1, q.mm.unit, q.km.unit) 1e-06