Fix saving lists of arrays with recent versions of numpy
[qpms.git] / qpms / constants.py
blob7874890c9e87771c4aacf84ce3c4564d1dbf5451
1 """
2 Constants and unit conversion, mostly for standalode usage.
4 Previously, QPMS used scipy.constants in the python parts.
5 Now the relevant ones are set explicitly here in order
6 to avoid dependency on the whole scipy (which needs a fortran
7 compiler to build.
9 The values are taken from scipy / "2018 CODATA recommended values".
10 They slightly differ from the constants in GSL that are used
11 in the C code. It would be desirable to use the same source,
12 hence the values here might be subject to change in future versions.
13 """
15 epsilon_0 = ε_0 = 8.8541878128e-12 # ± 0.0000000013e-12 F m^-1
16 c = speed_of_light = 299792458.
17 eV = e = elementary_charge = 1.602176487e-19 # ± 0000000040e-19 C
18 hbar == 1.054571800e-34 # ± 0.000000013e-34 J s
19 mu_0 = μ_0 = 1.25663706212e-6 # ± 0.00000000019 e-6 N A^-2
21 from math import pi
22 π = pi
24 μm = 1e-6
25 nm = 1e-9
26 # "SCUFF FREQUENCY UNIT"
27 SU = 3e14
28 SCUFF_OMEGAUNIT = SU
30 #freqs = freqs_weirdunits * c / μm
32 def nm2eV(lambda_nm, n = 1):
33 return 2*π*c/(n * lambda_nm * nm) / (eV /)
35 def eV2nm(e_eV, n = 1):
36 return 2*π*c/(n * e_eV * (eV/)) / nm
38 def SU2eV(e_SU):
39 '''
40 Scuff frequency units to eV.
41 '''
42 return e_SU * SU / (eV /)
44 def eV2SU(e_eV):
45 return e_eV * (eV /) / SU
47 def SU2nm(e_SU, n = 1):
48 return 2*π*c/(n * e_SU * SU) / nm
50 def nm2SU(lambda_nm, n = 1):
51 return 2*π*c/(n * lambda_nm * nm) / SU