Skip to content

gabbpuy/PyQuantity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyQuantity

A library to deal with quantities, that have units. Quantities reduce themselves to the lowest SI prefix, see Units.RealWorld to configure prefixes that aren't normally used.

Usage

from quantity.quantity import Quantity
import quantity.unit.units as units 

length = Quantity(5, units.metre)
width = Quantity(4,  units.metre)
area = length * width
print(area)
'20.0 m²'
area / length
'4.0 m'

unit.units defines SI units, which are looked up by symbol.

from quantity.quantity import Quantity

q = Quantity(1.0, "MV")
print(q)
'1.0 MV'
q = Quantity(1000000, 'V')
print(q)
'1.0 MV'
print(q.to('V'))
1000000.0

Many simple conversions are also provided

from quantity.quantity import Quantity

volts = Quantity(10, 'V')
amps = Quantity(100, 'A')
volts * amps
'1.0 kW'
volts / amps
'100.0 mΩ'

You can define your own units. We can get frames per second by defining frames.

from quantity.unit import Unit
from quantity.quantity import Quantity

frame = Unit('f', "frame")
frames = Quantity(432000, "frame")
running_time = Quantity(120 * 60, 's')
fps = frames / running_time
print(fps)
'60.0 f/s'

About

Quantities in Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages