Skip to main content

Physical units library

Project description

Standard physical units are imported from intec.units.si

from intec.units.si import METER, MILLIMETER, NANOMETER, AMPERE, VOLT, OHM

A Quantity is created by multiplying a number (the magnitude) and a Unit

d = 1550*NANOMETER
print(d)
1550.000000 nm
d
LengthQuantity( 1.5500000000e+03, nm )

Quantities of the same physical dimension can be added or substracted

1*METER + 5*MILLIMETER
LengthQuantity( 1.0050000000e+00, m )

The resulting quantity gets the unit of the first term.

print(5*MILLIMETER + 1*METER)
1005.000000 mm
1*METER + 1*AMPERE
---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

<ipython-input-6-26114287a935> in <module>
----> 1 1*METER + 1*AMPERE


TypeError: Cannot convert unit [A] to unit [m]

Quantities of the same physical dimension can be compared

p = 1*VOLT*2*AMPERE
print(p)
2.000000 V.A
from intec.units.si import WATT, MILLIWATT, DBM
p == 2*WATT
True
3*VOLT/AMPERE > 2*OHM
True

Use the to member function to convert a quantity to a related unit.

print(p.to(MILLIWATT))
print(p.to(DBM))
2000.000000 mW
33.010300 dBm
from intec.units.si import METER, KILOMETER, SECOND
from intec.units.extra import HOUR
speed = 10*METER/SECOND
print(speed.to(KILOMETER/HOUR))
36.000000 km/h

Use the member magnitude or m to retrieve the numerical value of a quantity

speed.magnitude
10.0
speed.m
10.0

Use the member unit or u to retrieve the unit of a quantity

speed.unit
Unit( 'm/s' [m/s] )
speed.u
Unit( 'm/s' [m/s] )

For (wave)lengths there is a convenience function to convert to frequency.

from intec.units.si import NANOMETER,HERTZ
λ = 1550*NANOMETER
λ.to_frequency()
FrequencyQuantity( 1.9341448903e+02, THz )
λ.to_frequency(HERTZ)
FrequencyQuantity( 1.9341448903e+14, Hz )

For photonic experiments, use intec.units.photonic to import all common units in one fell swoop

from intec.units.photonic import *
from .si import METER, MILLIMETER, MICROMETER, NANOMETER, PICOMETER, FEMTOMETER
from .si import WATT, MILLIWATT, MICROWATT, DBM
from .si import VOLT, MILLIVOLT, MICROVOLT
from .si import AMPERE, MILLIAMPERE, MICROAMPERE
from .si import HERTZ, KILOHERTZ, MEGAHERTZ, GIGAHERTZ, TERAHERTZ
from .si import SECOND, MILLISECOND, MICROSECOND
from .si import KELVIN, CELCIUS


          

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for intec-units, version 0.0.5
Filename, size File type Python version Upload date Hashes
Filename, size intec_units-0.0.5-cp34-cp34m-win32.whl (24.8 kB) File type Wheel Python version cp34 Upload date Hashes View hashes
Filename, size intec_units-0.0.5-cp34-cp34m-win_amd64.whl (26.6 kB) File type Wheel Python version cp34 Upload date Hashes View hashes
Filename, size intec_units-0.0.5-cp35-cp35m-win32.whl (24.8 kB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size intec_units-0.0.5-cp35-cp35m-win_amd64.whl (26.6 kB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size intec_units-0.0.5-cp36-cp36m-win32.whl (24.8 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size intec_units-0.0.5-cp36-cp36m-win_amd64.whl (26.6 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size intec_units-0.0.5-cp37-cp37m-win32.whl (24.8 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size intec_units-0.0.5-cp37-cp37m-win_amd64.whl (26.6 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size intec_units-0.0.5-cp38-cp38m-win32.whl (24.7 kB) File type Wheel Python version cp38 Upload date Hashes View hashes
Filename, size intec_units-0.0.5-cp38-cp38m-win_amd64.whl (26.6 kB) File type Wheel Python version cp38 Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page