Skip to content

Latest commit

 

History

History
104 lines (66 loc) · 6.11 KB

pq-ipython.rst

File metadata and controls

104 lines (66 loc) · 6.11 KB

Using PhysicalQuantities in IPython

The IPython extension makes using physical quantities easier. To load the extension use:

>>> %load_ext PhysicalQuantities.ipython

Now entering a physical quantities gets very easy:

>>> d = 2.3 s**3
>>> print("d = %s" %d)
d = 2.3 s^3
>>> t = 3 A
>>> print("t = %s" %t)
t = 3 A
>>> v = 2.3e3 * d / t
>>> print("v = %s" %v)
v = 1763.3333333333333 s^3/A

Unit conversion

The easiest way to scale a unit is to use prefix attributes:

>>> u = 1 V
>>> print(u)
1 V
>>> print(u.mV)
1000.0 mV
>>> print(u.uV)
1000000.0 uV

To convert between different representations of a unit, to() can be used:

>>> a = 1 N * 1 m
>>> print(a)
1 m*N
>>> print(a.to('J'))
1.0 J

Using other value types

The PhysicalQuantity class tries to be a wrapper around the value of a given quantity, i.e. not only single numbers can be used. For examples using Numpy arrays, take a look at the Using Numpy Arrays notebook.

>>> u = (1 + 1j) * 1V
>>> print("u = %s" %u)
u = (1+1j) V
>>> u = [1,2,3] * 1V
>>> print("u = %s" %u)
u = [1, 2, 3] V
>>> a = [1, 2, 3] * 1V
>>> a

$[1, 2, 3] $\text{V}$

>>> a.value
[1, 2, 3]
>>> 2*a

[1, 2, 3, 1, 2, 3]V

List of all defined Units:

All predefined units can be listed using the list() or html_list() function of a unit:

>>> from PhysicalQuantities import units_html_list
>>> units_html_list()
Name Base Unit Quantity
Wb 1.0 $\frac{\text{m}^{2}\cdot \text{kg}}{\text{A}\cdot \text{s}^2}$ Weber
s 1.0 $\text{s}$ Second
h 3600.0 $\text{s}$ Hour
lx 1.0 $\frac{\text{cd}\cdot \text{sr}}{\text{m}^2}$ Lux
sr 1.0 $\text{sr}$ Streradian
min 60.0 $\text{s}$ Minute
J 1.0 $\frac{\text{m}^{2}\cdot \text{kg}}{\text{s}^2}$ Joule
Pa 1.0 $\frac{\text{kg}}{\text{m}\cdot \text{s}^2}$ Pascal
arcsec 4.84813681109536e-06 $\text{rad}$ seconds of arc
cd 1.0 $\text{cd}$ Candela
lm 1.0 $\text{cd}\cdot \text{sr}$ Lumen
H 1.0 $\frac{\text{m}^{2}\cdot \text{kg}}{\text{A}^2\cdot \text{s}^2}$ Henry
m 1.0 $\text{m}$ Metre
T 1.0 $\frac{\text{kg}}{\text{A}\cdot \text{s}^2}$ Tesla
S 1.0 $\frac{\text{A}^{2}\cdot \text{s}^{3}}{\text{m}^2\cdot \text{kg}}$ Siemens
C 1.0 $\text{A}\cdot \text{s}$ Coulomb
deg 0.017453292519943295 $\text{rad}$ Degree
K 1.0 $\text{K}$ Kelvin
g 0.001 $\text{kg}$ Gram
kg 1 $\text{kg}$ Kilogram
F 1.0 $\frac{\text{A}^{2}\cdot \text{s}^{4}}{\text{m}^2\cdot \text{kg}}$ Farad
W 1.0 $\frac{\text{m}^{2}\cdot \text{kg}}{\text{s}^3}$ Watt
arcmin 0.0002908882086657216 $\text{rad}$ minutes of arc
Hz 1.0 $\frac{1}{\text{s}}$ Hertz
A 1.0 $\text{A}$ Ampere
Ohm 1.0 $\frac{\text{m}^{2}\cdot \text{kg}}{\text{A}^2\cdot \text{s}^3}$ Ohm
N 1.0 $\frac{\text{m}\cdot \text{kg}}{\text{s}^2}$ Newton
V 1.0 $\frac{\text{m}^{2}\cdot \text{kg}}{\text{A}\cdot \text{s}^3}$ Volt
rad 1.0 $\text{rad}$ Radian
mol 1.0 $\text{mol}$ Mol