PhysicalQuantites - Calculation in Python with Units
PhysicalQuantities is a module for Python 3.6 that allows calculations to be aware of physical units with a focus on engineering applications. Built-in unit conversion ensures that calculations will result in the correct aggregate unit.
The module also contains an extension for IPython. This allows greatly simplified use by typing in physical quantities directly as number and unit.
In : %load_ext PhysicalQuantities.ipython In : a = 100mm In : a Out: 100 mm In : a.cm Out: 10.0 cm In : a = 10_000_000 nm In : a.autoscale Out: 1.0 cm In : a = 10 m/s In : 5s * a Out: 50 m
dB calculations are supported, too:
In : u = 10V In : u.dB Out: 20.0 dBV In : p = 10 dBm In : p Out: 10 dBm In : p.W Out: 0.01 W In : p.mW Out: 10.0 mW
Additional units, e.g. imperial units:
In : %precision 2 Out: '%.2f' In : import PhysicalQuantities.imperial In : a = 2 inch In : a Out: 2 inch In : a.mil Out: 2000.00 mil In : a.mm Out: 50.80 mm
Using PhysicalQuantities in plain Python:
>>> from PhysicalQuantities import q >>> 1 * q.mm 1 mm >>> 1 * q.dBm 1 dBm >>>
This module requires Python 3.6 or above. This is due to the use of new features like f strings or supporting underscores in numeric literals.
To install, simply do a
pip install PhysicalQuantities
There also is a conda receive, so you can do
to generate a conda package. I will upload a receipe to conda-forge at a later time.
This module is originally based on the IPython extension by Georg Brandl at https://bitbucket.org/birkenfeld/ipython-physics.