units.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 '''
3 Provide Python access to Wire Cell system of units.
4 
5 It is made from WireCellUtil/Units.h by one time Emacs hackery and a
6 few extra added for convenience.
7 '''
8  #
9  #
10  #
11 pi = 3.14159265358979323846
12 twopi = 2*pi
13 halfpi = pi/2
14 pi2 = pi*pi
15 
16  #
17  # Length [L]
18  #
19 millimeter = 1.
20 millimeter2 = millimeter*millimeter
21 millimeter3 = millimeter*millimeter*millimeter
22 
23 centimeter = 10.*millimeter
24 centimeter2 = centimeter*centimeter
25 centimeter3 = centimeter*centimeter*centimeter
26 
27 meter = 1000.*millimeter
28 meter2 = meter*meter
29 meter3 = meter*meter*meter
30 
31 kilometer = 1000.*meter
32 kilometer2 = kilometer*kilometer
33 kilometer3 = kilometer*kilometer*kilometer
34 
35 parsec = 3.0856775807e+16*meter
36 
37 micrometer = 1.e-6 *meter
38 nanometer = 1.e-9 *meter
39 angstrom = 1.e-10*meter
40 fermi = 1.e-15*meter
41 
42 barn = 1.e-28*meter2
43 millibarn = 1.e-3 *barn
44 microbarn = 1.e-6 *barn
45 nanobarn = 1.e-9 *barn
46 picobarn = 1.e-12*barn
47 
48  # symbols
49 nm = nanometer
50 um = micrometer
51 
52 mm = millimeter
53 mm2 = millimeter2
54 mm3 = millimeter3
55 
56 cm = centimeter
57 cm2 = centimeter2
58 cm3 = centimeter3
59 
60 m = meter
61 m2 = meter2
62 m3 = meter3
63 
64 km = kilometer
65 km2 = kilometer2
66 km3 = kilometer3
67 
68 pc = parsec
69 
70 #
71 # Angle
72 #
73 radian = 1.
74 milliradian = 1.e-3*radian
75 degree = (pi/180.0)*radian
76 
77 steradian = 1.
78 
79 # symbols
80 rad = radian
81 mrad = milliradian
82 sr = steradian
83 deg = degree
84 
85 #
86 # Time [T]
87 #
88 nanosecond = 1.
89 second = 1.e+9 *nanosecond
90 millisecond = 1.e-3 *second
91 microsecond = 1.e-6 *second
92 picosecond = 1.e-12*second
93 
94 hertz = 1./second
95 kilohertz = 1.e+3*hertz
96 megahertz = 1.e+6*hertz
97 Hz = hertz
98 kHz = kilohertz
99 MHz = megahertz
100 
101 # symbols
102 ns = nanosecond
103 s = second
104 ms = millisecond
105 us = microsecond
106 
107 #
108 # Electric charge [Q]
109 #
110 eplus = 1. # positron charge
111 e_SI = 1.602176487e-19 # positron charge in coulomb
112 coulomb = eplus/e_SI # coulomb = 6.24150 e+18 * eplus
113 fC = 1.0e-15*coulomb
114 
115 #
116 # Energy [E]
117 #
118 megaelectronvolt = 1.
119 electronvolt = 1.e-6*megaelectronvolt
120 kiloelectronvolt = 1.e-3*megaelectronvolt
121 gigaelectronvolt = 1.e+3*megaelectronvolt
122 teraelectronvolt = 1.e+6*megaelectronvolt
123 petaelectronvolt = 1.e+9*megaelectronvolt
124 
125 joule = electronvolt/e_SI # joule = 6.24150 e+12 * MeV
126 
127 # symbols
128 MeV = megaelectronvolt
129 eV = electronvolt
130 keV = kiloelectronvolt
131 GeV = gigaelectronvolt
132 TeV = teraelectronvolt
133 PeV = petaelectronvolt
134 
135 #
136 # Mass [E][T^2][L^-2]
137 #
138 kilogram = joule*second*second/(meter*meter)
139 gram = 1.e-3*kilogram
140 milligram = 1.e-3*gram
141 
142 # symbols
143 kg = kilogram
144 g = gram
145 mg = milligram
146 
147 #
148 # Power [E][T^-1]
149 #
150 watt = joule/second # watt = 6.24150 e+3 * MeV/ns
151 
152 #
153 # Force [E][L^-1]
154 #
155 newton = joule/meter # newton = 6.24150 e+9 * MeV/mm
156 
157 #
158 # Pressure [E][L^-3]
159 #
160 pascal = newton/m2 # pascal = 6.24150 e+3 * MeV/mm3
161 bar = 100000*pascal # bar = 6.24150 e+8 * MeV/mm3
162 atmosphere = 101325*pascal # atm = 6.32420 e+8 * MeV/mm3
163 
164 #
165 # Electric current [Q][T^-1]
166 #
167 ampere = coulomb/second # ampere = 6.24150 e+9 * eplus/ns
168 milliampere = 1.e-3*ampere
169 microampere = 1.e-6*ampere
170 nanoampere = 1.e-9*ampere
171 picoampere = 1.e-12*ampere
172 
173 #
174 # Electric potential [E][Q^-1]
175 #
176 megavolt = megaelectronvolt/eplus
177 kilovolt = 1.e-3*megavolt
178 volt = 1.e-6*megavolt
179 millivolt = 1.e-3*volt
180 mV = millivolt
181 
182 #
183 # Electric resistance [E][T][Q^-2]
184 #
185 ohm = volt/ampere # ohm = 1.60217e-16*(MeV/eplus)/(eplus/ns)
186 
187 #
188 # Electric capacitance [Q^2][E^-1]
189 #
190 farad = coulomb/volt # farad = 6.24150e+24 * eplus/Megavolt
191 millifarad = 1.e-3*farad
192 microfarad = 1.e-6*farad
193 nanofarad = 1.e-9*farad
194 picofarad = 1.e-12*farad
195 
196 #
197 # Magnetic Flux [T][E][Q^-1]
198 #
199 weber = volt*second # weber = 1000*megavolt*ns
200 
201 #
202 # Magnetic Field [T][E][Q^-1][L^-2]
203 #
204 tesla = volt*second/meter2 # tesla =0.001*megavolt*ns/mm2
205 
206 gauss = 1.e-4*tesla
207 kilogauss = 1.e-1*tesla
208 
209 #
210 # Inductance [T^2][E][Q^-2]
211 #
212 henry = weber/ampere # henry = 1.60217e-7*MeV*(ns/eplus)**2
213 
214 #
215 # Temperature
216 #
217 kelvin = 1.
218 
219 #
220 # Amount of substance
221 #
222 mole = 1.
223 
224 #
225 # Activity [T^-1]
226 #
227 becquerel = 1./second
228 curie = 3.7e+10 * becquerel
229 kilobecquerel = 1.e+3*becquerel
230 megabecquerel = 1.e+6*becquerel
231 gigabecquerel = 1.e+9*becquerel
232 millicurie = 1.e-3*curie
233 microcurie = 1.e-6*curie
234 Bq = becquerel
235 kBq = kilobecquerel
236 MBq = megabecquerel
237 GBq = gigabecquerel
238 Ci = curie
239 mCi = millicurie
240 uCi = microcurie
241 
242 #
243 # Absorbed dose [L^2][T^-2]
244 #
245 gray = joule/kilogram
246 kilogray = 1.e+3*gray
247 milligray = 1.e-3*gray
248 microgray = 1.e-6*gray
249 
250 #
251 # Luminous intensity [I]
252 #
253 candela = 1.
254 
255 #
256 # Luminous flux [I]
257 #
258 lumen = candela*steradian
259 
260 #
261 # Illuminance [I][L^-2]
262 #
263 lux = lumen/meter2
264 
265 #
266 # Miscellaneous
267 #
268 perCent = 0.01
269 perThousand = 0.001
270 perMillion = 0.000001
271 
272 
273 # some constants of nature.
274 clight = 2.99792458e8*meter/second
275 
276 
277 # extra added in Python:
278 femtocoulomb = fC = 1.e-15*coulomb