Skip to content

Commit

Permalink
syntax improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rieder committed Mar 6, 2023
1 parent 6145723 commit 1edc358
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
31 changes: 17 additions & 14 deletions src/amuse/units/derivedsi.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
from amuse.units.si import (
named, s, m, kg, A, none, k,
)
from amuse.units.si import *

Hz = named('hertz', 'Hz', 1/s)
MHz = named('megahertz', 'MHz', 1e6*Hz)
rad = named('radian','rad',m/m)
sr = named('steradian','sr',m**2/m**2)
N = named('newton', 'N', kg * m /s**2)
Pa = named('pascal', 'Pa', N / (m ** 2))
J = named('joule','J', kg * m **2 * s ** -2)
Hz = named('hertz', 'Hz', 1 / s)
MHz = named('megahertz', 'MHz', 1e6 * Hz)
rad = named('radian', 'rad', m / m)
sr = named('steradian', 'sr', m**2 / (m**2))
N = named('newton', 'N', kg * m / (s**2))
Pa = named('pascal', 'Pa', N / (m**2))
J = named('joule', 'J', kg * m**2 * s**-2)
W = named('watt', 'W', J / s)
F = named('farad','F', s**4*A**2*m**(-2)*kg**(-1))
C = named('coulomb','C', A*s)
V = named('volt','V', J/C)
T = named('tesla','T', kg/A/s/s)
F = named('farad', 'F', s**4 * A**2 * m**(-2) * kg**(-1))
C = named('coulomb', 'C', A * s)
V = named('volt', 'V', J / C)
T = named('tesla', 'T', kg / A / s / s)
tesla = T
ohm = named('ohm','ohm', V/A)
S = named('siemens', 'S', A/V)
Wb = named('weber','Wb', V*s)
ohm = named('ohm', 'ohm', V / A)
S = named('siemens', 'S', A / V)
Wb = named('weber', 'Wb', V * s)
weber = Wb

# handy definitions
Expand Down
7 changes: 2 additions & 5 deletions src/amuse/units/quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
HAS_ASTROPY = False


class Quantity(object):
class Quantity:
"""
A Quantity objects represents a scalar or vector with a
specific unit. Quantity is an abstract base class
Expand Down Expand Up @@ -181,9 +181,6 @@ def sqrt(self):
"""
return new_quantity(numpy.sqrt(self.number), (self.unit ** 0.5).to_simple_form())




def as_quantity_in(self, another_unit):
"""
Reproduce quantity in another unit.
Expand All @@ -197,7 +194,7 @@ def as_quantity_in(self, another_unit):
factor = self.unit.conversion_factor_from(another_unit)
return new_quantity(self.number * factor, another_unit)

in_=as_quantity_in
in_ = as_quantity_in

def as_string_in(self, another_unit):
"""
Expand Down
45 changes: 23 additions & 22 deletions src/amuse/units/si.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,52 @@
cd = core.base_unit('luminous intensity', 'candela', 'cd', system)

no_system = core.no_system
none = core.none_unit('none','none')
none = core.none_unit('none', 'none')
no_unit = none

named = core.named_unit

# SI prefixes
def deca(unit):
return named('deca'+unit.name,'da'+unit.symbol,10.*unit)
return named('deca' + unit.name, 'da' + unit.symbol, 10. * unit)
def hecto(unit):
return named('hecto'+unit.name,'h'+unit.symbol,100.*unit)
return named('hecto' + unit.name, 'h' + unit.symbol, 100. * unit)
def kilo(unit):
return named('kilo'+unit.name,'k'+unit.symbol,1000.*unit)
return named('kilo' + unit.name, 'k' + unit.symbol, 1000. * unit)
def mega(unit):
return named('mega'+unit.name,'M'+unit.symbol,1.e6*unit)
return named('mega' + unit.name, 'M' + unit.symbol, 1.e6 * unit)
def giga(unit):
return named('giga'+unit.name,'G'+unit.symbol,1.e9*unit)
return named('giga' + unit.name, 'G' + unit.symbol, 1.e9 * unit)
def tera(unit):
return named('tera'+unit.name,'T'+unit.symbol,1.e12*unit)
return named('tera' + unit.name, 'T' + unit.symbol, 1.e12 * unit)
def peta(unit):
return named('peta'+unit.name,'P'+unit.symbol,1.e15*unit)
return named('peta' + unit.name, 'P' + unit.symbol, 1.e15 * unit)
def exa(unit):
return named('exa'+unit.name,'E'+unit.symbol,1.e18*unit)
return named('exa' + unit.name, 'E' + unit.symbol, 1.e18 * unit)
def zetta(unit):
return named('zetta'+unit.name,'Z'+unit.symbol,1.e21*unit)
return named('zetta' + unit.name, 'Z' + unit.symbol, 1.e21 * unit)
def yotta(unit):
return named('yotta'+unit.name,'Y'+unit.symbol,1.e24*unit)
return named('yotta' + unit.name, 'Y' + unit.symbol, 1.e24 * unit)
def deci(unit):
return named('deci'+unit.name,'d'+unit.symbol,0.1*unit)
return named('deci' + unit.name, 'd' + unit.symbol, 0.1 * unit)
def centi(unit):
return named('centi'+unit.name,'c'+unit.symbol,0.01*unit)
return named('centi' + unit.name, 'c' + unit.symbol, 0.01 * unit)
def milli(unit):
return named('milli'+unit.name,'m'+unit.symbol,0.001*unit)
return named('milli' + unit.name, 'm' + unit.symbol, 0.001 * unit)
def micro(unit):
return named('micro'+unit.name,'mu'+unit.symbol,1.e-6*unit)
return named('micro' + unit.name, 'mu' + unit.symbol, 1.e-6 * unit)
def nano(unit):
return named('nano'+unit.name,'n'+unit.symbol,1.e-9*unit)
return named('nano' + unit.name, 'n' + unit.symbol, 1.e-9 * unit)
def pico(unit):
return named('pico'+unit.name,'p'+unit.symbol,1.e-12*unit)
return named('pico' + unit.name, 'p' + unit.symbol, 1.e-12 * unit)
def femto(unit):
return named('femto'+unit.name,'f'+unit.symbol,1.e-15*unit)
return named('femto' + unit.name, 'f' + unit.symbol, 1.e-15 * unit)
def atto(unit):
return named('atto'+unit.name,'a'+unit.symbol,1.e-18*unit)
return named('atto' + unit.name, 'a' + unit.symbol, 1.e-18 * unit)
def zepto(unit):
return named('zepto'+unit.name,'z'+unit.symbol,1.e-21*unit)
return named('zepto' + unit.name, 'z' + unit.symbol, 1.e-21 * unit)
def yocto(unit):
return named('yocto'+unit.name,'y'+unit.symbol,1.e-24*unit)
return named('yocto' + unit.name, 'y' + unit.symbol, 1.e-24 * unit)

k=kilo

k = kilo

0 comments on commit 1edc358

Please sign in to comment.