def test_named_pickle(): """Pickling is reversible on quantities backed by named units""" named = named_unit('S', 'N', 'D') arbitrary_quantity = named(3.0) pickled = dumps(arbitrary_quantity) unpickled = loads(pickled) assert within_epsilon(arbitrary_quantity, unpickled)
def __init__(self, codata): #SI units self.si_mass = unit('kg') self.si_charge = unit('C') self.si_energy = unit('J') self.si_action = unit('J') * unit('s') self.si_time = unit('s') self.si_frequency = unit('Hz') #farad_per_meter = unit('F') / unit('m') self.codata = codata #Define basic atomic units constants self.mass = scaled_unit('mass_au', *codata['electron mass']) self.charge = scaled_unit('charge_au', *codata['atomic unit of charge']) self.electrostatic_constant = named_unit('eps0_au', ['F'], ['m'], codata['atomic unit of permittivity'][1]) self.hbar = named_unit('action_au', ['J'], ['s'], codata['atomic unit of action'][1]) self.alpha = codata['fine-structure constant'][1] self.time = scaled_unit('time_au', *codata['atomic unit of time']) #Derived units self.speed = scaled_unit("speed_au", *codata['atomic unit of velocity']) self.lightspeed = self.speed(codata['speed of light in vacuum'][1]) self.length = scaled_unit('length_au', 'm', (self.electrostatic_constant * self.hbar**2 / (self.mass * self.charge**2)).squeeze()) self.energy = scaled_unit('energy_au', 'J', (self.hbar**2 / (self.mass * self.length**2)).squeeze()) self.electric_field_strength = named_unit('efield_au', ['V'], ['m'], (self.charge / (self.electrostatic_constant * self.length**2)).squeeze()) self.frequency = scaled_unit('frequency_au', 'Hz', 1.0/self.time.squeeze()) #Other units self.electron_volt = scaled_unit('eV', *codata['electron volt']) self.femtosecond = scaled_unit('fs', 's', self.si_time.squeeze()*1e-15)
"""Define the scalar units used by vehicle measurements.""" import sys from units import unit, scaled_unit, named_unit import units.predefined units.predefined.define_units() Percentage = unit('%') Meter = unit('m') Kilometer = scaled_unit('km', 'm', 1000) Hour = unit('h') KilometersPerHour = unit('km') / unit('h') RotationsPerMinute = unit('rotations') / unit('m') Litre = unit('L') Degree = unit('deg') NewtonMeter = named_unit("Nm", ["N", "m"], []) MetersPerSecondSquared = unit('m') / (pow(unit('s'), 2)) Undefined = unit('undef')
def define_complex_si_units(): """Define SI units that are built on other SI units. >>> define_complex_si_units() >>> unit('Hz').is_si() True """ LeafUnit("rad", name="radian", is_si=True) # Plane angle LeafUnit("sr", name="steradian", is_si=True) # Solid angle named_unit("Hz", [], ["s"], name="hertz") # Frequency named_unit("N", ["m", "kg"], ["s", "s"], name="newton") # Force named_unit("Pa", ["N"], ["m", "m"], name="pascal") # Pressure or mechanical stress named_unit("J", ["N", "m"], [], name="joule") # Energy, work, or amount of heat (Dangerous, 3J is a complex number) named_unit("W", ["J"], ["s"], name="watt") # Power or heat flow rate named_unit("C", ["s", "A"], [], name="coulomb") # Electric charge named_unit("V", ["W"], ["A"], name="volt") # Electromotive force, electric potential difference named_unit("Ohm", ["V"], ["A"], symbal=u"Ω", name="ohm") # Electrical resistance named_unit("F", ["C"], ["V"], name="farad") # Capacitance named_unit("Wb", ["V", "s"], [], name="weber") # Magnetic flux named_unit("T", ["Wb"], ["m", "m"], name="tesla") # Magnetic flux density named_unit("H", ["Wb"], ["A"], name="henry") # Inductance named_unit("lm", ["cd", "sr"], [], name="lumen") # Luminous flux named_unit("lx", ["lm"], ["m", "m"], name="lux") # Illuminance named_unit("Bq", [], ["s"], name="becquerel") # Radiation - source activity named_unit("Gy", ["J"], ["kg"], name="gray") # Radiation - absorbed dose named_unit("Sv", ["J"], ["kg"], name="sievert") # Radiation - equivalent dose named_unit("S", ["A"], ["V"], name="siemens") # Siemens named_unit("kat", ["mol"], ["s"], name="katal") # Katal
"""Define the scalar units used by vehicle measurements.""" from __future__ import absolute_import import sys from units import unit, scaled_unit, named_unit import units.predefined units.predefined.define_units() Percentage = unit("%") Meter = unit("m") Kilometer = scaled_unit("km", "m", 1000) Hour = unit("h") KilometersPerHour = unit("km") / unit("h") RotationsPerMinute = unit("rotations") / unit("m") Litre = unit("L") Degree = unit("deg") NewtonMeter = named_unit("Nm", ["N", "m"], []) MetersPerSecondSquared = unit("m") / (pow(unit("s"), 2)) Undefined = unit("undef")
def define_complex_si_units(): """Define SI units that are built on other SI units. >>> define_complex_si_units() >>> unit('Hz').is_si() True """ for sym in ["rad", "sr"]: LeafUnit(sym, is_si=True) named_unit("Hz", [], ["s"]) #hertz named_unit("N", ["m", "kg"], ["s", "s"]) #Newton named_unit("Pa", ["N"], ["m", "m"]) #pascal named_unit("J", ["N", "m"], []) #Joule # Dangerous, 3J is a complex number named_unit("W", ["J"], ["s"]) # Watt named_unit("C", ["s", "A"], []) # Coulomb named_unit("V", ["W"], ["A"]) # Volt named_unit("F", ["C"], ["V"]) # Farad named_unit("Ohm", ["V"], ["A"]) named_unit("S", ["A"], ["V"]) #Siemens named_unit("Wb", ["V", "s"], []) # Weber named_unit("T", ["Wb"], ["m", "m"]) # Tesla named_unit("H", ["Wb"], ["A"]) # Henry named_unit("lm", ["cd", "sr"], []) # lumen named_unit("lx", ["lm"], ["m", "m"]) #lux named_unit("Bq", [], ["s"]) # Becquerel named_unit("Gy", ["J"], ["kg"]) # Gray named_unit("Sv", ["J"], ["kg"]) # Sievert named_unit("kat", ["mol"], ["s"]) # Katal