buckingham 1.0

Massimo Di Pierro mdipierro at cs.depaul.edu
Mon Oct 18 02:11:22 CEST 2010

Dimensional Analysis / Formula Validation/ Units Conversion / Error Propagation
In one single small file without dependencies



based on the Buckingham Theorem

How to use

download the module
download Python
start Python
import the module:
>>> from buckingham import Number, sin, cos, exp, log, allunits, pm
Example of dimensional analysis and conversions

>>> a = Number(10,dims='meter/second')
>>> b = Number(2,dims='yard/minute')
>>> c = a + b
>>> print c.convert('kilometer/hour')
    (36.109728 ± 0)
>>> Number(1,dims='joule').convert('eV').value
>>> print c.value, c.error, c.units()
    10.03048 0.0 meter*second^-1
Without conversion results are always in:

meters, seconds, grams, ampere, kelvin, currency (and combination)
The error is the standard deviation assuming the true value is Normal distributed

Error propagation assumes independence

>>> a = Number(1,dims='decimeter^3')
>>> b = Number(2,dims='liter')
>>> c = Number(5,dims='gram/centimeter^3')
>>> d = (a + b)*c
>>> print d.convert('kilogram')
    (15.000000 ± 0)
Simplified syntax

>>> globals().update(allunits())
>>> length = (4+pm(0.5)) * meter
>>> velocity = 5 * meter/second
>>> time = length/velocity
>>> print time
    (8.00 ± 1.00)/10 
Example of formula validation

>>> a = Number(10,dims='meter/second')
>>> b = Number(2,dims='yard^3')
>>> c = a + b
Traceback (most recent call last):
RuntimeError: Incompatible Dimensions
Examples of error propagation

>>> a = Number(10,error=2,dims='meter/second') # (10±2)m/s
>>> b = Number(5,error=1,dims='hour')  # (5±1)h
>>> c = a*b
>>> print c.convert('kilometer')
    (1.800 ± 0.509)x10^2
>>> print c.convert('lightyear')
    (1.903 ± 0.538)/10^11
>>> print c.convert('kilometer').value
>>> print c.convert('kilometer').error
Examples of more complex formulas

>>> c = a**4/(7*b)     
>>> print '%s %s' % (c,c.units())
    (7.94 ± 6.54)/10^2 meter^4*second^-5
For pure numbers sin, cos, exp, log are also defined. You can use a.is_pure() to check if a number is pure.
Financial application example

>>> coupon = Number(200,error=1,dims="dollar/day")
>>> expiration = Number(1,error=0,dims="year")
>>> payoff = coupon*expiration
>>> print payoff.convert('dollar')
    (7.3048 ± 0.0365)x10^4
I.e. $73048 dollars with $365 dollars of one sigma uncertainly

Latex Output

>>> print payoff.as_latex()
    (7.3048 \pm 0.0365)\times 10^{4} 

Notice the output as a string always uses scientific notation and value is automatically rounded compatibly with error/uncertainty in result.

Supported units and combination of

ampere, angstrom, atm, attoL, attoampere, attoangstrom, attoatm, attoau, attobar, attocalorie, attocoulomb, attocurrency, attoday, attodollar, attoeV, attoev, attofarad, attofaraday, attofermi, attofoot, attogram, attohenry, attohour, attohz, attoinch, attojoule, attokelvin, attolightyear, attoliter, attometer, attomho, attomile, attominute, attommhg, attonewton, attoohm, attopascal, attopound, attopsi, attopure, attoquart, attosecond, attosiemens, attovolt, attowatt, attoweber, attoyard, attoyear, au, bar, calorie, centiL, centiampere, centiangstrom, centiatm, centiau, centibar, centicalorie, centicoulomb, centicurrency, centiday, centidollar, centieV, centiev, centifarad, centifaraday, centifermi, centifoot, centigram, centihenry, centihour, centihz, centiinch, centijoule, centikelvin, centilightyear, centiliter, centimeter, centimho, centimile, centiminute, centimmhg, centinewton, centiohm, centipascal, centipound, centipsi, centipure, centiquart, centisecond, centisiemens, centivolt, centiwatt, centiweber, centiyard, centiyear, coulomb, currency, day, deciL, deciampere, deciangstrom, deciatm, deciau, decibar, decicalorie, decicoulomb, decicurrency, deciday, decidollar, decieV, deciev, decifarad, decifaraday, decifermi, decifoot, decigram, decihenry, decihour, decihz, deciinch, decijoule, decikelvin, decilightyear, deciliter, decimeter, decimho, decimile, deciminute, decimmhg, decinewton, deciohm, decipascal, decipound, decipsi, decipure, deciquart, decisecond, decisiemens, decivolt, deciwatt, deciweber, deciyard, deciyear, dekaL, dekaampere, dekaangstrom, dekaatm, dekaau, dekabar, dekacalorie, dekacoulomb, dekacurrency, dekaday, dekadollar, dekaeV, dekaev, dekafarad, dekafaraday, dekafermi, dekafoot, dekagram, dekahenry, dekahour, dekahz, dekainch, dekajoule, dekakelvin, dekalightyear, dekaliter, dekameter, dekamho, dekamile, dekaminute, dekammhg, dekanewton, dekaohm, dekapascal, dekapound, dekapsi, dekapure, dekaquart, dekasecond, dekasiemens, dekavolt, dekawatt, dekaweber, dekayard, dekayear, dollar, eV, ev, exaL, exaampere, exaangstrom, exaatm, exaau, exabar, exacalorie, exacoulomb, exacurrency, exaday, exadollar, exaeV, exaev, exafarad, exafaraday, exafermi, exafoot, exagram, exahenry, exahour, exahz, exainch, exajoule, exakelvin, exalightyear, exaliter, exameter, examho, examile, examinute, exammhg, exanewton, exaohm, exapascal, exapound, exapsi, exapure, exaquart, exasecond, exasiemens, exavolt, exawatt, exaweber, exayard, exayear, farad, faraday, femtoL, femtoampere, femtoangstrom, femtoatm, femtoau, femtobar, femtocalorie, femtocoulomb, femtocurrency, femtoday, femtodollar, femtoeV, femtoev, femtofarad, femtofaraday, femtofermi, femtofoot, femtogram, femtohenry, femtohour, femtohz, femtoinch, femtojoule, femtokelvin, femtolightyear, femtoliter, femtometer, femtomho, femtomile, femtominute, femtommhg, femtonewton, femtoohm, femtopascal, femtopound, femtopsi, femtopure, femtoquart, femtosecond, femtosiemens, femtovolt, femtowatt, femtoweber, femtoyard, femtoyear, fermi, foot, gigaL, gigaampere, gigaangstrom, gigaatm, gigaau, gigabar, gigacalorie, gigacoulomb, gigacurrency, gigaday, gigadollar, gigaeV, gigaev, gigafarad, gigafaraday, gigafermi, gigafoot, gigagram, gigahenry, gigahour, gigahz, gigainch, gigajoule, gigakelvin, gigalightyear, gigaliter, gigameter, gigamho, gigamile, gigaminute, gigammhg, giganewton, gigaohm, gigapascal, gigapound, gigapsi, gigapure, gigaquart, gigasecond, gigasiemens, gigavolt, gigawatt, gigaweber, gigayard, gigayear, gram, henctoL, henctoampere, henctoangstrom, henctoatm, henctoau, henctobar, henctocalorie, henctocoulomb, henctocurrency, henctoday, henctodollar, henctoeV, henctoev, henctofarad, henctofaraday, henctofermi, henctofoot, henctogram, henctohenry, henctohour, henctohz, henctoinch, henctojoule, henctokelvin, henctolightyear, henctoliter, henctometer, henctomho, henctomile, henctominute, henctommhg, henctonewton, henctoohm, henctopascal, henctopound, henctopsi, henctopure, henctoquart, henctosecond, henctosiemens, henctovolt, henctowatt, henctoweber, henctoyard, henctoyear, henry, hour, hz, inch, joule, kelvin, kiloL, kiloampere, kiloangstrom, kiloatm, kiloau, kilobar, kilocalorie, kilocoulomb, kilocurrency, kiloday, kilodollar, kiloeV, kiloev, kilofarad, kilofaraday, kilofermi, kilofoot, kilogram, kilohenry, kilohour, kilohz, kiloinch, kilojoule, kilokelvin, kilolightyear, kiloliter, kilometer, kilomho, kilomile, kilominute, kilommhg, kilonewton, kiloohm, kilopascal, kilopound, kilopsi, kilopure, kiloquart, kilosecond, kilosiemens, kilovolt, kilowatt, kiloweber, kiloyard, kiloyear, lightyear, liter, megaL, megaampere, megaangstrom, megaatm, megaau, megabar, megacalorie, megacoulomb, megacurrency, megaday, megadollar, megaeV, megaev, megafarad, megafaraday, megafermi, megafoot, megagram, megahenry, megahour, megahz, megainch, megajoule, megakelvin, megalightyear, megaliter, megameter, megamho, megamile,  megaminute, megammhg, meganewton, megaohm, megapascal, megapound, megapsi, megapure, megaquart, megasecond, megasiemens, megavolt, megawatt, megaweber, megayard, megayear, meter, mho, microL, microampere, microangstrom, microatm, microau, microbar, microcalorie, microcoulomb, microcurrency, microday, microdollar, microeV, microev, microfarad, microfaraday, microfermi, microfoot, microgram, microhenry, microhour, microhz, microinch, microjoule, microkelvin, microlightyear, microliter, micrometer, micromho, micromile, microminute, micrommhg, micronewton, microohm, micropascal, micropound, micropsi, micropure, microquart, microsecond, microsiemens, microvolt, microwatt, microweber, microyard, microyear, mile, milliL, milliampere, milliangstrom, milliatm, milliau, millibar, millicalorie, millicoulomb, millicurrency, milliday, millidollar, millieV, milliev, millifarad, millifaraday, millifermi, millifoot, milligram, millihenry, millihour, millihz, milliinch, millijoule, millikelvin, millilightyear, milliliter, millimeter, millimho, millimile, milliminute, millimmhg, millinewton, milliohm, millipascal, millipound, millipsi, millipure, milliquart, millisecond, millisiemens, millivolt, milliwatt, milliweber, milliyard, milliyear, minute, mmhg, nanoL, nanoampere, nanoangstrom, nanoatm, nanoau, nanobar, nanocalorie, nanocoulomb, nanocurrency, nanoday, nanodollar, nanoeV, nanoev, nanofarad, nanofaraday, nanofermi, nanofoot, nanogram, nanohenry, nanohour, nanohz, nanoinch, nanojoule, nanokelvin, nanolightyear, nanoliter, nanometer, nanomho, nanomile, nanominute, nanommhg, nanonewton, nanoohm, nanopascal, nanopound, nanopsi, nanopure, nanoquart, nanosecond, nanosiemens, nanovolt, nanowatt, nanoweber, nanoyard, nanoyear, newton, none, ohm, pascal, petaL, petaampere, petaangstrom, petaatm, petaau, petabar, petacalorie, petacoulomb, petacurrency, petaday, petadollar, petaeV, petaev, petafarad, petafaraday, petafermi, petafoot, petagram, petahenry, petahour, petahz, petainch, petajoule, petakelvin, petalightyear, petaliter, petameter, petamho, petamile, petaminute, petammhg, petanewton, petaohm, petapascal, petapound, petapsi, petapure, petaquart, petasecond, petasiemens, petavolt, petawatt, petaweber, petayard, petayear, picoL, picoampere, picoangstrom, picoatm, picoau, picobar, picocalorie, picocoulomb, picocurrency, picoday, picodollar, picoeV, picoev, picofarad, picofaraday, picofermi, picofoot, picogram, picohenry, picohour, picohz, picoinch, picojoule, picokelvin, picolightyear, picoliter, picometer, picomho, picomile, picominute, picommhg, piconewton, picoohm, picopascal, picopound, picopsi, picopure, picoquart, picosecond, picosiemens, picovolt, picowatt, picoweber, picoyard, picoyear, pound, psi, pure, quart, second, siemens, teraL, teraampere, teraangstrom, teraatm, teraau, terabar, teracalorie, teracoulomb, teracurrency, teraday, teradollar, teraeV, teraev, terafarad, terafaraday, terafermi, terafoot, teragram, terahenry, terahour, terahz, terainch, terajoule, terakelvin, teralightyear, teraliter, terameter, teramho, teramile, teraminute, terammhg, teranewton, teraohm, terapascal, terapound, terapsi, terapure, teraquart, terasecond, terasiemens, teravolt, terawatt, teraweber, terayard, terayear, volt, vottaL, vottaampere, vottaangstrom, vottaatm, vottaau, vottabar, vottacalorie, vottacoulomb, vottacurrency, vottaday, vottadollar, vottaeV, vottaev, vottafarad, vottafaraday, vottafermi, vottafoot, vottagram, vottahenry, vottahour, vottahz, vottainch, vottajoule, vottakelvin, vottalightyear, vottaliter, vottameter, vottamho, vottamile, vottaminute, vottammhg, vottanewton, vottaohm, vottapascal, vottapound, vottapsi, vottapure, vottaquart, vottasecond, vottasiemens, vottavolt, vottawatt, vottaweber, vottayard, vottayear, watt, weber, yard, year, yoctoL, yoctoampere, yoctoangstrom, yoctoatm, yoctoau, yoctobar, yoctocalorie, yoctocoulomb, yoctocurrency, yoctoday, yoctodollar, yoctoeV, yoctoev, yoctofarad, yoctofaraday, yoctofermi, yoctofoot, yoctogram, yoctohenry, yoctohour, yoctohz, yoctoinch, yoctojoule, yoctokelvin, yoctolightyear, yoctoliter, yoctometer, yoctomho, yoctomile, yoctominute, yoctommhg, yoctonewton, yoctoohm, yoctopascal, yoctopound, yoctopsi, yoctopure, yoctoquart, yoctosecond, yoctosiemens, yoctovolt, yoctowatt, yoctoweber, yoctoyard, yoctoyear, zeptoL, zeptoampere, zeptoangstrom, zeptoatm, zeptoau, zeptobar, zeptocalorie, zeptocoulomb, zeptocurrency, zeptoday, zeptodollar, zeptoeV, zeptoev, zeptofarad, zeptofaraday, zeptofermi, zeptofoot, zeptogram, zeptohenry, zeptohour, zeptohz, zeptoinch, zeptojoule, zeptokelvin, zeptolightyear, zeptoliter, zeptometer, zeptomho, zeptomile, zeptominute, zeptommhg, zeptonewton, zeptoohm, zeptopascal, zeptopound, zeptopsi, zeptopure, zeptoquart, zeptosecond, zeptosiemens, zeptovolt, zeptowatt, zeptoweber, zeptoyard, zeptoyear, zettaL, zettaampere, zettaangstrom, zettaatm, zettaau, zettabar, zettacalorie, zettacoulomb, zettacurrency, zettaday, zettadollar, zettaeV, zettaev, zettafarad, zettafaraday, zettafermi, zettafoot, zettagram, zettahenry, zettahour, zettahz, zettainch, zettajoule, zettakelvin, zettalightyear, zettaliter, zettameter, zettamho, zettamile, zettaminute, zettammhg, zettanewton, zettaohm, zettapascal, zettapound, zettapsi, zettapure, zettaquart, zettasecond, zettasiemens, zettavolt, zettawatt, zettaweber, zettayard, zettayear 

More information about the Python-announce-list mailing list