diff --git a/src/amuse/test/suite/core_tests/test_new_quantities.py b/src/amuse/test/suite/core_tests/test_new_quantities.py new file mode 100644 index 0000000000..39263b3ed7 --- /dev/null +++ b/src/amuse/test/suite/core_tests/test_new_quantities.py @@ -0,0 +1,544 @@ +from amuse.test import amusetest + +import numpy +import sys + + +from amuse.support.exceptions import AmuseException +from amuse.units.quantities import * +from amuse.units import si +from amuse.units import units +from amuse.units import trigo +from amuse.units import nbody_system +from amuse.units import quantities +from amuse.units import core + + +from amuse import datamodel +class TestQuantities(amusetest.TestCase): + + def test1(self): + x = 1.0 * si.kg + self.assertTrue(isinstance(x, ScalarQuantity)) + x = [1.0, 2.0, 3.0] * si.kg + self.assertTrue(isinstance(x, VectorQuantity)) + + def test2(self): + x = [1.0, 2.0, 3.0] * si.kg + y = [2.0, 3.0, 4.0] * si.kg + xy = x * y + self.assertTrue(isinstance(xy, VectorQuantity)) + + + def test3(self): + x = [1.0, 2.0, 3.0] * si.kg + y = [2.0, 3.0, 4.0] * si.kg + self.assertTrue(isinstance(x[0], ScalarQuantity)) + self.assertEqual(str(x[1]), "2.0 kg") + + + def test4(self): + g = si.kg / 1000 + x = [1.0, 2.0, 3.0] * si.kg + self.assertEqual(str(x), "[1.0, 2.0, 3.0] kg") + x[0] = 3000.0 * g + self.assertEqual(str(x), "[3.0, 2.0, 3.0] kg") + + def test5(self): + number_of_stars = 10 + stars = datamodel.Particles(number_of_stars) + stars.position = [0,0,0] * units.km + for i, star in enumerate(stars): + star.position = units.km.new_quantity([float(i+1), float((i+1)*2), float(-1 * (i+1))]) + + + minpos = [float(sys.maxsize)] * 3 * units.m + maxpos = [-float(sys.maxsize)] * 3 * units.m + for star in stars: + for i in range(3): + if star.position[i] < minpos[i]: + minpos[i] = star.position[i] + if star.position[i] > maxpos[i]: + maxpos[i] = star.position[i] + + self.assertEqual(str(minpos), "[1000.0, 2000.0, -10000.0] m") + self.assertEqual(str(maxpos), "[10000.0, 20000.0, -1000.0] m") + + def test6(self): + x = [1.0, 2.0, 3.0] * si.kg + y = x.copy() + y[0] = 3.0 * si.kg + self.assertEqual(x[0].value_in(si.kg), 1.0) + self.assertEqual(y[0].value_in(si.kg), 3.0) + + def test7(self): + x = 2.0 * si.kg + y = 1 / x + self.assertEqual(y.value_in(1/si.kg), 0.5) + + + def test8(self): + x = (1.0, 2.0, 3.0) * si.kg + self.assertTrue(isinstance(x, VectorQuantity)) + + def test9(self): + converter = nbody_system.nbody_to_si(1 * si.kg, 2 * si.s) + self.assertEqual(0.0 * nbody_system.mass, converter.to_nbody(zero)) + self.assertEqual(converter.to_nbody(zero), 0.0 * nbody_system.mass) + + def test10(self): + self.assertEqual(1 * units.m, 1 * units.m) + self.assertTrue (1 * units.m == 1 * units.m) + self.assertFalse(1 * units.m == 2 * units.m) + self.assertTrue (1 * units.m != 2 * units.m) + self.assertFalse(1 * units.m != 1 * units.m) + self.assertTrue (1 * units.m >= 1 * units.m) + self.assertFalse(1 * units.m >= 2 * units.m) + self.assertTrue (1 * units.m <= 1 * units.m) + self.assertFalse(1 * units.m <= 0 * units.m) + self.assertTrue (1 * units.m > 0 * units.m) + self.assertFalse(1 * units.m > 1 * units.m) + self.assertTrue (1 * units.m < 3 * units.m) + self.assertFalse(1 * units.m < 0 * units.m) + + def test11(self): + self.assertEqual([1] * units.m, [1] * units.m) + self.assertTrue ([1] * units.m == [1] * units.m) + self.assertFalse([1] * units.m == [2] * units.m) + self.assertTrue ([1] * units.m != [2] * units.m) + self.assertFalse([1] * units.m != [1] * units.m) + self.assertTrue ([1] * units.m >= [1] * units.m) + self.assertFalse([1] * units.m >= [2] * units.m) + self.assertTrue ([1] * units.m <= [1] * units.m) + self.assertFalse([1] * units.m <= [0] * units.m) + self.assertTrue ([1] * units.m > [0] * units.m) + self.assertFalse([1] * units.m > [1] * units.m) + self.assertTrue ([1] * units.m < [3] * units.m) + self.assertFalse([1] * units.m < [0] * units.m) + + def test12(self): + self.assertEqual(zero, zero) + self.assertTrue (zero == zero) + self.assertFalse(zero == zero + (1 * units.m)) + self.assertFalse(zero + (1 * units.m) == zero) + self.assertTrue (zero != zero + (1 * units.m)) + self.assertFalse(zero != zero) + self.assertTrue (zero >= zero) + self.assertFalse(zero >= zero + (1 * units.m)) + self.assertTrue (zero <= zero + (1 * units.m)) + self.assertFalse(zero <= zero - (1 * units.m)) + self.assertTrue (zero > zero - (1 * units.m)) + self.assertFalse(zero > zero) + self.assertTrue (zero < zero + (1 * units.m)) + self.assertFalse(zero < zero - (1 * units.m)) + self.assertTrue (zero == 0 * units.m) + + def test13(self): + self.assertEqual('a', 'a') + self.assertTrue ('a' == 'a') + self.assertFalse('a' == 'ab') + self.assertTrue ('a' != 'A') + self.assertFalse('a' != 'a') + self.assertTrue ('b' >= 'a') + self.assertFalse('B' >= 'a') + self.assertTrue ('a' <= 'ab') + self.assertFalse('a' <= 'A') + self.assertTrue ('a' > 'A') + self.assertFalse('a' > 'a') + self.assertTrue ('a' < 'b') + self.assertFalse('a' < 'B') + + def test14(self): + # Tests for 'is_quantity' + self.assertTrue( is_quantity(0 * units.kg) ) + self.assertTrue( is_quantity(1 * units.none) ) + self.assertTrue( is_quantity([1.0, 2.0, 3.0] * units.m) ) + self.assertFalse( is_quantity(1) ) + self.assertFalse( is_quantity(1.0) ) + self.assertFalse( is_quantity("string") ) + + def test15(self): + # Tests for 'to_quantity' + self.assertTrue( is_quantity(to_quantity(0 * units.kg)) ) + self.assertTrue( is_quantity(to_quantity(1 * units.none)) ) + self.assertTrue( is_quantity(to_quantity([1.0, 2.0, 3.0] * units.m)) ) + self.assertTrue( is_quantity(to_quantity(1)) ) + self.assertTrue( is_quantity(to_quantity(1.0)) ) + masses = [1, 2, 3] * units.kg + self.assertTrue( to_quantity(masses) is masses ) + numbers = [1, 2, 3] + self.assertFalse( to_quantity(numbers) is numbers * units.none ) + self.assertTrue( numpy.all(to_quantity(numbers) == numbers * units.none) ) + + def test16(self): + # Tests for add/sub of quantity (with none unit) and number + self.assertEqual( (2.0 * units.none) + 1.0, 3.0 ) + self.assertEqual( (2.0 * units.none) - 1.0, 1.0 ) + self.assertEqual( 1.0 + (2.0 * units.none), 3.0 ) + self.assertEqual( 1.0 - (2.0 * units.none), -1.0 ) + + def test17(self): + # Tests for add/sub of quantity (with other unit) and number + number = 1.0 + quantity = 2.0 * units.m + self.assertTrue( number.__add__(quantity) is NotImplemented) + self.assertRaises(AmuseException, quantity.__radd__, number) + self.assertTrue( number.__radd__(quantity) is NotImplemented) + self.assertRaises(AmuseException, quantity.__add__, number) + self.assertTrue( number.__sub__(quantity) is NotImplemented) + self.assertRaises(AmuseException, quantity.__rsub__, number) + self.assertTrue( number.__rsub__(quantity) is NotImplemented) + self.assertRaises(AmuseException, quantity.__sub__, number) + # in other words... + self.assertRaises(AmuseException, lambda: number + quantity, + expected_message = "Cannot express none in m, the units do not have the same bases") + self.assertRaises(AmuseException, lambda: quantity + number, + expected_message = "Cannot express none in m, the units do not have the same bases") + self.assertRaises(AmuseException, lambda: number - quantity, + expected_message = "Cannot express none in m, the units do not have the same bases") + self.assertRaises(AmuseException, lambda: quantity - number, + expected_message = "Cannot express none in m, the units do not have the same bases") + + def test18(self): + quantity = 'string' + self.assertEqual(quantity , 'string') + quantity = 'string' + self.assertEqual(quantity , 'string') + + def test19(self): + x = 1.0 * si.kg + self.assertTrue(x==x.amin()) + self.assertTrue(x==x.prod()) + self.assertTrue(x==x.sorted()) + self.assertTrue(x==x.amax()) + self.assertTrue(x==x.sum()) + + def test20(self): + lengths = [] * units.m + lengths.append(1 * units.m) + self.assertEqual(lengths, [1] * units.m) + lengths.append(2 * units.m) + self.assertEqual(lengths, [1, 2] * units.m) + + positions = [] * units.m + positions.append([1, 2, 3] * units.m) + self.assertEqual(positions, [[1, 2, 3]] * units.m) + positions.append([4, 5, 6] * units.m) + self.assertEqual(positions, [[1, 2, 3], [4, 5, 6]] * units.m) + + two_positions = [] * units.m + two_positions.append([[1, 2, 3], [-1, -2, -3]] * units.m) + self.assertEqual(two_positions, [[[1, 2, 3], [-1, -2, -3]]] * units.m) + two_positions.append([[4, 5, 6], [7, 8, 9]] * units.m) + self.assertEqual(two_positions, [[[1, 2, 3], [-1, -2, -3]], [[4, 5, 6], [7, 8, 9]]] * units.m) + # Appending quantities with incompatible shapes: + two_positions.append(99 * units.m) + self.assertEqual(two_positions, [1, 2, 3, -1, -2, -3, 4, 5, 6, 7, 8, 9, 99] * units.m) + + def test21(self): + zero_vector = zero.as_vector_with_length(3) + self.assertEqual(str(zero_vector), "[0.0, 0.0, 0.0] zero") + + self.assertEqual(zero_vector + (1 * units.m), [1, 1, 1] * units.m) + self.assertEqual(zero_vector - (1 * units.m), [-1, -1, -1] * units.m) + self.assertEqual((1 * units.m) + zero_vector, [1, 1, 1] * units.m) + self.assertEqual((1 * units.m) - zero_vector, [1, 1, 1] * units.m) + + self.assertEqual(zero_vector + ([1, 1, 1] * units.m), [1, 1, 1] * units.m) + self.assertEqual(zero_vector - ([1, 1, 1] * units.m), [-1, -1, -1] * units.m) + self.assertEqual(([1, 1, 1] * units.m) + zero_vector, [1, 1, 1] * units.m) + self.assertEqual(([1, 1, 1] * units.m) - zero_vector, [1, 1, 1] * units.m) + + for one_zero in zero_vector: + self.assertEqual(one_zero, zero) + + self.assertEqual(zero_vector[0:2], zero.as_vector_with_length(2)) + + + def test22(self): + x = numpy.asarray([1,2,3,4]) + y = 2 * units.m + self.assertTrue(is_quantity(y * x)) + self.assertAlmostRelativeEquals(y*x, [2,4,6,8] * units.m) + self.assertTrue(is_quantity(x * y)) + self.assertAlmostRelativeEquals(x*y, [2,4,6,8] * units.m) + + def test23(self): + z = zero.as_vector_with_length(2) + self.assertEqual(len(z), 2) + z += 1 * units.kg + self.assertEqual(z.unit, units.kg) + self.assertEqual(z, [1,1] * units.kg) + + + def xtest24(self): + rhs = 2 * units.MSun / units.AU + lhs = 3 * units.AU + product = rhs * lhs + product_unit = product.unit + print(product) + self.assertTrue(product_unit is units.MSun) + + + def xtest25(self): + rhs = 2.0 * (2 * units.MSun)**2 / units.AU + lhs = 3.0 * units.MSun + product = rhs / lhs + product_unit = product.unit + print(product) + self.assertEqual(product_unit , units.MSun / units.AU) + self.assertEqual(product_unit.local_factor , 4) + + + def xtest26(self): + rhs = 2.0 * units.AU / (2 * units.MSun)**2 + lhs = 3.0 * units.MSun + product = rhs * lhs + product_unit = product.unit + print(product) + print(type(product_unit)) + self.assertEqual(product_unit , units.AU / units.MSun) + self.assertEqual(product_unit.local_factor , 1/4.0) + + def test27(self): + a=[1.*units.kg,2.*units.kg,3000.* units.g, 4.* (1000*units.g)] + b=VectorQuantity.new_from_scalar_quantities(*a) + c=[1.,2.,3.,4.] * units.kg + print(a[0].unit==a[2].unit) + self.assertEqual(b,c) + + def test28(self): + a=[1.*units.kg,2.*units.kg,3000.* units.m, 4.* (1000*units.g)] + try: + b=VectorQuantity.new_from_scalar_quantities(*a) + raise Exception("expect error") + except: + pass + + def test29(self): + one_inch = 2.54 * units.cm + self.assertFalse(isinstance(one_inch, core.unit)) + self.assertTrue(isinstance(one_inch.as_unit(), core.unit)) + self.assertEqual(one_inch.as_unit(), 2.54 * units.cm) + self.assertEqual(1 * one_inch.as_unit(), 2.54 * units.cm) + + def test30(self): + a=1.5* units.km + b=1000. * units.m + self.assertEqual(a%b,500. * units.m) + a=[1.5,1.75]* units.km + b=1000. * units.m + self.assertEqual(a%b,[500.,750] * units.m) + a=[1.5,1.75]* units.km + b=[1000.,500.] * units.m + self.assertEqual(a%b,[500.,250.] * units.m) + a=[1.5]* units.km + b=[1000.,500.] * units.m + self.assertEqual(a%b,[500.,0.] * units.m) + + def test31(self): + """ + test trigonometric unit stuff + """ + self.assertEqual(units.pi,numpy.pi) + a=units.pi + self.assertEqual(trigo.to_rad(a), numpy.pi * units.rad) + self.assertEqual(trigo.to_deg(a), 180. * units.deg) + self.assertEqual(trigo.to_rev(a), 0.5 * units.rev) + a=90 * units.deg + self.assertEqual(trigo.to_rad(a), numpy.pi/2 * units.rad) + self.assertEqual(trigo.to_deg(a), 90. * units.deg) + self.assertEqual(trigo.to_rev(a), 0.25 * units.rev) + a=0.75 * units.rev + self.assertEqual(trigo.to_rad(a), 3/2.*numpy.pi * units.rad) + self.assertEqual(trigo.to_deg(a), 270. * units.deg) + self.assertEqual(trigo.to_rev(a), 0.75 * units.rev) + a=2*numpy.pi + self.assertEqual(trigo.to_rad(a), 2*numpy.pi * units.rad) + self.assertEqual(trigo.to_deg(a), 360. * units.deg) + self.assertEqual(trigo.to_rev(a), 1. * units.rev) + + a=45. * units.deg + self.assertEqual(trigo.sin(a),numpy.sin(45./180*numpy.pi)) + self.assertEqual(trigo.cos(a),numpy.cos(45./180*numpy.pi)) + self.assertEqual(trigo.tan(a),numpy.tan(45./180*numpy.pi)) + + a=1. * units.rad + self.assertEqual(trigo.sin(a),numpy.sin(1.)) + self.assertEqual(trigo.cos(a),numpy.cos(1.)) + self.assertEqual(trigo.tan(a),numpy.tan(1.)) + + a=0.125 * units.rev + self.assertEqual(trigo.sin(a),numpy.sin(45./180*numpy.pi)) + self.assertEqual(trigo.cos(a),numpy.cos(45./180*numpy.pi)) + self.assertEqual(trigo.tan(a),numpy.tan(45./180*numpy.pi)) + + a=45. * units.deg + self.assertAlmostEqual(trigo.arcsin(trigo.sin(a)),45. * units.deg,13) + self.assertAlmostEqual(trigo.arccos(trigo.cos(a)),45. * units.deg,13) + self.assertAlmostEqual(trigo.arctan(trigo.tan(a)),45. * units.deg,13) + + def test32(self): + a=numpy.array([[1.,2.,3.],[4.,5.,6.]]) * units.m + b=numpy.array([[1.,2.,3.],[4.,5.,6.]]) + self.assertEqual(list(a.flatten()), list(a.flat)) + flat1=b.flat + flat2=a.flat + self.assertEqual(flat1[2:5],flat2[2:5].number) + next(flat1) + next(flat2) + self.assertEqual(flat1.index,flat2.index) + self.assertEqual(flat1.base,flat2.base.number) + self.assertEqual(flat1.copy(),flat2.copy().number) + + def test32b(self): + a=numpy.array([[1.,2.,3.],[4.,5.,6.]]) * units.m + b=numpy.array([[1.,2.,3.],[4.,5.,6.]]) + flat1=b.flat + flat2=a.flat + self.assertEqual(flat1[2:5],flat2[2:5].number) + self.assertEqual(flat1,flat2.number) + + flat2[:]=numpy.arange(6) * units.cm + a_=numpy.array([[0.,1.,2.],[3.,4.,5.]]) * units.cm + self.assertEqual(a, a_) + + def test33(self): + a=[1,2,3,4] + b=new_quantity_nonone(a,units.none) + self.assertEqual(len(a),len(b)) + b=new_quantity_nonone(a,2*units.none) + self.assertEqual(len(a),len(b)) + + def test34(self): + a= [1,2,3,4,5] * units.m + x= a.value_in(units.cm) + x[0]=-1 + self.assertEqual(a, [1,2,3,4,5] * units.m) + + a= [1,2,3,4,5] * units.m + x= a.value_in(units.m) + x[0]=-1 + self.assertEqual(a, [1,2,3,4,5] * units.m) + + +class TestAdaptingVectorQuantities(amusetest.TestCase): + + def test1(self): + x = AdaptingVectorQuantity() + self.assertEqual(x.append.__name__, "append_start") + x.append(1 * units.kg) + self.assertEqual(x.unit, units.kg) + self.assertEqual(len(x), 1) + self.assertEqual(x.append.__name__, "append_normal") + + self.assertTrue(isinstance(x._number_list, list)) + self.assertFalse(isinstance(x._number_list, numpy.ndarray)) + self.assertTrue(isinstance(x.number, numpy.ndarray)) + self.assertFalse(isinstance(x.number, list)) + self.assertEqual(x._number_list, [1]) + self.assertEqual(x.number, numpy.array([1])) + + def test2(self): + x = AdaptingVectorQuantity() + self.assertEqual(len(x), 0) + self.assertEqual(len(x.number), 0) + self.assertEqual(str(x), '[]') + x.append(1 * units.kg) + self.assertEqual(x.unit, units.kg) + self.assertEqual(len(x), 1) + self.assertEqual(str(x), '[1] kg') + x.append(2 * units.kg) + self.assertEqual(x.unit, units.kg) + self.assertEqual(len(x), 2) + self.assertEqual(str(x), '[1, 2] kg') + + def test3(self): + x = AdaptingVectorQuantity() + x.extend([1,2,3] * units.kg) + self.assertEqual(x.unit, units.kg) + self.assertEqual(len(x), 3) + self.assertEqual(x.number, numpy.array([1,2,3])) + + x.extend([1,2,3] * units.g) + self.assertEqual(x.unit, units.kg) + self.assertEqual(len(x), 6) + self.assertAlmostRelativeEquals(x, [1000,2000,3000,1,2,3] * units.g) + + def test4(self): + x = AdaptingVectorQuantity() + x.prepend(1 * units.kg) + self.assertEqual(x.unit, units.kg) + self.assertEqual(len(x), 1) + self.assertEqual(str(x), '[1] kg') + x.prepend(2 * units.kg) + self.assertEqual(x.unit, units.kg) + self.assertEqual(len(x), 2) + self.assertEqual(str(x), '[2, 1] kg') + + def test5(self): + # Everything mixed... + x = AdaptingVectorQuantity() + x.extend([3,4,5] * units.kg) + x.append(6 * units.kg) + x.prepend(2 * units.kg) + x.extend([7000,8000,9000] * units.g) + x.prepend(1000 * units.g) + x.append(10000 * units.g) + self.assertEqual(x.unit, units.kg) + self.assertEqual(len(x), 10) + self.assertEqual(x.number, numpy.array([1,2,3,4,5,6,7,8,9,10])) + self.assertEqual(x, [1,2,3,4,5,6,7,8,9,10]*units.kg) + + def test6(self): + x = 6 * units.kg + y = 5 * units.kg + self.assertEqual(x/y, 6/5) + self.assertEqual(x//y, 6//5) + self.assertEqual(operator.__truediv__(x,y), 1.2) + +class TestNumpyFunctionWithUnits(amusetest.TestCase): + + def test1(self): + array = quantities.arange(0 * units.kg, 10 * units.kg, 1 * units.kg) + self.assertEqual(len(array), 10) + self.assertAlmostRelativeEquals(array, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] * units.kg) + + + def test2(self): + array = quantities.linspace(0 * units.kg, 10 * units.kg, 11) + self.assertEqual(len(array), 11) + self.assertAlmostRelativeEquals(array, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] * units.kg) + + + def test3(self): + array = quantities.linspace(0 , 10 , 11) + self.assertEqual(len(array), 11) + self.assertAlmostRelativeEquals(array, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + + def test4(self): + x = quantities.arange(0 * units.yr, 10 * units.yr, 1 * units.yr) + y = (2.0*units.km) * (x/ (2.0*units.yr))**2 + (20.0*units.km) + + fit = quantities.polyfit(x, y, 2) + + self.assertEqual(len(fit), 3) + self.assertEqual(fit[0].unit, units.km/units.yr**2) + + fit_values = quantities.polyval(fit, x) + + self.assertEqual(fit_values.shape, x.shape) + self.assertEqual(y.unit, fit_values.unit) + + self.assertAlmostRelativeEquals(y, fit_values, 1) + + def test5(self): + a=[1,2,3] * units.m + b=[4,5,6] * units.m + + ab1=quantities.column_stack((a,b)) + ab2=quantities.column_stack((a.number,b.number)) * units.m + + self.assertEqual(ab1,ab2) + + diff --git a/src/amuse/units/constants.py b/src/amuse/units/constants.py index 9809b97f51..92489ab377 100644 --- a/src/amuse/units/constants.py +++ b/src/amuse/units/constants.py @@ -7,343 +7,343 @@ from amuse.units.derivedsi import * #BASE UNITS*********************************************** -X220X_lattice_spacing_of_silicon = 1.920155762e-10 | m -alpha_particle_mass = 6.6446562e-27 | kg -alpha_particle_mass_energy_equivalent = 5.97191917e-10 | J -Angstrom_star = 1.00001498e-10 | m -u = 1.660538782e-27 | kg -atomic_mass_constant_energy_equivalent = 1.49241783e-10 | J -atomic_mass_unit_hyphen_hertz_relationship = 2.2523427369e+23 | Hz -atomic_mass_unit_hyphen_joule_relationship = 1.49241783e-10 | J -atomic_mass_unit_hyphen_kelvin_relationship = 1.0809527e+13 | K -atomic_mass_unit_hyphen_kilogram_relationship = 1.660538782e-27 | kg -atomic_unit_of_charge = 1.602176487e-19 | C -atomic_unit_of_current = 0.00662361763 | A -atomic_unit_of_electric_potential = 27.21138386 | V -atomic_unit_of_energy = 4.35974394e-18 | J -atomic_unit_of_force = 8.23872206e-08 | N -atomic_unit_of_length = 5.2917720859e-11 | m -atomic_unit_of_mag_flux_density = 235051.7382 | T -atomic_unit_of_mass = 9.10938215e-31 | kg -atomic_unit_of_time = 2.4188843265e-17 | s -Bohr_radius = 5.2917720859e-11 | m -characteristic_impedance_of_vacuum = 376.730313461 | ohm -classical_electron_radius = 2.8179402894e-15 | m -Compton_wavelength = 2.4263102175e-12 | m -Compton_wavelength_over_2_pi = 3.8615926459e-13 | m -conductance_quantum = 7.7480917004e-05 | S -conventional_value_of_von_Klitzing_constant = 25812.807 | ohm -Cu_x_unit = 1.00207699e-13 | m -deuteron_mass = 3.3435832e-27 | kg -deuteron_mass_energy_equivalent = 3.00506272e-10 | J -deuteron_rms_charge_radius = 2.1402e-15 | m -electron_mass = 9.10938215e-31 | kg -electron_mass_energy_equivalent = 8.18710438e-14 | J -electron_volt = 1.602176487e-19 | J -electron_volt_hyphen_hertz_relationship = 2.417989454e+14 | Hz -electron_volt_hyphen_joule_relationship = 1.602176487e-19 | J -electron_volt_hyphen_kelvin_relationship = 11604.505 | K -electron_volt_hyphen_kilogram_relationship = 1.782661758e-36 | kg -elementary_charge = 1.602176487e-19 | C -Hartree_energy = 4.35974394e-18 | J -hartree_hyphen_hertz_relationship = 6.57968392072e+15 | Hz -hartree_hyphen_joule_relationship = 4.35974394e-18 | J -hartree_hyphen_kelvin_relationship = 315774.65 | K -hartree_hyphen_kilogram_relationship = 4.85086934e-35 | kg -helion_mass = 5.00641192e-27 | kg -helion_mass_energy_equivalent = 4.49953864e-10 | J -hertz_hyphen_joule_relationship = 6.62606896e-34 | J -hertz_hyphen_kelvin_relationship = 4.7992374e-11 | K -hertz_hyphen_kilogram_relationship = 7.372496e-51 | kg -inverse_meter_hyphen_hertz_relationship = 299792458.0 | Hz -inverse_meter_hyphen_joule_relationship = 1.986445501e-25 | J -inverse_meter_hyphen_kelvin_relationship = 0.014387752 | K -inverse_meter_hyphen_kilogram_relationship = 2.2102187e-42 | kg -inverse_of_conductance_quantum = 12906.4037787 | ohm -joule_hyphen_hertz_relationship = 1.50919045e+33 | Hz -joule_hyphen_kelvin_relationship = 7.242963e+22 | K -joule_hyphen_kilogram_relationship = 1.112650056e-17 | kg -kelvin_hyphen_hertz_relationship = 20836644000.0 | Hz -kelvin_hyphen_joule_relationship = 1.3806504e-23 | J -kelvin_hyphen_kilogram_relationship = 1.5361807e-40 | kg -kilogram_hyphen_hertz_relationship = 1.356392733e+50 | Hz -kilogram_hyphen_joule_relationship = 8.987551787e+16 | J -kilogram_hyphen_kelvin_relationship = 6.509651e+39 | K -lattice_parameter_of_silicon = 5.43102064e-10 | m -mag_flux_quantum = 2.067833667e-15 | Wb -Mo_x_unit = 1.00209955e-13 | m -muon_Compton_wavelength = 1.173444104e-14 | m -muon_Compton_wavelength_over_2_pi = 1.867594295e-15 | m -muon_mass = 1.8835313e-28 | kg -muon_mass_energy_equivalent = 1.69283351e-11 | J -natural_unit_of_energy = 8.18710438e-14 | J -natural_unit_of_length = 3.8615926459e-13 | m -natural_unit_of_mass = 9.10938215e-31 | kg -natural_unit_of_time = 1.288088657e-21 | s -neutron_Compton_wavelength = 1.3195908951e-15 | m -neutron_Compton_wavelength_over_2_pi = 2.1001941382e-16 | m -neutron_mass = 1.674927211e-27 | kg -neutron_mass_energy_equivalent = 1.505349505e-10 | J -Planck_length = 1.616252e-35 | m -Planck_mass = 2.17644e-08 | kg -Planck_temperature = 1.416785e+32 | K -Planck_time = 5.39124e-44 | s -proton_Compton_wavelength = 1.3214098446e-15 | m -proton_Compton_wavelength_over_2_pi = 2.1030890861e-16 | m -proton_mass = 1.672621637e-27 | kg -proton_mass_energy_equivalent = 1.503277359e-10 | J -proton_rms_charge_radius = 8.768e-16 | m -Rydberg_constant_times_c_in_Hz = 3.28984196036e+15 | Hz -Rydberg_constant_times_hc_in_J = 2.17987197e-18 | J -standard_atmosphere = 101325.0 | Pa -tau_Compton_wavelength = 6.9772e-16 | m -tau_Compton_wavelength_over_2_pi = 1.11046e-16 | m -tau_mass = 3.16777e-27 | kg -tau_mass_energy_equivalent = 2.84705e-10 | J -triton_mass = 5.00735588e-27 | kg -triton_mass_energy_equivalent = 4.50038703e-10 | J -unified_atomic_mass_unit = 1.660538782e-27 | kg -von_Klitzing_constant = 25812.807557 | ohm +X220X_lattice_spacing_of_silicon = 1.920155762e-10 * m +alpha_particle_mass = 6.6446562e-27 * kg +alpha_particle_mass_energy_equivalent = 5.97191917e-10 * J +Angstrom_star = 1.00001498e-10 * m +u = 1.660538782e-27 * kg +atomic_mass_constant_energy_equivalent = 1.49241783e-10 * J +atomic_mass_unit_hyphen_hertz_relationship = 2.2523427369e+23 * Hz +atomic_mass_unit_hyphen_joule_relationship = 1.49241783e-10 * J +atomic_mass_unit_hyphen_kelvin_relationship = 1.0809527e+13 * K +atomic_mass_unit_hyphen_kilogram_relationship = 1.660538782e-27 * kg +atomic_unit_of_charge = 1.602176487e-19 * C +atomic_unit_of_current = 0.00662361763 * A +atomic_unit_of_electric_potential = 27.21138386 * V +atomic_unit_of_energy = 4.35974394e-18 * J +atomic_unit_of_force = 8.23872206e-08 * N +atomic_unit_of_length = 5.2917720859e-11 * m +atomic_unit_of_mag_flux_density = 235051.7382 * T +atomic_unit_of_mass = 9.10938215e-31 * kg +atomic_unit_of_time = 2.4188843265e-17 * s +Bohr_radius = 5.2917720859e-11 * m +characteristic_impedance_of_vacuum = 376.730313461 * ohm +classical_electron_radius = 2.8179402894e-15 * m +Compton_wavelength = 2.4263102175e-12 * m +Compton_wavelength_over_2_pi = 3.8615926459e-13 * m +conductance_quantum = 7.7480917004e-05 * S +conventional_value_of_von_Klitzing_constant = 25812.807 * ohm +Cu_x_unit = 1.00207699e-13 * m +deuteron_mass = 3.3435832e-27 * kg +deuteron_mass_energy_equivalent = 3.00506272e-10 * J +deuteron_rms_charge_radius = 2.1402e-15 * m +electron_mass = 9.10938215e-31 * kg +electron_mass_energy_equivalent = 8.18710438e-14 * J +electron_volt = 1.602176487e-19 * J +electron_volt_hyphen_hertz_relationship = 2.417989454e+14 * Hz +electron_volt_hyphen_joule_relationship = 1.602176487e-19 * J +electron_volt_hyphen_kelvin_relationship = 11604.505 * K +electron_volt_hyphen_kilogram_relationship = 1.782661758e-36 * kg +elementary_charge = 1.602176487e-19 * C +Hartree_energy = 4.35974394e-18 * J +hartree_hyphen_hertz_relationship = 6.57968392072e+15 * Hz +hartree_hyphen_joule_relationship = 4.35974394e-18 * J +hartree_hyphen_kelvin_relationship = 315774.65 * K +hartree_hyphen_kilogram_relationship = 4.85086934e-35 * kg +helion_mass = 5.00641192e-27 * kg +helion_mass_energy_equivalent = 4.49953864e-10 * J +hertz_hyphen_joule_relationship = 6.62606896e-34 * J +hertz_hyphen_kelvin_relationship = 4.7992374e-11 * K +hertz_hyphen_kilogram_relationship = 7.372496e-51 * kg +inverse_meter_hyphen_hertz_relationship = 299792458.0 * Hz +inverse_meter_hyphen_joule_relationship = 1.986445501e-25 * J +inverse_meter_hyphen_kelvin_relationship = 0.014387752 * K +inverse_meter_hyphen_kilogram_relationship = 2.2102187e-42 * kg +inverse_of_conductance_quantum = 12906.4037787 * ohm +joule_hyphen_hertz_relationship = 1.50919045e+33 * Hz +joule_hyphen_kelvin_relationship = 7.242963e+22 * K +joule_hyphen_kilogram_relationship = 1.112650056e-17 * kg +kelvin_hyphen_hertz_relationship = 20836644000.0 * Hz +kelvin_hyphen_joule_relationship = 1.3806504e-23 * J +kelvin_hyphen_kilogram_relationship = 1.5361807e-40 * kg +kilogram_hyphen_hertz_relationship = 1.356392733e+50 * Hz +kilogram_hyphen_joule_relationship = 8.987551787e+16 * J +kilogram_hyphen_kelvin_relationship = 6.509651e+39 * K +lattice_parameter_of_silicon = 5.43102064e-10 * m +mag_flux_quantum = 2.067833667e-15 * Wb +Mo_x_unit = 1.00209955e-13 * m +muon_Compton_wavelength = 1.173444104e-14 * m +muon_Compton_wavelength_over_2_pi = 1.867594295e-15 * m +muon_mass = 1.8835313e-28 * kg +muon_mass_energy_equivalent = 1.69283351e-11 * J +natural_unit_of_energy = 8.18710438e-14 * J +natural_unit_of_length = 3.8615926459e-13 * m +natural_unit_of_mass = 9.10938215e-31 * kg +natural_unit_of_time = 1.288088657e-21 * s +neutron_Compton_wavelength = 1.3195908951e-15 * m +neutron_Compton_wavelength_over_2_pi = 2.1001941382e-16 * m +neutron_mass = 1.674927211e-27 * kg +neutron_mass_energy_equivalent = 1.505349505e-10 * J +Planck_length = 1.616252e-35 * m +Planck_mass = 2.17644e-08 * kg +Planck_temperature = 1.416785e+32 * K +Planck_time = 5.39124e-44 * s +proton_Compton_wavelength = 1.3214098446e-15 * m +proton_Compton_wavelength_over_2_pi = 2.1030890861e-16 * m +proton_mass = 1.672621637e-27 * kg +proton_mass_energy_equivalent = 1.503277359e-10 * J +proton_rms_charge_radius = 8.768e-16 * m +Rydberg_constant_times_c_in_Hz = 3.28984196036e+15 * Hz +Rydberg_constant_times_hc_in_J = 2.17987197e-18 * J +standard_atmosphere = 101325.0 * Pa +tau_Compton_wavelength = 6.9772e-16 * m +tau_Compton_wavelength_over_2_pi = 1.11046e-16 * m +tau_mass = 3.16777e-27 * kg +tau_mass_energy_equivalent = 2.84705e-10 * J +triton_mass = 5.00735588e-27 * kg +triton_mass_energy_equivalent = 4.50038703e-10 * J +unified_atomic_mass_unit = 1.660538782e-27 * kg +von_Klitzing_constant = 25812.807557 * ohm #DERIVED UNITS*********************************************** -alpha_particle_molar_mass = 0.00400150617913 | kg*mol**-1 -atomic_mass_unit_hyphen_inverse_meter_relationship = 7.513006671e+14 | m**-1 -atomic_unit_of_1st_hyperpolarizablity = 3.206361533e-53 | C**3*m**3*J**-2 -atomic_unit_of_2nd_hyperpolarizablity = 6.23538095e-65 | C**4*m**4*J**-3 -atomic_unit_of_action = 1.054571628e-34 | J*s -atomic_unit_of_charge_density = 1.0812023e+12 | C*m**-3 -atomic_unit_of_electric_dipole_mom = 8.47835281e-30 | C*m -atomic_unit_of_electric_field = 5.14220632e+11 | V*m**-1 -atomic_unit_of_electric_field_gradient = 9.71736166e+21 | V*m**-2 -atomic_unit_of_electric_polarizablity = 1.6487772536e-41 | C**2*m**2*J**-1 -atomic_unit_of_electric_quadrupole_mom = 4.48655107e-40 | C*m**2 -atomic_unit_of_mag_dipole_mom = 1.85480183e-23 | J*T**-1 -atomic_unit_of_magnetizability = 7.891036433e-29 | J*T**-2 -atomic_unit_of_momentum = 1.992851565e-24 | kg*m*s**-1 -atomic_unit_of_permittivity = 1.112650056e-10 | F*m**-1 -atomic_unit_of_velocity = 2187691.2541 | m*s**-1 -Avogadro_constant = 6.02214179e+23 | mol**-1 -Bohr_magneton = 9.27400915e-24 | J*T**-1 -Bohr_magneton_in_Hz_div_T = 13996246040.0 | Hz*T**-1 -Bohr_magneton_in_inverse_meters_per_tesla = 46.6864515 | m**-1*T**-1 -Bohr_magneton_in_K_div_T = 0.6717131 | K*T**-1 -kB = 1.3806504e-23 | J*K**-1 -Boltzmann_constant_in_Hz_div_K = 20836644000.0 | Hz*K**-1 -Boltzmann_constant_in_inverse_meters_per_kelvin = 69.50356 | m**-1*K**-1 -conventional_value_of_Josephson_constant = 4.835979e+14 | Hz*V**-1 -deuteron_mag_mom = 4.33073465e-27 | J*T**-1 -deuteron_molar_mass = 0.00201355321272 | kg*mol**-1 -electric_constant = 8.854187817e-12 | F*m**-1 -electron_charge_to_mass_quotient = -1.75882015e+11 | C*kg**-1 -electron_gyromag_ratio = 1.76085977e+11 | s**-1*T**-1 -electron_gyromag_ratio_over_2_pi = 28024.95364 | MHz*T**-1 -electron_mag_mom = -9.28476377e-24 | J*T**-1 -electron_molar_mass = 5.4857990943e-07 | kg*mol**-1 -electron_volt_hyphen_inverse_meter_relationship = 806554.465 | m**-1 -elementary_charge_over_h = 2.417989454e+14 | A*J**-1 -Faraday_constant = 96485.3399 | C*mol**-1 -first_radiation_constant = 3.74177118e-16 | W*m**2 -first_radiation_constant_for_spectral_radiance = 1.191042759e-16 | W*m**2*sr**-1 -hartree_hyphen_inverse_meter_relationship = 21947463.137 | m**-1 -helion_molar_mass = 0.0030149322473 | kg*mol**-1 -hertz_hyphen_inverse_meter_relationship = 3.335640951e-09 | m**-1 -Josephson_constant = 4.83597891e+14 | Hz*V**-1 -joule_hyphen_inverse_meter_relationship = 5.03411747e+24 | m**-1 -kelvin_hyphen_inverse_meter_relationship = 69.50356 | m**-1 -kilogram_hyphen_inverse_meter_relationship = 4.52443915e+41 | m**-1 -Loschmidt_constant_X27315_K_and__101325_kPaX = 2.6867774e+25 | m**-3 -mag_constant = 1.2566370614e-06 | N*A**-2 -molar_gas_constant = 8.314472 | J*mol**-1*K**-1 -molar_mass_constant = 0.001 | kg*mol**-1 -molar_mass_of_carbon_hyphen_12 = 0.012 | kg*mol**-1 -molar_Planck_constant = 3.9903126821e-10 | J*s*mol**-1 -molar_Planck_constant_times_c = 0.11962656472 | J*m*mol**-1 -molar_volume_of_ideal_gas_X27315_K_and__100_kPaX = 0.022710981 | m**3*mol**-1 -molar_volume_of_ideal_gas_X27315_K_and__101325_kPaX = 0.022413996 | m**3*mol**-1 -molar_volume_of_silicon = 1.20588349e-05 | m**3*mol**-1 -muon_mag_mom = -4.49044786e-26 | J*T**-1 -muon_molar_mass = 0.0001134289256 | kg*mol**-1 -natural_unit_of_action = 1.054571628e-34 | J*s -natural_unit_of_momentum = 2.73092406e-22 | kg*m*s**-1 -natural_unit_of_velocity = 299792458.0 | m*s**-1 -neutron_gyromag_ratio = 183247185.0 | s**-1*T**-1 -neutron_gyromag_ratio_over_2_pi = 29.1646954 | MHz*T**-1 -neutron_mag_mom = -9.6623641e-27 | J*T**-1 -neutron_molar_mass = 0.00100866491597 | kg*mol**-1 -G = 6.67428e-11 | m**3*kg**-1*s**-2 -nuclear_magneton = 5.05078324e-27 | J*T**-1 -nuclear_magneton_in_inverse_meters_per_tesla = 0.02542623616 | m**-1*T**-1 -nuclear_magneton_in_K_div_T = 0.00036582637 | K*T**-1 -nuclear_magneton_in_MHz_div_T = 7.62259384 | MHz*T**-1 -h = 6.62606896e-34 | J*s -Planck_constant_over_2_pi = 1.054571628e-34 | J*s -proton_charge_to_mass_quotient = 95788339.2 | C*kg**-1 -proton_gyromag_ratio = 267522209.9 | s**-1*T**-1 -proton_gyromag_ratio_over_2_pi = 42.5774821 | MHz*T**-1 -proton_mag_mom = 1.410606662e-26 | J*T**-1 -proton_molar_mass = 0.00100727646677 | kg*mol**-1 -quantum_of_circulation = 0.00036369475199 | m**2*s**-1 -quantum_of_circulation_times_2 = 0.000727389504 | m**2*s**-1 -Rydberg_constant = 10973731.5685 | m**-1 -second_radiation_constant = 0.014387752 | m*K -shielded_helion_gyromag_ratio = 203789473.0 | s**-1*T**-1 -shielded_helion_gyromag_ratio_over_2_pi = 32.43410198 | MHz*T**-1 -shielded_helion_mag_mom = -1.074552982e-26 | J*T**-1 -shielded_proton_gyromag_ratio = 267515336.2 | s**-1*T**-1 -shielded_proton_gyromag_ratio_over_2_pi = 42.5763881 | MHz*T**-1 -shielded_proton_mag_mom = 1.410570419e-26 | J*T**-1 -c = 299792458.0 | m*s**-1 -standard_acceleration_of_gravity = 9.80665 | m*s**-2 -Stefan_hyphen_Boltzmann_constant = 5.6704e-08 | W*m**-2*K**-4 -tau_molar_mass = 0.00190768 | kg*mol**-1 -Thomson_cross_section = 6.652458558e-29 | m**2 -triton_mag_mom = 1.504609361e-26 | J*T**-1 -triton_molar_mass = 0.0030155007134 | kg*mol**-1 -Wien_frequency_displacement_law_constant = 58789330000.0 | Hz*K**-1 -Wien_wavelength_displacement_law_constant = 0.0028977685 | m*K +alpha_particle_molar_mass = 0.00400150617913 * kg*mol**-1 +atomic_mass_unit_hyphen_inverse_meter_relationship = 7.513006671e+14 * m**-1 +atomic_unit_of_1st_hyperpolarizablity = 3.206361533e-53 * C**3*m**3*J**-2 +atomic_unit_of_2nd_hyperpolarizablity = 6.23538095e-65 * C**4*m**4*J**-3 +atomic_unit_of_action = 1.054571628e-34 * J*s +atomic_unit_of_charge_density = 1.0812023e+12 * C*m**-3 +atomic_unit_of_electric_dipole_mom = 8.47835281e-30 * C*m +atomic_unit_of_electric_field = 5.14220632e+11 * V*m**-1 +atomic_unit_of_electric_field_gradient = 9.71736166e+21 * V*m**-2 +atomic_unit_of_electric_polarizablity = 1.6487772536e-41 * C**2*m**2*J**-1 +atomic_unit_of_electric_quadrupole_mom = 4.48655107e-40 * C*m**2 +atomic_unit_of_mag_dipole_mom = 1.85480183e-23 * J*T**-1 +atomic_unit_of_magnetizability = 7.891036433e-29 * J*T**-2 +atomic_unit_of_momentum = 1.992851565e-24 * kg*m*s**-1 +atomic_unit_of_permittivity = 1.112650056e-10 * F*m**-1 +atomic_unit_of_velocity = 2187691.2541 * m*s**-1 +Avogadro_constant = 6.02214179e+23 * mol**-1 +Bohr_magneton = 9.27400915e-24 * J*T**-1 +Bohr_magneton_in_Hz_div_T = 13996246040.0 * Hz*T**-1 +Bohr_magneton_in_inverse_meters_per_tesla = 46.6864515 * m**-1*T**-1 +Bohr_magneton_in_K_div_T = 0.6717131 * K*T**-1 +kB = 1.3806504e-23 * J*K**-1 +Boltzmann_constant_in_Hz_div_K = 20836644000.0 * Hz*K**-1 +Boltzmann_constant_in_inverse_meters_per_kelvin = 69.50356 * m**-1*K**-1 +conventional_value_of_Josephson_constant = 4.835979e+14 * Hz*V**-1 +deuteron_mag_mom = 4.33073465e-27 * J*T**-1 +deuteron_molar_mass = 0.00201355321272 * kg*mol**-1 +electric_constant = 8.854187817e-12 * F*m**-1 +electron_charge_to_mass_quotient = -1.75882015e+11 * C*kg**-1 +electron_gyromag_ratio = 1.76085977e+11 * s**-1*T**-1 +electron_gyromag_ratio_over_2_pi = 28024.95364 * (MHz*T**-1) +electron_mag_mom = -9.28476377e-24 * J*T**-1 +electron_molar_mass = 5.4857990943e-07 * kg*mol**-1 +electron_volt_hyphen_inverse_meter_relationship = 806554.465 * m**-1 +elementary_charge_over_h = 2.417989454e+14 * A*J**-1 +Faraday_constant = 96485.3399 * C*mol**-1 +first_radiation_constant = 3.74177118e-16 * W*m**2 +first_radiation_constant_for_spectral_radiance = 1.191042759e-16 * W*m**2*sr**-1 +hartree_hyphen_inverse_meter_relationship = 21947463.137 * m**-1 +helion_molar_mass = 0.0030149322473 * kg*mol**-1 +hertz_hyphen_inverse_meter_relationship = 3.335640951e-09 * m**-1 +Josephson_constant = 4.83597891e+14 * Hz*V**-1 +joule_hyphen_inverse_meter_relationship = 5.03411747e+24 * m**-1 +kelvin_hyphen_inverse_meter_relationship = 69.50356 * m**-1 +kilogram_hyphen_inverse_meter_relationship = 4.52443915e+41 * m**-1 +Loschmidt_constant_X27315_K_and__101325_kPaX = 2.6867774e+25 * m**-3 +mag_constant = 1.2566370614e-06 * N*A**-2 +molar_gas_constant = 8.314472 * J*mol**-1*K**-1 +molar_mass_constant = 0.001 * kg*mol**-1 +molar_mass_of_carbon_hyphen_12 = 0.012 * kg*mol**-1 +molar_Planck_constant = 3.9903126821e-10 * J*s*mol**-1 +molar_Planck_constant_times_c = 0.11962656472 * J*m*mol**-1 +molar_volume_of_ideal_gas_X27315_K_and__100_kPaX = 0.022710981 * m**3*mol**-1 +molar_volume_of_ideal_gas_X27315_K_and__101325_kPaX = 0.022413996 * m**3*mol**-1 +molar_volume_of_silicon = 1.20588349e-05 * m**3*mol**-1 +muon_mag_mom = -4.49044786e-26 * J*T**-1 +muon_molar_mass = 0.0001134289256 * kg*mol**-1 +natural_unit_of_action = 1.054571628e-34 * J*s +natural_unit_of_momentum = 2.73092406e-22 * kg*m*s**-1 +natural_unit_of_velocity = 299792458.0 * m*s**-1 +neutron_gyromag_ratio = 183247185.0 * s**-1*T**-1 +neutron_gyromag_ratio_over_2_pi = 29.1646954 * (MHz*T**-1) +neutron_mag_mom = -9.6623641e-27 * J*T**-1 +neutron_molar_mass = 0.00100866491597 * kg*mol**-1 +G = 6.67428e-11 * m**3*kg**-1*s**-2 +nuclear_magneton = 5.05078324e-27 * J*T**-1 +nuclear_magneton_in_inverse_meters_per_tesla = 0.02542623616 * m**-1*T**-1 +nuclear_magneton_in_K_div_T = 0.00036582637 * K*T**-1 +nuclear_magneton_in_MHz_div_T = 7.62259384 * (MHz*T**-1) +h = 6.62606896e-34 * (J*s) +Planck_constant_over_2_pi = 1.054571628e-34 * J*s +proton_charge_to_mass_quotient = 95788339.2 * C*kg**-1 +proton_gyromag_ratio = 267522209.9 * s**-1*T**-1 +proton_gyromag_ratio_over_2_pi = 42.5774821 * (MHz*T**-1) +proton_mag_mom = 1.410606662e-26 * J*T**-1 +proton_molar_mass = 0.00100727646677 * kg*mol**-1 +quantum_of_circulation = 0.00036369475199 * m**2*s**-1 +quantum_of_circulation_times_2 = 0.000727389504 * m**2*s**-1 +Rydberg_constant = 10973731.5685 * m**-1 +second_radiation_constant = 0.014387752 * m*K +shielded_helion_gyromag_ratio = 203789473.0 * s**-1*T**-1 +shielded_helion_gyromag_ratio_over_2_pi = 32.43410198 * (MHz*T**-1) +shielded_helion_mag_mom = -1.074552982e-26 * J*T**-1 +shielded_proton_gyromag_ratio = 267515336.2 * s**-1*T**-1 +shielded_proton_gyromag_ratio_over_2_pi = 42.5763881 * (MHz*T**-1) +shielded_proton_mag_mom = 1.410570419e-26 * J*T**-1 +c = 299792458.0 * (m*s**-1) +standard_acceleration_of_gravity = 9.80665 * m*s**-2 +Stefan_hyphen_Boltzmann_constant = 5.6704e-08 * (W*m**-2*K**-4) +tau_molar_mass = 0.00190768 * kg*mol**-1 +Thomson_cross_section = 6.652458558e-29 * m**2 +triton_mag_mom = 1.504609361e-26 * J*T**-1 +triton_molar_mass = 0.0030155007134 * kg*mol**-1 +Wien_frequency_displacement_law_constant = 58789330000.0 * Hz*K**-1 +Wien_wavelength_displacement_law_constant = 0.0028977685 * m*K #RATIOS *********************************************** -alpha_particle_hyphen_electron_mass_ratio = 7294.2995365 | none -alpha_particle_hyphen_proton_mass_ratio = 3.97259968951 | none -deuteron_hyphen_electron_mag_mom_ratio = -0.0004664345537 | none -deuteron_hyphen_electron_mass_ratio = 3670.4829654 | none -deuteron_g_factor = 0.8574382308 | none -deuteron_mag_mom_to_Bohr_magneton_ratio = 0.0004669754556 | none -deuteron_mag_mom_to_nuclear_magneton_ratio = 0.8574382308 | none -deuteron_hyphen_neutron_mag_mom_ratio = -0.44820652 | none -deuteron_hyphen_proton_mag_mom_ratio = 0.307012207 | none -deuteron_hyphen_proton_mass_ratio = 1.99900750108 | none -electron_hyphen_deuteron_mag_mom_ratio = -2143.923498 | none -electron_hyphen_deuteron_mass_ratio = 0.00027244371093 | none -electron_g_factor = -2.00231930436 | none -electron_mag_mom_anomaly = 0.00115965218111 | none -electron_mag_mom_to_Bohr_magneton_ratio = -1.00115965218 | none -electron_mag_mom_to_nuclear_magneton_ratio = -1838.28197092 | none -electron_hyphen_muon_mag_mom_ratio = 206.7669877 | none -electron_hyphen_muon_mass_ratio = 0.00483633171 | none -electron_hyphen_neutron_mag_mom_ratio = 960.9205 | none -electron_hyphen_neutron_mass_ratio = 0.00054386734459 | none -electron_hyphen_proton_mag_mom_ratio = -658.2106848 | none -electron_hyphen_proton_mass_ratio = 0.00054461702177 | none -electron_hyphen_tau_mass_ratio = 0.000287564 | none -electron_to_alpha_particle_mass_ratio = 0.00013709335557 | none -electron_to_shielded_helion_mag_mom_ratio = 864.058257 | none -electron_to_shielded_proton_mag_mom_ratio = -658.2275971 | none -fine_hyphen_structure_constant = 0.0072973525376 | none -helion_hyphen_electron_mass_ratio = 5495.8852765 | none -helion_hyphen_proton_mass_ratio = 2.9931526713 | none -inverse_fine_hyphen_structure_constant = 137.035999679 | none -muon_hyphen_electron_mass_ratio = 206.7682823 | none -muon_g_factor = -2.0023318414 | none -muon_mag_mom_anomaly = 0.00116592069 | none -muon_mag_mom_to_Bohr_magneton_ratio = -0.00484197049 | none -muon_mag_mom_to_nuclear_magneton_ratio = -8.89059705 | none -muon_hyphen_neutron_mass_ratio = 0.1124545167 | none -muon_hyphen_proton_mag_mom_ratio = -3.183345137 | none -muon_hyphen_proton_mass_ratio = 0.1126095261 | none -muon_hyphen_tau_mass_ratio = 0.0594592 | none -neutron_hyphen_electron_mag_mom_ratio = 0.00104066882 | none -neutron_hyphen_electron_mass_ratio = 1838.6836605 | none -neutron_g_factor = -3.82608545 | none -neutron_mag_mom_to_Bohr_magneton_ratio = -0.00104187563 | none -neutron_mag_mom_to_nuclear_magneton_ratio = -1.91304273 | none -neutron_hyphen_muon_mass_ratio = 8.89248409 | none -neutron_hyphen_proton_mag_mom_ratio = -0.68497934 | none -neutron_hyphen_proton_mass_ratio = 1.00137841918 | none -neutron_hyphen_tau_mass_ratio = 0.52874 | none -neutron_to_shielded_proton_mag_mom_ratio = -0.68499694 | none -proton_hyphen_electron_mass_ratio = 1836.15267247 | none -proton_g_factor = 5.585694713 | none -proton_mag_mom_to_Bohr_magneton_ratio = 0.001521032209 | none -proton_mag_mom_to_nuclear_magneton_ratio = 2.792847356 | none -proton_mag_shielding_correction = 2.5694e-05 | none -proton_hyphen_muon_mass_ratio = 8.88024339 | none -proton_hyphen_neutron_mag_mom_ratio = -1.45989806 | none -proton_hyphen_neutron_mass_ratio = 0.99862347824 | none -proton_hyphen_tau_mass_ratio = 0.528012 | none -Sackur_hyphen_Tetrode_constant_X1_K_and__100_kPaX = -1.1517047 | none -Sackur_hyphen_Tetrode_constant_X1_K_and__101325_kPaX = -1.1648677 | none -shielded_helion_mag_mom_to_Bohr_magneton_ratio = -0.001158671471 | none -shielded_helion_mag_mom_to_nuclear_magneton_ratio = -2.127497718 | none -shielded_helion_to_proton_mag_mom_ratio = -0.761766558 | none -shielded_helion_to_shielded_proton_mag_mom_ratio = -0.7617861313 | none -shielded_proton_mag_mom_to_Bohr_magneton_ratio = 0.001520993128 | none -shielded_proton_mag_mom_to_nuclear_magneton_ratio = 2.792775598 | none -tau_hyphen_electron_mass_ratio = 3477.48 | none -tau_hyphen_muon_mass_ratio = 16.8183 | none -tau_hyphen_neutron_mass_ratio = 1.89129 | none -tau_hyphen_proton_mass_ratio = 1.8939 | none -triton_hyphen_electron_mag_mom_ratio = -0.001620514423 | none -triton_hyphen_electron_mass_ratio = 5496.9215269 | none -triton_g_factor = 5.957924896 | none -triton_mag_mom_to_Bohr_magneton_ratio = 0.001622393657 | none -triton_mag_mom_to_nuclear_magneton_ratio = 2.978962448 | none -triton_hyphen_neutron_mag_mom_ratio = -1.55718553 | none -triton_hyphen_proton_mag_mom_ratio = 1.066639908 | none -triton_hyphen_proton_mass_ratio = 2.9937170309 | none -weak_mixing_angle = 0.22255 | none +alpha_particle_hyphen_electron_mass_ratio = 7294.2995365 * none +alpha_particle_hyphen_proton_mass_ratio = 3.97259968951 * none +deuteron_hyphen_electron_mag_mom_ratio = -0.0004664345537 * none +deuteron_hyphen_electron_mass_ratio = 3670.4829654 * none +deuteron_g_factor = 0.8574382308 * none +deuteron_mag_mom_to_Bohr_magneton_ratio = 0.0004669754556 * none +deuteron_mag_mom_to_nuclear_magneton_ratio = 0.8574382308 * none +deuteron_hyphen_neutron_mag_mom_ratio = -0.44820652 * none +deuteron_hyphen_proton_mag_mom_ratio = 0.307012207 * none +deuteron_hyphen_proton_mass_ratio = 1.99900750108 * none +electron_hyphen_deuteron_mag_mom_ratio = -2143.923498 * none +electron_hyphen_deuteron_mass_ratio = 0.00027244371093 * none +electron_g_factor = -2.00231930436 * none +electron_mag_mom_anomaly = 0.00115965218111 * none +electron_mag_mom_to_Bohr_magneton_ratio = -1.00115965218 * none +electron_mag_mom_to_nuclear_magneton_ratio = -1838.28197092 * none +electron_hyphen_muon_mag_mom_ratio = 206.7669877 * none +electron_hyphen_muon_mass_ratio = 0.00483633171 * none +electron_hyphen_neutron_mag_mom_ratio = 960.9205 * none +electron_hyphen_neutron_mass_ratio = 0.00054386734459 * none +electron_hyphen_proton_mag_mom_ratio = -658.2106848 * none +electron_hyphen_proton_mass_ratio = 0.00054461702177 * none +electron_hyphen_tau_mass_ratio = 0.000287564 * none +electron_to_alpha_particle_mass_ratio = 0.00013709335557 * none +electron_to_shielded_helion_mag_mom_ratio = 864.058257 * none +electron_to_shielded_proton_mag_mom_ratio = -658.2275971 * none +fine_hyphen_structure_constant = 0.0072973525376 * none +helion_hyphen_electron_mass_ratio = 5495.8852765 * none +helion_hyphen_proton_mass_ratio = 2.9931526713 * none +inverse_fine_hyphen_structure_constant = 137.035999679 * none +muon_hyphen_electron_mass_ratio = 206.7682823 * none +muon_g_factor = -2.0023318414 * none +muon_mag_mom_anomaly = 0.00116592069 * none +muon_mag_mom_to_Bohr_magneton_ratio = -0.00484197049 * none +muon_mag_mom_to_nuclear_magneton_ratio = -8.89059705 * none +muon_hyphen_neutron_mass_ratio = 0.1124545167 * none +muon_hyphen_proton_mag_mom_ratio = -3.183345137 * none +muon_hyphen_proton_mass_ratio = 0.1126095261 * none +muon_hyphen_tau_mass_ratio = 0.0594592 * none +neutron_hyphen_electron_mag_mom_ratio = 0.00104066882 * none +neutron_hyphen_electron_mass_ratio = 1838.6836605 * none +neutron_g_factor = -3.82608545 * none +neutron_mag_mom_to_Bohr_magneton_ratio = -0.00104187563 * none +neutron_mag_mom_to_nuclear_magneton_ratio = -1.91304273 * none +neutron_hyphen_muon_mass_ratio = 8.89248409 * none +neutron_hyphen_proton_mag_mom_ratio = -0.68497934 * none +neutron_hyphen_proton_mass_ratio = 1.00137841918 * none +neutron_hyphen_tau_mass_ratio = 0.52874 * none +neutron_to_shielded_proton_mag_mom_ratio = -0.68499694 * none +proton_hyphen_electron_mass_ratio = 1836.15267247 * none +proton_g_factor = 5.585694713 * none +proton_mag_mom_to_Bohr_magneton_ratio = 0.001521032209 * none +proton_mag_mom_to_nuclear_magneton_ratio = 2.792847356 * none +proton_mag_shielding_correction = 2.5694e-05 * none +proton_hyphen_muon_mass_ratio = 8.88024339 * none +proton_hyphen_neutron_mag_mom_ratio = -1.45989806 * none +proton_hyphen_neutron_mass_ratio = 0.99862347824 * none +proton_hyphen_tau_mass_ratio = 0.528012 * none +Sackur_hyphen_Tetrode_constant_X1_K_and__100_kPaX = -1.1517047 * none +Sackur_hyphen_Tetrode_constant_X1_K_and__101325_kPaX = -1.1648677 * none +shielded_helion_mag_mom_to_Bohr_magneton_ratio = -0.001158671471 * none +shielded_helion_mag_mom_to_nuclear_magneton_ratio = -2.127497718 * none +shielded_helion_to_proton_mag_mom_ratio = -0.761766558 * none +shielded_helion_to_shielded_proton_mag_mom_ratio = -0.7617861313 * none +shielded_proton_mag_mom_to_Bohr_magneton_ratio = 0.001520993128 * none +shielded_proton_mag_mom_to_nuclear_magneton_ratio = 2.792775598 * none +tau_hyphen_electron_mass_ratio = 3477.48 * none +tau_hyphen_muon_mass_ratio = 16.8183 * none +tau_hyphen_neutron_mass_ratio = 1.89129 * none +tau_hyphen_proton_mass_ratio = 1.8939 * none +triton_hyphen_electron_mag_mom_ratio = -0.001620514423 * none +triton_hyphen_electron_mass_ratio = 5496.9215269 * none +triton_g_factor = 5.957924896 * none +triton_mag_mom_to_Bohr_magneton_ratio = 0.001622393657 * none +triton_mag_mom_to_nuclear_magneton_ratio = 2.978962448 * none +triton_hyphen_neutron_mag_mom_ratio = -1.55718553 * none +triton_hyphen_proton_mag_mom_ratio = 1.066639908 * none +triton_hyphen_proton_mass_ratio = 2.9937170309 * none +weak_mixing_angle = 0.22255 * none #DERIVED CONSTANTS*********************************************** pi = numpy.pi hbar = h / (2.0 * numpy.pi) four_pi_stefan_boltzmann = 4.0 * numpy.pi * Stefan_hyphen_Boltzmann_constant -mu0 = 4 * numpy.pi * 1.e-7 | N/A**2 +mu0 = 4 * numpy.pi * 1.e-7 * N/A**2 eps0 = mu0**-1 * c**-2 -sidereal_day = 86164.100352 | s +sidereal_day = 86164.100352 * s #machine constants eps = numpy.finfo(numpy.double).eps precision = int(numpy.log10(2/eps)) #DROPPED UNITS*********************************************** -"""alpha_particle_mass_energy_equivalent_in_MeV = 3727.379109 | MeV -alpha_particle_mass_in_u = 4.00150617913 | u -atomic_mass_constant_energy_equivalent_in_MeV = 931.494028 | MeV -atomic_mass_unit_hyphen_electron_volt_relationship = 931494028.0 | eV -atomic_mass_unit_hyphen_hartree_relationship = 34231777.149 | E_h -Bohr_magneton_in_eV_div_T = 5.7883817555e-05 | eV*T**-1 -kBeV = 8.617343e-05 | eV*K**-1 -deuteron_mass_energy_equivalent_in_MeV = 1875.612793 | MeV -deuteron_mass_in_u = 2.01355321272 | u -electron_mass_energy_equivalent_in_MeV = 0.51099891 | MeV -electron_mass_in_u = 0.00054857990943 | u -electron_volt_hyphen_atomic_mass_unit_relationship = 1.073544188e-09 | u -electron_volt_hyphen_hartree_relationship = 0.0367493254 | E_h -Faraday_constant_for_conventional_electric_current = 96485.3401 | C_90*mol**-1 -Fermi_coupling_constant = 1.16637e-05 | GeV**-2 -hartree_hyphen_atomic_mass_unit_relationship = 2.9212622986e-08 | u -hartree_hyphen_electron_volt_relationship = 27.21138386 | eV -Hartree_energy_in_eV = 27.21138386 | eV -helion_mass_energy_equivalent_in_MeV = 2808.391383 | MeV -helion_mass_in_u = 3.0149322473 | u -hertz_hyphen_atomic_mass_unit_relationship = 4.4398216294e-24 | u -hertz_hyphen_electron_volt_relationship = 4.13566733e-15 | eV -hertz_hyphen_hartree_relationship = 1.51982984601e-16 | E_h -inverse_meter_hyphen_atomic_mass_unit_relationship = 1.3310250394e-15 | u -inverse_meter_hyphen_electron_volt_relationship = 1.239841875e-06 | eV -inverse_meter_hyphen_hartree_relationship = 4.55633525276e-08 | E_h -joule_hyphen_atomic_mass_unit_relationship = 6700536410.0 | u -joule_hyphen_electron_volt_relationship = 6.24150965e+18 | eV -joule_hyphen_hartree_relationship = 2.29371269e+17 | E_h -kelvin_hyphen_atomic_mass_unit_relationship = 9.251098e-14 | u -kelvin_hyphen_electron_volt_relationship = 8.617343e-05 | eV -kelvin_hyphen_hartree_relationship = 3.1668153e-06 | E_h -kilogram_hyphen_atomic_mass_unit_relationship = 6.02214179e+26 | u -kilogram_hyphen_electron_volt_relationship = 5.60958912e+35 | eV -kilogram_hyphen_hartree_relationship = 2.06148616e+34 | E_h -muon_mass_energy_equivalent_in_MeV = 105.6583668 | MeV -muon_mass_in_u = 0.1134289256 | u -natural_unit_of_action_in_eV_s = 6.58211899e-16 | eV*s -natural_unit_of_energy_in_MeV = 0.51099891 | MeV -natural_unit_of_momentum_in_MeV_div_c = 0.51099891 | MeV/c -neutron_mass_energy_equivalent_in_MeV = 939.565346 | MeV -neutron_mass_in_u = 1.00866491597 | u -Newtonian_constant_of_gravitation_over_h_hyphen_bar_c = 6.70881e-39 | (GeV/c**2)**-2 -nuclear_magneton_in_eV_div_T = 3.1524512326e-08 | eV*T**-1 -heV = 4.13566733e-15 | eV*s -Planck_constant_over_2_pi_in_eV_s = 6.58211899e-16 | eV*s -Planck_constant_over_2_pi_times_c_in_MeV_fm = 197.3269631 | MeV*fm -Planck_mass_energy_equivalent_in_GeV = 1.220892e+19 | GeV -proton_mass_energy_equivalent_in_MeV = 938.272013 | MeV -proton_mass_in_u = 1.00727646677 | u -Rydberg_constant_times_hc_in_eV = 13.60569193 | eV -tau_mass_energy_equivalent_in_MeV = 1776.99 | MeV -tau_mass_in_u = 1.90768 | u -triton_mass_energy_equivalent_in_MeV = 2808.920906 | MeV -triton_mass_in_u = 3.0155007134 | u +"""alpha_particle_mass_energy_equivalent_in_MeV = 3727.379109 * MeV +alpha_particle_mass_in_u = 4.00150617913 * u +atomic_mass_constant_energy_equivalent_in_MeV = 931.494028 * MeV +atomic_mass_unit_hyphen_electron_volt_relationship = 931494028.0 * eV +atomic_mass_unit_hyphen_hartree_relationship = 34231777.149 * E_h +Bohr_magneton_in_eV_div_T = 5.7883817555e-05 * eV*T**-1 +kBeV = 8.617343e-05 * eV*K**-1 +deuteron_mass_energy_equivalent_in_MeV = 1875.612793 * MeV +deuteron_mass_in_u = 2.01355321272 * u +electron_mass_energy_equivalent_in_MeV = 0.51099891 * MeV +electron_mass_in_u = 0.00054857990943 * u +electron_volt_hyphen_atomic_mass_unit_relationship = 1.073544188e-09 * u +electron_volt_hyphen_hartree_relationship = 0.0367493254 * E_h +Faraday_constant_for_conventional_electric_current = 96485.3401 * C_90*mol**-1 +Fermi_coupling_constant = 1.16637e-05 * GeV**-2 +hartree_hyphen_atomic_mass_unit_relationship = 2.9212622986e-08 * u +hartree_hyphen_electron_volt_relationship = 27.21138386 * eV +Hartree_energy_in_eV = 27.21138386 * eV +helion_mass_energy_equivalent_in_MeV = 2808.391383 * MeV +helion_mass_in_u = 3.0149322473 * u +hertz_hyphen_atomic_mass_unit_relationship = 4.4398216294e-24 * u +hertz_hyphen_electron_volt_relationship = 4.13566733e-15 * eV +hertz_hyphen_hartree_relationship = 1.51982984601e-16 * E_h +inverse_meter_hyphen_atomic_mass_unit_relationship = 1.3310250394e-15 * u +inverse_meter_hyphen_electron_volt_relationship = 1.239841875e-06 * eV +inverse_meter_hyphen_hartree_relationship = 4.55633525276e-08 * E_h +joule_hyphen_atomic_mass_unit_relationship = 6700536410.0 * u +joule_hyphen_electron_volt_relationship = 6.24150965e+18 * eV +joule_hyphen_hartree_relationship = 2.29371269e+17 * E_h +kelvin_hyphen_atomic_mass_unit_relationship = 9.251098e-14 * u +kelvin_hyphen_electron_volt_relationship = 8.617343e-05 * eV +kelvin_hyphen_hartree_relationship = 3.1668153e-06 * E_h +kilogram_hyphen_atomic_mass_unit_relationship = 6.02214179e+26 * u +kilogram_hyphen_electron_volt_relationship = 5.60958912e+35 * eV +kilogram_hyphen_hartree_relationship = 2.06148616e+34 * E_h +muon_mass_energy_equivalent_in_MeV = 105.6583668 * MeV +muon_mass_in_u = 0.1134289256 * u +natural_unit_of_action_in_eV_s = 6.58211899e-16 * eV*s +natural_unit_of_energy_in_MeV = 0.51099891 * MeV +natural_unit_of_momentum_in_MeV_div_c = 0.51099891 * MeV/c +neutron_mass_energy_equivalent_in_MeV = 939.565346 * MeV +neutron_mass_in_u = 1.00866491597 * u +Newtonian_constant_of_gravitation_over_h_hyphen_bar_c = 6.70881e-39 * (GeV/c**2)**-2 +nuclear_magneton_in_eV_div_T = 3.1524512326e-08 * eV*T**-1 +heV = 4.13566733e-15 * eV*s +Planck_constant_over_2_pi_in_eV_s = 6.58211899e-16 * eV*s +Planck_constant_over_2_pi_times_c_in_MeV_fm = 197.3269631 * MeV*fm +Planck_mass_energy_equivalent_in_GeV = 1.220892e+19 * GeV +proton_mass_energy_equivalent_in_MeV = 938.272013 * MeV +proton_mass_in_u = 1.00727646677 * u +Rydberg_constant_times_hc_in_eV = 13.60569193 * eV +tau_mass_energy_equivalent_in_MeV = 1776.99 * MeV +tau_mass_in_u = 1.90768 * u +triton_mass_energy_equivalent_in_MeV = 2808.920906 * MeV +triton_mass_in_u = 3.0155007134 * u """ diff --git a/src/amuse/units/core.py b/src/amuse/units/core.py index 9ec1aa6ac7..56901fdc98 100644 --- a/src/amuse/units/core.py +++ b/src/amuse/units/core.py @@ -7,6 +7,7 @@ from amuse.support.core import MultitonMetaClass + class system(object): ALL = {} @@ -38,11 +39,9 @@ def get(cls, name): from amuse.units import si return cls.ALL[name] - def __reduce__(self): return (get_system_with_name, (self.name,)) - def __str__(self): return self.name @@ -50,16 +49,16 @@ def __str__(self): class unit(object): """ Abstract base class for unit objects. - + Two classes of units are defined: base units The base units in a given system of units. For SI, these - are meter, kilogram, second, ampere, kelvin, mole and + are meter, kilogram, second, ampere, kelvin, mole and candele. See the si module :mod:`amuse.units.si` derived units Derived units are created by dividing or multiplying - with a number or with another unit. For example, + with a number or with another unit. For example, to get a velocity unit we can devine vel = 1000 * m / s Units can also be named, by creating a named unit. @@ -71,40 +70,42 @@ def __mul__(self, other): if isinstance(other, unit): return mul_unit(self, other) else: - return other*self + return self.new_quantity(other) + # return other*self # return factor_unit(other, self) def __truediv__(self, other): if isinstance(other, unit): return div_unit(self, other) else: - return (1.0/other)*self + return self.new_quantity(1.0/other) + # return (1.0/other)*self # return factor_unit(1.0 / other, self) def __rmul__(self, other): - if other == 1: - return self - else: - return factor_unit(other, self) + if isinstance(other, unit): + return mul_unit(other, self) + return self.new_quantity(other) def __ror__(self, value): """Create a new Quantity object. - - :argument value: numeric value of the quantity, can be + + :argument value: numeric value of the quantity, can be a number or a sequence (list or ndarray) - :returns: new ScalarQuantity or VectorQuantity object + :returns: new ScalarQuantity or VectorQuantity object with this unit - + Examples - + >>> from amuse.units import units - >>> 100 | units.kg + >>> 100 * units.kg quantity<100 kg> """ return self.new_quantity(value) def __rtruediv__(self, other): - return factor_unit(other, pow_unit(-1,self)) + # return factor_unit(other, pow_unit(-1, self)) + return pow_unit(-1, self).new_quantity(other) def __div__(self, other): return self.__truediv__(other) @@ -129,11 +130,18 @@ def __eq__(self, other): else: return False - def __ne__(self, other): if isinstance(other, unit): - if (isinstance(self, base_unit) and isinstance(other, base_unit)) or \ - isinstance(self, nonnumeric_unit) or isinstance(other, nonnumeric_unit): + if ( + ( + isinstance(self, base_unit) + and isinstance(other, base_unit) + ) + or ( + isinstance(self, nonnumeric_unit) + or isinstance(other, nonnumeric_unit) + ) + ): return NotImplemented return self.base != other.base and self.factor != other.factor else: @@ -167,9 +175,9 @@ def iskey(self): def new_quantity(self, value): """Create a new Quantity object. - :argument value: numeric value of the quantity, can be + :argument value: numeric value of the quantity, can be a number or a sequence (list or ndarray) - :returns: new ScalarQuantity or VectorQuantity object + :returns: new ScalarQuantity or VectorQuantity object with this unit """ from amuse.units import quantities @@ -177,9 +185,9 @@ def new_quantity(self, value): def to_simple_form(self): """Convert unit to a form with only one factor and powers - + :result: Unit with only a factor and power terms - + >>> from amuse.units import units >>> N = (units.m * units.kg) / (units.s * units.s) >>> N @@ -207,7 +215,7 @@ def to_simple_form(self): return result def to_reduced_form(self): - """Convert unit to a reduced (simpler) form + """Convert unit to a reduced (simpler) form """ if not self.base: @@ -229,10 +237,8 @@ def to_reduced_form(self): else: return factor_unit(total_factor , combined_unit) - - def to_factor_and_reduced_form(self): - """Convert unit to a reduced (simpler) form + """Convert unit to a reduced (simpler) form """ if not self.base: @@ -297,36 +303,38 @@ def conversion_factor_from(self, x): elif self._compare_bases(x): this_factor = self.factor * 1.0 other_factor = x.factor - return 1*(this_factor == other_factor) or this_factor / other_factor + return ( + 1*(this_factor == other_factor) + or this_factor / other_factor + ) else: raise IncompatibleUnitsException(x, self) - def in_(self, x): """Express this quantity in the given unit - + :argument unit: The unit to express this quantity in :result: A Quantity object - + Examples >>> from amuse.units import units - >>> l = 1 | units.AU + >>> l = 1 * units.AU >>> l.in_(units.km) quantity<149597870.691 km> - + """ return self.as_quantity_in(x) def as_quantity_in(self, unit): """Express this unit as a quantity in the given unit - + :argument unit: The unit to express this unit in :result: A Quantity object - + Examples - + >>> from amuse.units import units >>> ton = 1000 * units.kg >>> ton.as_quantity_in(units.kg) @@ -334,7 +342,9 @@ def as_quantity_in(self, unit): """ from amuse.units import quantities if isinstance(unit, quantities.Quantity): - raise exceptions.AmuseException("Cannot expres a unit in a quantity") + raise exceptions.AmuseException( + "Cannot expres a unit in a quantity" + ) factor = self.conversion_factor_from(unit) return quantities.new_quantity(factor, unit) @@ -344,17 +354,17 @@ def value_in(self, unit): Return a numeric value of this unit in the given unit. Works only when the units are compatible, i.e. from tonnage to kg's. - + A number is returned without any unit information. - + :argument unit: wanted unit of the value :returns: number in the given unit - + >>> from amuse.units import units >>> x = units.km >>> x.value_in(units.m) 1000.0 - + """ return self.conversion_factor_from(unit) @@ -377,8 +387,12 @@ def combine_bases(self, base1, base2): if sub1[1] == sub2[1]: result.append((sub1[0], sub2[0], sub1[1])) else: - raise exceptions.AmuseException("Cannot combine units from " - "different systems: {0} and {1}".format(sub1[1], sub2[1])) + raise exceptions.AmuseException( + "Cannot combine units from " + "different systems: {0} and {1}".format( + sub1[1], sub2[1] + ) + ) else: result.append((sub1[0], 0, sub1[1])) elif not sub2 is None: @@ -388,10 +402,10 @@ def combine_bases(self, base1, base2): def has_same_base_as(self, other): """Determine if the base of other is the same as the base of self. - + :argument other: unit to compare base to :result: True, if bases are compatiple. - + >>> from amuse.units import units >>> mps = units.m / units.s >>> kph = units.km / units.hour @@ -399,7 +413,7 @@ def has_same_base_as(self, other): True >>> mps.has_same_base_as(units.km) False - + """ return other.base == self.base @@ -410,9 +424,9 @@ def base_unit(self): unit = 1 for n, base in self.base: if n == 1: - unit = unit*base + unit = unit*base else: - unit = unit*(base ** n) + unit = unit*(base ** n) return unit def is_non_numeric(self): @@ -439,10 +453,10 @@ def convert_argument_value(self, method, definition, value): def append_result_value(self, method, definition, value, result): result.append(self.convert_result_value(method, definition, value)) - def to_array_of_floats(self): - """Represent a unit as an array of 8 64-bit floats. First float represents the factor, the other 7 the power of each base unit. - Cannot be used for non numeric units + """Represent a unit as an array of 8 64-bit floats. + First float represents the factor, the other 7 the power of each base + unit. Cannot be used for non numeric units """ result = numpy.zeros(9, dtype=numpy.float64) if not self.base: @@ -473,20 +487,25 @@ def describe_array_of_floats(self): parts[1] = str(base.system) return ', '.join(parts) + def as_unit(self): + return self + + def to_unit(self): + return self class base_unit(unit): """ - base_unit objects are orthogonal, indivisable units + base_unit objects are orthogonal, indivisable units of a sytem of units. - + A system of units contains a set of base units - + :argument quantity: name of the base quantity, for example *length* :argument name: name of the unit, for example *meter* :argument symbol: symbol of the unit, for example *m* :argument system: system of units object - + >>> cgs = system("cgs") >>> cm = base_unit("length", "centimetre", "cm", cgs) >>> cm @@ -509,7 +528,7 @@ def __hash__(self): def factor(self): """ The multiplication factor of a unit. - For example, factor is 1000 for km. + For example, factor is 1000 for km. """ return 1 @@ -522,13 +541,13 @@ def base(self): return ((1,self),) def reference_string(self): - return '{0}.base({1!r})'.format(self.system.reference_string(), self.quantity) + return '{0}.base({1!r})'.format( + self.system.reference_string(), self.quantity) def __reduce__(self): return (get_base_unit_with_name, (self.system, self.quantity,)) - def __eq__(self, other): if self is other: return True @@ -616,13 +635,13 @@ def dtype(self): class nonnumeric_unit(unit): """ - nonnumeric_unit objects are indivisable units + nonnumeric_unit objects are indivisable units not connected to any system of units. - + nonnumeric_units cannot be used to derive new units from. - - nonnumeric_units have no physical meaning. + + nonnumeric_units have no physical meaning. """ def __init__(self, name, symbol): self.name = name @@ -638,28 +657,33 @@ def reference_string(self): def __mul__(self, other): if other == 1: return self - raise exceptions.AmuseException("Cannot derive other units from a non numeric unit") + raise exceptions.AmuseException( + "Cannot derive other units from a non numeric unit") def __truediv__(self, other): - raise exceptions.AmuseException("Cannot derive other units from a non numeric unit") + raise exceptions.AmuseException( + "Cannot derive other units from a non numeric unit") def __rmul__(self, other): if other == 1: return self - raise exceptions.AmuseException("Cannot derive other units from a non numeric unit") + raise exceptions.AmuseException( + "Cannot derive other units from a non numeric unit") def __rtruediv__(self, other): if other == 1: return self - raise exceptions.AmuseException("Cannot derive other units from a non numeric unit") + raise exceptions.AmuseException( + "Cannot derive other units from a non numeric unit") def __pow__(self, other): if other == 1: return self - raise exceptions.AmuseException("Cannot derive other units from a non numeric unit") + raise exceptions.AmuseException( + "Cannot derive other units from a non numeric unit") def __div__(self, other): return self.__truediv__(other) @@ -696,7 +720,7 @@ class string_unit(nonnumeric_unit): """ String unit objects define quantities with a string value. These have no physical meaning, but are needed for some - legacy codes. For example the path of a file. + legacy codes. For example the path of a file. """ def __init__(self, name, symbol): nonnumeric_unit.__init__(self, name, symbol) @@ -715,46 +739,51 @@ class enumeration_unit(nonnumeric_unit): DEFINED={} """ Enumeration unit objects define a fixed set of quantities. - + A quantity with a enumeration_unit can only have a value defined in the set of values of the enumeration_unit. - - :argument possible_values: A sequence or iterable with all + + :argument possible_values: A sequence or iterable with all the possible values. If None the possible values are integers ranging from 0 to the length of the names_for_values argument :argument names_for_values: A sequence of strings defining a display name for each value. If None the names are the string vales of the values in the possible_values arguments - + Examples - + >>> my_unit = enumeration_unit('my_unit','my_unit', [1,2,5], ["star","gas","planet"]) - >>> 2 | my_unit + >>> 2 * my_unit quantity<2 - gas> >>> list(my_unit.quantities()) [quantity<1 - star>, quantity<2 - gas>, quantity<5 - planet>] - >>> 3 | my_unit + >>> 3 * my_unit Traceback (most recent call last): ... AmuseException: <3> is not a valid value for unit - + Or, with default values: - + >>> my_unit = enumeration_unit('my_unit','my_unit', None, ["star","gas","planet"]) - >>> 2 | my_unit + >>> 2 * my_unit quantity<2 - planet> >>> list(my_unit.quantities()) [quantity<0 - star>, quantity<1 - gas>, quantity<2 - planet>] - + """ - def __init__(self, name, symbol, possible_values = None, names_for_values = None): + def __init__( + self, name, symbol, possible_values=None, names_for_values=None, + ): nonnumeric_unit.__init__(self, name, symbol) - self.possible_values = self._initial_list_of_possible_values(possible_values, names_for_values) - self.names_for_values = self._initial_names_for_values(possible_values, names_for_values) + self.possible_values = self._initial_list_of_possible_values( + possible_values, names_for_values) + self.names_for_values = self._initial_names_for_values( + possible_values, names_for_values) if not len(self.possible_values) == len(self.names_for_values): - raise exceptions.AmuseException("Must provide equal lenght list for values({0}) and names({1})".format(len(self.possible_values), len(self.names_for_values))) + raise exceptions.AmuseException( + "Must provide equal lenght list for values({0}) and names({1})".format(len(self.possible_values), len(self.names_for_values))) self.mapping_from_values_to_names = self._initial_mapping_from_values_to_names() self.DEFINED[name] = self @@ -793,12 +822,12 @@ def value_to_string(self, value): def quantities(self): for x in self.possible_values: - yield x | self + yield x * self def __call__(self, string): index = self.names_for_values.index(string) if index > 0: - return self.possible_values[index] | self + return self.possible_values[index] * self else: raise exceptions.AmuseException("{0} is not a valid name for {1} enumeration type".format(string, self.name)) @@ -830,25 +859,25 @@ class named_unit(unit): is shown and not the unit parts. For all other operations the named_units works exactly like the aliased unit. - + :argument name: Long name or description of the unit :argument symbol: Short name to show when printing units or quantities :argument unit: The unit to alias - + >>> from amuse.units import si >>> 60.0 * si.s unit<60.0 * s> >>> minute = named_unit("minute","min", 60*si.s) >>> minute unit - >>> (20.0 | (60.0 * si.s)).as_quantity_in(minute) + >>> (20.0 * (60.0 * si.s)).as_quantity_in(minute) quantity<20.0 min> """ def __init__(self, name, symbol, unit): self.name = name self.symbol = symbol - self.local_unit = unit + self.local_unit = unit.as_unit() def __str__(self): return self.symbol @@ -883,10 +912,10 @@ class factor_unit(derived_unit): a number. Do not call this method directly, factor_unit objects are supposed to be created by multiplying a number with a unit. - + :argument unit: The unit to derive from. :argument factor: The multiplication factor. - + >>> from amuse.units import si >>> minute = 60.0 * si.s >>> minute.as_quantity_in(si.s) @@ -896,7 +925,7 @@ class factor_unit(derived_unit): unit<60.0 * 60.0 * s> >>> hour.as_quantity_in(si.s) quantity<3600.0 s> - + """ def __init__(self, factor, unit, name = None, symbol = None): @@ -908,7 +937,7 @@ def __init__(self, factor, unit, name = None, symbol = None): def __str__(self): if self.symbol is None: return str(self.local_factor) + ' * ' + str(self.local_unit) - return self.symbol + str(self.local_unit) + return self.symbol + str(self.local_unit) def reference_string(self): @@ -943,10 +972,10 @@ class mul_unit(derived_unit): another unit. Do not call this method directly, mul_unit objects are supposed to be created by multiplying units. - + :argument left_hand: Left hand side of the multiplication. :argument right_hand: Right hand side of the multiplication. - + >>> from amuse.units import si >>> area = si.m * si.m >>> area @@ -954,14 +983,14 @@ class mul_unit(derived_unit): >>> hectare = (100 * si.m) * (100 * si.m) >>> hectare.as_quantity_in(area) quantity<10000.0 m * m> - + """ def __init__(self, left_hand, right_hand): self.left_hand = left_hand self.right_hand = right_hand def __str__(self): - return str(self.left_hand) + ' * ' + str(self.right_hand) + return str(self.left_hand) + ' * ' + str(self.right_hand) def reference_string(self): return '(' + self.left_hand.reference_string() + ' * ' + self.right_hand.reference_string() + ')' @@ -983,12 +1012,12 @@ def base(self): ] ) - def get_parts_with_power(self): + def get_parts_with_power(self): lhs_parts = list(self.left_hand.get_parts_with_power()) rhs_parts = list(self.right_hand.get_parts_with_power()) result = [] - for lhs_factor, lhs_power, lhs_unit in lhs_parts: + for lhs_factor, lhs_power, lhs_unit in lhs_parts: rhs_index = 0 found_match = False for rhs_factor, rhs_power, rhs_unit in rhs_parts: @@ -1011,15 +1040,15 @@ def get_parts_with_power(self): class pow_unit(derived_unit): """ A pow_unit object defines a unit as - another unit to a specified power. - + another unit to a specified power. + Do not call this method directly, pow_unit objects are supposed to be created by taking powers of units. - + :argument power: Power of the unit :argument unit: The unit to derive from - + >>> from amuse.units import si >>> area = si.m**2 >>> area @@ -1029,7 +1058,7 @@ class pow_unit(derived_unit): >>> hectare = (100 * si.m) ** 2 >>> hectare.as_quantity_in(area) quantity<10000.0 m**2> - + """ def __init__(self, power, unit): self.power = power @@ -1064,7 +1093,7 @@ def factor(self): - def get_parts_with_power(self): + def get_parts_with_power(self): result = [] for factor, power, unit in self.local_unit.get_parts_with_power(): @@ -1079,10 +1108,10 @@ class div_unit(derived_unit): another unit. Do not call this method directly, div_unit objects are supposed to be created by dividing units. - + :argument left_hand: Left hand side of the multiplication. :argument right_hand: Right hand side of the multiplication. - + >>> from amuse.units import si >>> speed = si.m / si.s >>> speed @@ -1090,7 +1119,7 @@ class div_unit(derived_unit): >>> speed_with_powers = si.m * si.s ** -1 >>> speed.as_quantity_in(speed_with_powers) quantity<1 m * s**-1> - + """ def __init__(self, left_hand, right_hand): self.left_hand = left_hand @@ -1123,12 +1152,12 @@ def base(self): ) - def get_parts_with_power(self): + def get_parts_with_power(self): lhs_parts = list(self.left_hand.get_parts_with_power()) rhs_parts = list(self.right_hand.get_parts_with_power()) result = [] - for lhs_factor, lhs_power, lhs_unit in lhs_parts: + for lhs_factor, lhs_power, lhs_unit in lhs_parts: rhs_index = 0 found_match = False for rhs_factor, rhs_power, rhs_unit in rhs_parts: diff --git a/src/amuse/units/derivedsi.py b/src/amuse/units/derivedsi.py index 3dfdcc8a97..e92c7a4ce1 100644 --- a/src/amuse/units/derivedsi.py +++ b/src/amuse/units/derivedsi.py @@ -1,7 +1,7 @@ from amuse.units.si import * -Hz = named('hertz', 'Hz', 1/s) -MHz = named('megahertz', 'MHz', 1e6*Hz) +Hz = named('hertz', 'Hz', (1/s).as_unit()) +MHz = named('megahertz', 'MHz', (1e6*Hz).as_unit()) rad = named('radian','rad',m/m) sr = named('steradian','sr',m**2/m**2) N = named('newton', 'N', kg * m /s**2) @@ -19,5 +19,5 @@ weber = Wb # handy definitions -one = 1 | none +one = 1 * none km = k(m) diff --git a/src/amuse/units/nbody_system.py b/src/amuse/units/nbody_system.py index dc46308cd8..9f9aec3baa 100644 --- a/src/amuse/units/nbody_system.py +++ b/src/amuse/units/nbody_system.py @@ -4,7 +4,7 @@ International System of Quantities, I.S.Q. and defines the gravitational constant to be 1: -G = 1 | (length**3) / (mass * (time**2)) +G = 1 * (length**3) / (mass * (time**2)) +-------------------+-----------------------------------+-----------------+ |Base quantity |Name in generic unit |Name in S.I. unit| @@ -57,21 +57,19 @@ class nbody_unit(core.base_unit): def __init__(self, unit_in_si, system): core.base_unit.__init__(self, unit_in_si.quantity, unit_in_si.name, unit_in_si.symbol, system) self.unit_in_si = unit_in_si - + def __str__(self): return 'nbody '+self.unit_in_si.quantity - - def is_generic(self): return True - - + + nbody_system = core.system('nbody') length = generic_unit_system.length -time = generic_unit_system.time -mass = generic_unit_system.mass +time = generic_unit_system.time +mass = generic_unit_system.mass acceleration = length / (time ** 2) potential = (length ** 2) / (time ** 2) @@ -83,7 +81,7 @@ def is_generic(self): pressure = mass / length / (time ** 2) momentum_density = density * speed energy_density = density * specific_energy -G = 1. | (length**3) / (mass * (time**2)) +G = 1. * (length**3) / (mass * (time**2)) def is_nbody_unit(unit): for factor, x in unit.base: diff --git a/src/amuse/units/nist.py b/src/amuse/units/nist.py index b57817efeb..f49f431403 100644 --- a/src/amuse/units/nist.py +++ b/src/amuse/units/nist.py @@ -24,9 +24,9 @@ pi = numpy.pi hbar = h / (2.0 * numpy.pi) four_pi_stefan_boltzmann = 4.0 * numpy.pi * Stefan_hyphen_Boltzmann_constant -mu0 = 4 * numpy.pi * 1.e-7 | N/A**2 +mu0 = 4 * numpy.pi * 1.e-7 * N/A**2 eps0 = mu0**-1 * c**-2 -sidereal_day = 86164.100352 | s +sidereal_day = 86164.100352 * s #machine constants eps = numpy.finfo(numpy.double).eps precision = int(numpy.log10(2/eps)) @@ -173,7 +173,7 @@ def sort_units(self): def print_list_of_units(self, unitlist): for name, value, unit in unitlist: - self.nistfile += ("{0} = {1} | {2}\n".format(name, value, unit or "none")) + self.nistfile += ("{0} = {1} * {2}\n".format(name, value, unit or "none")) def generate_constants(self): self.list_constants() diff --git a/src/amuse/units/quantities.py b/src/amuse/units/quantities.py index 94308d2162..b714d68c73 100644 --- a/src/amuse/units/quantities.py +++ b/src/amuse/units/quantities.py @@ -10,7 +10,7 @@ from amuse.support.core import compare_version_strings from amuse.units import core from amuse.units.si import none -from amuse.units.core import zero_unit +from amuse.units.core import zero_unit, factor_unit """ @@ -21,30 +21,31 @@ class Quantity(object): specific unit. Quantity is an abstract base class for VectorQuantity and ScalarQuantity. - Quantities should be constructed using *or-operator* ("|"), + Quantities should be constructed using *mul-operator* ("*"), *new_quantity* or *unit.new_quantity*. + Constructing quantities using the *or-operator* ("|") is deprecated. Quantities emulate numeric types. Examples >>> from amuse.units import units - >>> 100 | units.m + >>> 100 * units.m quantity<100 m> - >>> (100 | units.m) + (1 | units.km) + >>> (100 * units.m) + (1 * units.km) quantity<1100.0 m> Quantities can be tested >>> from amuse.units import units - >>> x = 100 | units.m + >>> x = 100 * units.m >>> x.is_quantity() True >>> x.is_scalar() True >>> x.is_vector() False - >>> v = [100, 200, 300] | units.g + >>> v = [100, 200, 300] * units.g >>> v.is_quantity() True >>> v.is_scalar() @@ -55,7 +56,7 @@ class Quantity(object): Quantities can be converted to numbers >>> from amuse.units import units - >>> x = 1000.0 | units.m + >>> x = 1000.0 * units.m >>> x.value_in(units.m) 1000.0 >>> x.value_in(units.km) @@ -167,10 +168,10 @@ def sqrt(self): """Calculate the square root of each component >>> from amuse.units import units - >>> s1 = 144.0 | units.m**2 + >>> s1 = 144.0 * units.m**2 >>> s1.sqrt() quantity<12.0 m> - >>> v1 = [16.0, 25.0, 36.0] | units.kg + >>> v1 = [16.0, 25.0, 36.0] * units.kg >>> v1.sqrt() quantity<[4.0, 5.0, 6.0] kg**0.5> """ @@ -217,7 +218,7 @@ def value_in(self, unit): :returns: number in the given unit >>> from amuse.units import units - >>> x = 10 | units.km + >>> x = 10 * units.km >>> x.value_in(units.m) 10000.0 @@ -230,7 +231,7 @@ def __abs__(self): Return the absolute value of this quantity >>> from amuse.units import units - >>> x = -10 | units.km + >>> x = -10 * units.km >>> print abs(x) 10 km """ @@ -241,7 +242,7 @@ def __neg__(self): Unary minus. >>> from amuse.units import units - >>> x = -10 | units.km + >>> x = -10 * units.km >>> print -x 10 km """ @@ -308,11 +309,6 @@ def __getitem__(self, index): def copy(self): return new_quantity(self.number, self.unit) - def to_unit(self): - in_base=self.in_base() - return in_base.number * in_base.unit - - def __getstate__(self): return (self.unit, self.number) @@ -344,7 +340,11 @@ def sorted(self): return self def as_unit(self): - return self.number * self.unit + return factor_unit(self.number, self.unit) + + def to_unit(self): + in_base=self.in_base() + return in_base.number * in_base.unit class _flatiter_wrapper(object): def __init__(self, quantity): @@ -389,8 +389,8 @@ class VectorQuantity(Quantity): quantity. >>> from amuse.units import units - >>> v1 = [0.0, 1.0, 2.0] | units.kg - >>> v2 = [2.0, 4.0, 6.0] | units.kg + >>> v1 = [0.0, 1.0, 2.0] * units.kg + >>> v2 = [2.0, 4.0, 6.0] * units.kg >>> v1 + v2 quantity<[2.0, 5.0, 8.0] kg> >>> len(v1) @@ -481,7 +481,7 @@ def sum(self, axis=None, dtype=None, out=None): """Calculate the sum of the vector components >>> from amuse.units import units - >>> v1 = [0.0, 1.0, 2.0] | units.kg + >>> v1 = [0.0, 1.0, 2.0] * units.kg >>> v1.sum() quantity<3.0 kg> """ @@ -496,10 +496,10 @@ def prod(self, axis=None, dtype=None): """Calculate the product of the vector components >>> from amuse.units import units - >>> v1 = [1.0, 2.0, 3.0] | units.m + >>> v1 = [1.0, 2.0, 3.0] * units.m >>> v1.prod() quantity<6.0 m**3> - >>> v1 = [[2.0, 3.0], [2.0, 4.0], [5.0,3.0] ] | units.m + >>> v1 = [[2.0, 3.0], [2.0, 4.0], [5.0,3.0] ] * units.m >>> v1.prod() quantity<720.0 m**6> >>> v1.prod(0) @@ -507,7 +507,7 @@ def prod(self, axis=None, dtype=None): >>> v1.prod(1) quantity<[6.0, 8.0, 15.0] m**2> - >>> v1 = [[[2.0, 3.0], [2.0, 4.0]],[[5.0, 2.0], [3.0, 4.0]]] | units.m + >>> v1 = [[[2.0, 3.0], [2.0, 4.0]],[[5.0, 2.0], [3.0, 4.0]]] * units.m >>> v1.prod() # doctest:+ELLIPSIS quantity<5760.0 m**8...> >>> v1.prod(0) @@ -528,7 +528,7 @@ def inner(self, other): """Calculate the inner product of self with other. >>> from amuse.units import units - >>> v1 = [1.0, 2.0, 3.0] | units.m + >>> v1 = [1.0, 2.0, 3.0] * units.m >>> v1.inner(v1) quantity<14.0 m**2> """ @@ -540,7 +540,7 @@ def length_squared(self): """Calculate the squared length of the vector. >>> from amuse.units import units - >>> v1 = [2.0, 3.0, 4.0] | units.m + >>> v1 = [2.0, 3.0, 4.0] * units.m >>> v1.length_squared() quantity<29.0 m**2> """ @@ -550,7 +550,7 @@ def length(self): """Calculate the length of the vector. >>> from amuse.units import units - >>> v1 = [0.0, 3.0, 4.0] | units.m + >>> v1 = [0.0, 3.0, 4.0] * units.m >>> v1.length() quantity<5.0 m> """ @@ -560,7 +560,7 @@ def lengths(self): """Calculate the length of the vectors in this vector. >>> from amuse.units import units - >>> v1 = [[0.0, 3.0, 4.0],[2.0 , 2.0 , 1.0]] | units.m + >>> v1 = [[0.0, 3.0, 4.0],[2.0 , 2.0 , 1.0]] * units.m >>> v1.lengths() quantity<[5.0, 3.0] m> """ @@ -570,7 +570,7 @@ def lengths_squared(self): """Calculate the length of the vectors in this vector >>> from amuse.units import units - >>> v1 = [[0.0, 3.0, 4.0],[4.0, 2.0, 1.0]] | units.m + >>> v1 = [[0.0, 3.0, 4.0],[4.0, 2.0, 1.0]] * units.m >>> v1.lengths_squared() quantity<[25.0, 21.0] m**2> """ @@ -584,7 +584,7 @@ def __getitem__(self, index): :returns: quantity with the same units >>> from amuse.units import si - >>> vector = [0.0, 1.0, 2.0] | si.kg + >>> vector = [0.0, 1.0, 2.0] * si.kg >>> print vector[1] 1.0 kg >>> print vector[0:2] @@ -617,9 +617,9 @@ def __setitem__(self, index, quantity): the unit of this vector >>> from amuse.units import si - >>> vector = [0.0, 1.0, 2.0] | si.kg + >>> vector = [0.0, 1.0, 2.0] * si.kg >>> g = si.kg / 1000 - >>> vector[1] = 3500 | g + >>> vector[1] = 3500 * g >>> print vector [0.0, 3.5, 2.0] kg """ @@ -640,7 +640,7 @@ def x(self): :returns: x axis component as a quantity >>> from amuse.units import si - >>> vector = [1.0, 2.0, 3.0] | si.kg + >>> vector = [1.0, 2.0, 3.0] * si.kg >>> print vector.x 1.0 kg """ @@ -654,7 +654,7 @@ def y(self): :returns: y axis component as a quantity >>> from amuse.units import si - >>> vector = [1.0, 2.0, 3.0] | si.kg + >>> vector = [1.0, 2.0, 3.0] * si.kg >>> print vector.y 2.0 kg """ @@ -668,7 +668,7 @@ def z(self): :returns: z axis component as a quantity >>> from amuse.units import si - >>> vector = [1.0, 2.0, 3.0] | si.kg + >>> vector = [1.0, 2.0, 3.0] * si.kg >>> print vector.z 3.0 kg """ @@ -693,15 +693,15 @@ def append(self, scalar_quantity): Append a scalar quantity to this vector. >>> from amuse.units import si - >>> vector = [1.0, 2.0, 3.0] | si.kg - >>> vector.append(4.0 | si.kg) + >>> vector = [1.0, 2.0, 3.0] * si.kg + >>> vector.append(4.0 * si.kg) >>> print vector [1.0, 2.0, 3.0, 4.0] kg """ append_number = numpy.array(scalar_quantity.value_in(self.unit)) # fix for deg, unitless # The following lines make sure that appending vectors works as expected, - # e.g. ([]|units.m).append([1,2,3]|units.m) -> [[1,2,3]] | units.m - # e.g. ([[1,2,3]]|units.m).append([4,5,6]|units.m) -> [[1,2,3],[4,5,6]] | units.m + # e.g. ([]*units.m).append([1,2,3]*units.m) -> [[1,2,3]] * units.m + # e.g. ([[1,2,3]]*units.m).append([4,5,6]*units.m) -> [[1,2,3],[4,5,6]] * units.m if (append_number.shape and (len(self._number) == 0 or self._number.shape[1:] == append_number.shape)): new_shape = [1 + self._number.shape[0]] + list(append_number.shape) else: @@ -715,8 +715,8 @@ def extend(self, vector_quantity): is converted to the units of this vector. >>> from amuse.units import units - >>> vector1 = [1.0, 2.0, 3.0] | units.kg - >>> vector2 = [1500, 2500, 6000] | units.g + >>> vector1 = [1.0, 2.0, 3.0] * units.kg + >>> vector2 = [1500, 2500, 6000] * units.g >>> vector1.extend(vector2) >>> print vector1 [1.0, 2.0, 3.0, 1.5, 2.5, 6.0] kg @@ -730,8 +730,8 @@ def prepend(self, scalar_quantity): is converted to the units of this vector. >>> from amuse.units import units - >>> vector1 = [1.0, 2.0, 3.0] | units.kg - >>> vector1.prepend(0.0 | units.kg) + >>> vector1 = [1.0, 2.0, 3.0] * units.kg + >>> vector1.prepend(0.0 * units.kg) >>> print vector1 [0.0, 1.0, 2.0, 3.0] kg """ @@ -742,8 +742,8 @@ def minimum(self, other): Return the minimum of self and the argument. >>> from amuse.units import si - >>> v1 = [1.0, 2.0, 3.0] | si.kg - >>> v2 = [0.0, 3.0, 4.0] | si.kg + >>> v1 = [1.0, 2.0, 3.0] * si.kg + >>> v2 = [0.0, 3.0, 4.0] * si.kg >>> v1.minimum(v2) quantity<[0.0, 2.0, 3.0] kg> @@ -758,8 +758,8 @@ def maximum(self, other): Return the maximum of self and the argument. >>> from amuse.units import si - >>> v1 = [1.0, 2.0, 3.0] | si.kg - >>> v2 = [0.0, 3.0, 4.0] | si.kg + >>> v1 = [1.0, 2.0, 3.0] * si.kg + >>> v2 = [0.0, 3.0, 4.0] * si.kg >>> v1.maximum(v2) quantity<[1.0, 3.0, 4.0] kg> """ @@ -773,7 +773,7 @@ def max(self, axis = None): Return the maximum along an axis. >>> from amuse.units import si - >>> v1 = [1.0, 2.0, 3.0] | si.kg + >>> v1 = [1.0, 2.0, 3.0] * si.kg >>> v1.amax() quantity<3.0 kg> """ @@ -785,7 +785,7 @@ def min(self, axis = None): Return the minimum value along an axis. >>> from amuse.units import si - >>> v1 = [1.0, 2.0, 3.0] | si.kg + >>> v1 = [1.0, 2.0, 3.0] * si.kg >>> v1.amin() quantity<1.0 kg> """ @@ -799,7 +799,7 @@ def argmax(self, axis = None): Return the indices of the maximum values along an axis. >>> from amuse.units import si - >>> v1 = [[1.0, 2.0, 3.0], [2.5, 2.5, 2.5]] | si.kg + >>> v1 = [[1.0, 2.0, 3.0], [2.5, 2.5, 2.5]] * si.kg >>> v1.argmax(axis=0) array([1, 1, 0]) """ @@ -810,7 +810,7 @@ def argmin(self, axis = None): Return the indices of the minimum values along an axis. >>> from amuse.units import si - >>> v1 = [[1.0, 2.0, 3.0], [2.5, 2.5, 2.5]] | si.kg + >>> v1 = [[1.0, 2.0, 3.0], [2.5, 2.5, 2.5]] * si.kg >>> v1.argmin(axis=0) array([0, 0, 1]) """ @@ -822,7 +822,7 @@ def sorted(self): Return a new vector with all items sorted. >>> from amuse.units import si - >>> v1 = [3.0, 1.0, 2.0] | si.kg + >>> v1 = [3.0, 1.0, 2.0] * si.kg >>> v1.sorted() quantity<[1.0, 2.0, 3.0] kg> """ @@ -834,7 +834,7 @@ def argsort(self, **options): Returns the indices that would sort an array. >>> from amuse.units import si - >>> v1 = [3.0, 1.0, 2.0] | si.kg + >>> v1 = [3.0, 1.0, 2.0] * si.kg >>> v1.argsort() array([1, 2, 0]) """ @@ -845,7 +845,7 @@ def argmax(self, **options): Returns the index of the maximum item >>> from amuse.units import si - >>> v1 = [1.0, 3.0, 2.0] | si.kg + >>> v1 = [1.0, 3.0, 2.0] * si.kg >>> v1.argmax() 1 """ @@ -860,9 +860,9 @@ def sorted_with(self, *others): the numpy.sort documentation >>> from amuse.units import si - >>> v1 = [3.0, 1.0, 2.0] | si.kg - >>> v2 = [2.0, 3.0, 2.0] | si.m - >>> v3 = [1.0, 4.0, 5.0] | si.s + >>> v1 = [3.0, 1.0, 2.0] * si.kg + >>> v2 = [2.0, 3.0, 2.0] * si.m + >>> v3 = [1.0, 4.0, 5.0] * si.s >>> list(v1.sorted_with(v2, v3)) [quantity<[1.0, 2.0, 3.0] kg>, quantity<[3.0, 2.0, 2.0] m>, quantity<[4.0, 5.0, 1.0] s>] """ @@ -912,7 +912,7 @@ def dot(self, other, **kwargs): Return the dot product of this vector quantity with the supplied vector (quantity). >>> from amuse.units import units - >>> v1 = [1.0, 2.0, 3.0] | units.m + >>> v1 = [1.0, 2.0, 3.0] * units.m >>> v1.dot(v1) quantity<14.0 m**2> """ @@ -937,7 +937,7 @@ class ZeroQuantity(Quantity): >>> from amuse.units import si >>> x = zero - >>> x += 2.0 | si.kg + >>> x += 2.0 * si.kg >>> x quantity<2.0 kg> @@ -1077,9 +1077,9 @@ class NonNumericQuantity(Quantity): ... [1,3,4], ... ["first", "second", "third"]) ... - >>> 3 | my_unit + >>> 3 * my_unit quantity<3 - second> - >>> (3 | my_unit).value_in(my_unit) + >>> (3 * my_unit).value_in(my_unit) 3 """ @@ -1338,13 +1338,13 @@ def meshgrid(*xi, **kwargs): result = numpy.meshgrid(*unitless_xi, **kwargs) - return [matrix | unit for matrix, unit in zip(result, units)] + return [matrix * unit for matrix, unit in zip(result, units)] def polyfit(x, y, deg): (x_number, y_number), (x_unit, y_unit) = separate_numbers_and_units([x, y]) fit = numpy.polyfit(x_number, y_number, deg) - fit = [f | y_unit/(x_unit**(deg-i)) for i, f in enumerate(fit)] + fit = [f * y_unit/(x_unit**(deg-i)) for i, f in enumerate(fit)] return fit @@ -1361,7 +1361,7 @@ def polyval(p, x): value = numpy.polyval(p_number, x) - return value | y_unit + return value * y_unit def searchsorted(a, v, **kwargs): if is_quantity(a): diff --git a/src/amuse/units/si.py b/src/amuse/units/si.py index 56b85bf60a..88d0742187 100644 --- a/src/amuse/units/si.py +++ b/src/amuse/units/si.py @@ -11,51 +11,131 @@ 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, + core.factor_unit(10, unit) + ) def hecto(unit): - return named('hecto'+unit.name,'h'+unit.symbol,100.*unit) + return named( + 'hecto'+unit.name, + 'h'+unit.symbol, + core.factor_unit(100, unit) + ) def kilo(unit): - return named('kilo'+unit.name,'k'+unit.symbol,1000.*unit) + return named( + 'kilo'+unit.name, + 'k'+unit.symbol, + core.factor_unit(1000, unit) + ) def mega(unit): - return named('mega'+unit.name,'M'+unit.symbol,1.e6*unit) + return named( + 'mega'+unit.name, + 'M'+unit.symbol, + core.factor_unit(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, + core.factor_unit(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, + core.factor_unit(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, + core.factor_unit(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, + core.factor_unit(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, + core.factor_unit(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, + core.factor_unit(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, + core.factor_unit(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, + core.factor_unit(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, + core.factor_unit(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, + core.factor_unit(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, + core.factor_unit(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, + core.factor_unit(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, + core.factor_unit(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, + core.factor_unit(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, + core.factor_unit(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, + core.factor_unit(1.e-24, unit) + ) -k=kilo +k = kilo diff --git a/src/amuse/units/trigo.py b/src/amuse/units/trigo.py index 29189f859d..539e760c27 100644 --- a/src/amuse/units/trigo.py +++ b/src/amuse/units/trigo.py @@ -1,26 +1,26 @@ import numpy from amuse.units import quantities -from amuse.units.units import rad,deg,rev,pi +from amuse.units.units import rad, deg, rev, pi -#trigonometric convenience functions which are "unit aware" -sin=lambda x: numpy.sin(1.*x) -cos=lambda x: numpy.cos(1.*x) -tan=lambda x: numpy.tan(1.*x) -arcsin=lambda x: numpy.arcsin(x) | rad -arccos=lambda x: numpy.arccos(x) | rad -arctan=lambda x: numpy.arctan(x) | rad -arctan2=lambda x,y: numpy.arctan2(x,y) | rad +# trigonometric convenience functions which are "unit aware" +sin = lambda x: numpy.sin(1.*x) +cos = lambda x: numpy.cos(1.*x) +tan = lambda x: numpy.tan(1.*x) +arcsin = lambda x: numpy.arcsin(x) * rad +arccos = lambda x: numpy.arccos(x) * rad +arctan = lambda x: numpy.arctan(x) * rad +arctan2 = lambda x, y: numpy.arctan2(x, y) * rad def to_rad(angle): - return quantities.as_quantity_in(angle,rad) + return quantities.as_quantity_in(angle, rad) def to_deg(angle): - return quantities.as_quantity_in(angle,deg) + return quantities.as_quantity_in(angle, deg) def to_rev(angle): - return quantities.as_quantity_in(angle,rev) + return quantities.as_quantity_in(angle, rev) def in_rad(angle): - return quantities.value_in(angle,rad) + return quantities.value_in(angle, rad) def in_deg(angle): - return quantities.value_in(angle,deg) + return quantities.value_in(angle, deg) def in_rev(angle): - return quantities.value_in(angle,rev) + return quantities.value_in(angle, rev) diff --git a/src/amuse/units/units.py b/src/amuse/units/units.py index a1fb91ae80..2b27d671d2 100644 --- a/src/amuse/units/units.py +++ b/src/amuse/units/units.py @@ -3,57 +3,59 @@ from amuse.units.si import * from amuse.units.derivedsi import * from amuse.units import constants +from amuse.units.core import factor_unit # misc every day -minute = named('minute', 'min', 60.0 * s) -hour = named('hour', 'hr', 60.0 * minute) -day = named('day', 'day', 24.0 * hour) -yr = named('year', 'yr', 365.242199 * day) -julianyr = named('julian yr','julianyr',365.25* day) +minute = named('minute', 'min', factor_unit(60.0, s)) +hour = named('hour', 'hr', factor_unit(60.0, minute)) +day = named('day', 'day', factor_unit(24.0, hour)) +yr = named('year', 'yr', factor_unit(365.242199, day)) +julianyr = named('julian yr','julianyr', factor_unit(365.25, day)) ms = named('meter per seconds', 'ms', m / s) kms = named('kilometer per seconds', 'kms', km / s) # units based on measured quantities e = named('electron charge', 'e', constants.elementary_charge.as_unit()) -eV=named('electron volt','eV', e*V) -MeV=named('mega electron volt','MeV', 1e6*eV) -GeV=named('giga electron volt','GeV', 1e9*eV) +eV = named('electron volt', 'eV', e*V) +MeV = named('mega electron volt','MeV', factor_unit(1e6, eV)) +GeV = named('giga electron volt','GeV', factor_unit(1e9, eV)) E_h = named('hartree energy', 'E_h', constants.Hartree_energy.as_unit()) amu = named('atomic mass unit', 'amu', constants.u.as_unit()) Ry = named('rydberg unit', 'Ry', (constants.Rydberg_constant * constants.h * constants.c).as_quantity_in(eV).as_unit()) # astronomical units -angstrom = named('angstrom', 'angstrom', 1e-10*m) -AU = named('astronomical unit', 'AU', 149597870691.0 * m) -au = named('astronomical unit', 'au', 149597870691.0 * m) -AUd = named('AU per day','AUd', 149597870691.0 * m / day) -parsec=named('parsec','parsec', AU / numpy.tan(numpy.pi/(180*60*60))) -kpc=named('kilo parsec','kpc',10**3 * parsec) -Mpc=named('mega parsec','Mpc',10**6 * parsec) -Gpc=named('giga parsec','Gpc',10**9 * parsec) -lightyear = named('light year', 'ly', 9460730472580.8 * km) +angstrom = named('angstrom', 'angstrom', factor_unit(1e-10, m)) +au = named('astronomical unit', 'au', factor_unit(149597870691.0, m)) +AU = au # named('astronomical unit', 'AU', factor_unit(149597870691.0, m)) +aud = named('au per day','aud', factor_unit(149597870691.0, m / day)) +AUd = aud # named('AU per day','AUd', 149597870691.0 * m / day) +parsec = named('parsec','parsec', AU / numpy.tan(numpy.pi/(180*60*60))) +pc = parsec +kpc = named('kilo parsec','kpc', factor_unit(10**3, parsec)) +Mpc = named('mega parsec','Mpc',factor_unit(10**6, parsec)) +Gpc = named('giga parsec','Gpc', factor_unit(10**9, parsec)) +lightyear = named('light year', 'ly', factor_unit(9460730472580.8, km)) #lightyear = named('light year', 'ly', c*julianyr) -LSun = named('solar luminosity', 'LSun', 3.839e26 * W) -MSun = named('solar mass', 'MSun', 1.98892e30 * kg) -MJupiter = named('jupiter mass', 'MJupiter', 1.8987e27 * kg) -MEarth = named('earth mass', 'MEarth', 5.9722e24 * kg) -RSun = named('solar radius', 'RSun', 6.955e8 * m) -RJupiter = named('jupiter radius', 'RJupiter', 71492. * km) -REarth = named('earth radius', 'REarth', 6371.0088 * km) # IUGG mean radius -kyr = named('kilo year', 'kyr', 1000 * yr) -myr = named('million year', 'Myr', 1000000 * yr) +LSun = named('solar luminosity', 'LSun', factor_unit(3.839e26, W)) +MSun = named('solar mass', 'MSun', factor_unit(1.98892e30, kg)) +MJupiter = named('jupiter mass', 'MJupiter', factor_unit(1.8987e27, kg)) +MEarth = named('earth mass', 'MEarth', factor_unit(5.9722e24, kg)) +RSun = named('solar radius', 'RSun', factor_unit(6.955e8, m)) +RJupiter = named('jupiter radius', 'RJupiter', factor_unit(71492., km)) +REarth = named('earth radius', 'REarth', factor_unit(6371.0088, km)) # IUGG mean radius +kyr = named('kilo year', 'kyr', factor_unit(1000, yr)) +myr = named('million year', 'Myr', factor_unit(1000000, yr)) Myr = myr -gyr = named('giga (billion) year', 'Gyr', 1000000000 * yr) +gyr = named('giga (billion) year', 'Gyr', factor_unit(1000000000, yr)) Gyr = gyr -pc = parsec # cgs units -g = named('gram','g', 1e-3 * kg) -cm = named('centimeter','cm',0.01*m) -erg = named('erg','erg', 1e-7 * J) -barye = named('barye', 'Ba', 0.1*Pa) +g = named('gram','g', factor_unit(1e-3, kg)) +cm = named('centimeter','cm', factor_unit(0.01, m)) +erg = named('erg','erg', factor_unit(1e-7, J)) +barye = named('barye', 'Ba', factor_unit(0.1, Pa)) -percent = named('percent', '%', 0.01 * none) +percent = named('percent', '%', factor_unit(0.01, none)) metallicity = core.none_unit('metallicity', 'metallicity') string = core.string_unit('string', 'string') @@ -86,12 +88,14 @@ ) #special unit for keys of particles -object_key = core.key_unit('object_key','key') +object_key = core.key_unit('object_key', 'key') #angles #rad=named('radian','rad',m/m) (defined in derivedsi.py) -pi=numpy.pi | rad -rev=named('revolutions','rev',(2*numpy.pi) * rad) -deg=named('degree','deg',(numpy.pi/180) * rad) -arcmin=named('arcminutes', 'arcmin', (1./60) * deg) -arcsec=named('arcseconds', 'arcsec', (1./3600) * deg) +pi = numpy.pi * rad +rev = named('revolutions','rev', factor_unit((2*numpy.pi), rad)) +deg = named('degree','deg', factor_unit((numpy.pi/180), rad)) +arcmin = named('arcminutes', 'arcmin', factor_unit((1./60), deg)) +arcsec = named('arcseconds', 'arcsec', factor_unit((1./3600), deg)) + +del factor_unit