-
Notifications
You must be signed in to change notification settings - Fork 0
/
constants.py
127 lines (107 loc) · 3.33 KB
/
constants.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
from tools import latex
class Constant:
def __init__(self, name, value, unit=None, latex=None, source=None):
self.name = name
self._value = value
self.v = value
self._unit = unit
self._source = source
self._tex = latex
def __repr__(self):
if self._unit:
return f"{self._value} {self._unit}"
else:
return str(self._value)
def latex(self, dec_sep=","):
if self._tex:
return self._tex
else:
unit = ""
if self._unit:
unit = "\\,\\si{" + self._unit.replace("/", "\\per\\") + "}"
return latex.number_to_latex(self._value, dec_sep) + unit
def get_source(self):
if self._source:
return self._source
else:
return f"No source given for {self.name}"
def get_latex_source(self):
"""
@online{self.name,
% title={}
% subtitle={}
% organization = {}
url = {self._source}
}
:return:
"""
if self._source:
return "@online{+" + self.name.repalce(" ", "_") + \
"\n% title={}\n% subtitle={}\n% organization = {}" \
"\nurl = {" + self._source + "}\n}"
# MASSES
m_e = Constant("electron mass",
9.1093837015e-31,
unit="kg",
latex=r"9.1093837015\cdot10^{-31}\,\si{\kg}",
source="https://physics.nist.gov/cgi-bin/cuu/Value?me")
m_p = Constant("proton mass",
1.67262192369e-27,
unit="kg",
source="https://physics.nist.gov/cgi-bin/cuu/Value?mp")
m_n = Constant("neutron mass",
1.67492749804e-27,
unit="kg",
source="https://physics.nist.gov/cgi-bin/cuu/Value?mn")
#
# ELECTROMAGNETIC
#
mu_0 = Constant("vacuum magnetic permeability",
1.25663706212e-6,
unit="N/A^2",
source="https://physics.nist.gov/cgi-bin/cuu/Value?mu0")
ep_0 = Constant("vacuum electric permittivity",
8.8541878128e-12,
unit="F/m^-1",
source="https://www.physics.nist.gov/cgi-bin/cuu/Value?ep0")
e = Constant("elemtary charge",
1.602176634e-19,
unit="C",
source="https://physics.nist.gov/cgi-bin/cuu/Value?e")
#
# UNIVERSAL
#
pi = Constant("pi",
3.1415926535897932384626433)
h = Constant("Planck constant",
6.62607015e-34,
unit="Js",
source="https://physics.nist.gov/cgi-bin/cuu/Value?h")
h_eV = Constant("Planck constant",
4.135667696e-15,
unit="eVs",
source="https://physics.nist.gov/cgi-bin/cuu/Value?hev")
c_0 = Constant("standard acceleration of gravity",
299792458,
unit="m/s",
source="https://physics.nist.gov/cgi-bin/cuu/Value?c")
g_n = Constant("standard acceleration of gravity",
9.80665,
unit="m/s^2",
source="https://physics.nist.gov/cgi-bin/cuu/Value?gn")
const_d = {
# MASS
"m_e": m_e,
"m_p": m_p,
"m_n": m_n,
# ELECTROMAGNETIC
"mu_0": mu_0,
"ep_0": ep_0,
"e": e,
# UNIVERSAL
"pi": pi,
"h": h,
"h_eV": h_eV,
"c_0": c_0,
"g_n": g_n,
}