pythonradex 1.0.9__py3-none-any.whl → 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pythonradex/LAMDA_file.py +88 -53
- pythonradex/__init__.py +3 -1
- pythonradex/atomic_transition.py +209 -158
- pythonradex/escape_probability.py +91 -61
- pythonradex/escape_probability_functions.py +206 -165
- pythonradex/helpers.py +75 -28
- pythonradex/intensity.py +271 -0
- pythonradex/molecule.py +236 -188
- pythonradex/radiative_transfer.py +489 -344
- pythonradex/rate_equations.py +278 -189
- {pythonradex-1.0.9.dist-info → pythonradex-2.0.0.dist-info}/METADATA +17 -3
- pythonradex-2.0.0.dist-info/RECORD +15 -0
- {pythonradex-1.0.9.dist-info → pythonradex-2.0.0.dist-info}/WHEEL +1 -1
- pythonradex/flux.py +0 -209
- pythonradex-1.0.9.dist-info/RECORD +0 -15
- {pythonradex-1.0.9.dist-info → pythonradex-2.0.0.dist-info}/licenses/LICENSE.txt +0 -0
pythonradex/LAMDA_file.py
CHANGED
|
@@ -8,16 +8,19 @@ from pythonradex import atomic_transition
|
|
|
8
8
|
from scipy import constants
|
|
9
9
|
import numpy as np
|
|
10
10
|
|
|
11
|
+
|
|
11
12
|
def is_comment(line):
|
|
12
|
-
if line.replace(
|
|
13
|
+
if line.replace(" ", "")[0] == "!":
|
|
13
14
|
return True
|
|
14
15
|
else:
|
|
15
16
|
return False
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
|
|
19
|
+
def read(datafilepath, read_frequencies, read_quantum_numbers=False):
|
|
20
|
+
"""
|
|
21
|
+
Read a data file that follows the LAMDA format (https://home.strw.leidenuniv.nl/~moldata/molformat.html).
|
|
22
|
+
Such files can for example be downloaded from the EMAA (https://emaa.osug.fr/)
|
|
23
|
+
or the LAMDA (http://home.strw.leidenuniv.nl/~moldata) databases.
|
|
21
24
|
|
|
22
25
|
Args:
|
|
23
26
|
datafilepath (:obj:`str`): The filepath to the LAMDA file.
|
|
@@ -30,100 +33,132 @@ def read(datafilepath,read_frequencies,read_quantum_numbers=False):
|
|
|
30
33
|
read_quantum_numbers (:obj:`bool`): Whether to read the quantum numbers
|
|
31
34
|
from the file. Defaults to False. The LAMDA format does not force a
|
|
32
35
|
file to list quantum numbers, so they might not be present.
|
|
33
|
-
|
|
36
|
+
|
|
34
37
|
Returns:
|
|
35
38
|
dict: A dictionary containing the data read from the file.
|
|
36
39
|
The following keys give acces to lists containing the data.
|
|
37
40
|
The elements of these lists are in the order they appear in the file.
|
|
38
41
|
'levels' (a list of pythonradex.atomic_transition.Level objects);
|
|
39
|
-
'radiative transitions' (a list of
|
|
42
|
+
'radiative transitions' (a list of
|
|
40
43
|
pythonradex.atomic_transitions.RadiativeTransition objects);
|
|
41
44
|
'collisional transitions' (a list of
|
|
42
45
|
pythonradex.atomic_transition.CollisionalTransition objects);
|
|
43
46
|
'quantum numbers' (list of str, empty if read_quantum_numbers
|
|
44
47
|
was set to False)
|
|
45
|
-
|
|
46
|
-
#identifiers used in the LAMDA database files:
|
|
47
|
-
LAMDA_coll_ID = {
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
"""
|
|
49
|
+
# identifiers used in the LAMDA database files:
|
|
50
|
+
LAMDA_coll_ID = {
|
|
51
|
+
"1": "H2",
|
|
52
|
+
"2": "para-H2",
|
|
53
|
+
"3": "ortho-H2",
|
|
54
|
+
"4": "e",
|
|
55
|
+
"5": "H",
|
|
56
|
+
"6": "He",
|
|
57
|
+
"7": "H+",
|
|
58
|
+
}
|
|
59
|
+
datafile = open(datafilepath, "r")
|
|
50
60
|
levels = []
|
|
51
61
|
rad_transitions = []
|
|
52
62
|
coll_transitions = {}
|
|
53
63
|
quantum_numbers = []
|
|
54
64
|
comment_offset = 0
|
|
55
|
-
for i,line in enumerate(datafile):
|
|
56
|
-
if is_comment(line) or line==
|
|
65
|
+
for i, line in enumerate(datafile):
|
|
66
|
+
if is_comment(line) or line == "" or line == "\n":
|
|
57
67
|
comment_offset += 1
|
|
58
68
|
continue
|
|
59
|
-
if i == 0+comment_offset:
|
|
69
|
+
if i == 0 + comment_offset:
|
|
60
70
|
continue
|
|
61
|
-
if i == 1+comment_offset:
|
|
71
|
+
if i == 1 + comment_offset:
|
|
62
72
|
continue
|
|
63
|
-
if i == 2+comment_offset:
|
|
73
|
+
if i == 2 + comment_offset:
|
|
64
74
|
n_levels = int(line)
|
|
65
75
|
continue
|
|
66
|
-
if 3+comment_offset <= i < 3+comment_offset+n_levels:
|
|
76
|
+
if 3 + comment_offset <= i < 3 + comment_offset + n_levels:
|
|
67
77
|
line_entries = line.split()
|
|
68
78
|
leveldata = [float(string) for string in line_entries[:3]]
|
|
69
|
-
assert
|
|
70
|
-
|
|
71
|
-
|
|
79
|
+
assert (
|
|
80
|
+
int(leveldata[0]) == i - 2 - comment_offset
|
|
81
|
+
), "level numeration not consistent"
|
|
82
|
+
# transforming energy from cm-1 to J; level indices starting from 0:
|
|
72
83
|
lev = atomic_transition.Level(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
84
|
+
g=leveldata[2],
|
|
85
|
+
E=constants.c * constants.h * leveldata[1] / constants.centi,
|
|
86
|
+
index=int(leveldata[0]) - 1,
|
|
87
|
+
)
|
|
76
88
|
levels.append(lev)
|
|
77
89
|
if read_quantum_numbers:
|
|
78
90
|
quantum_numbers.append(line_entries[3])
|
|
79
91
|
continue
|
|
80
|
-
if i == 3+comment_offset+n_levels:
|
|
92
|
+
if i == 3 + comment_offset + n_levels:
|
|
81
93
|
n_rad_transitions = int(line)
|
|
82
94
|
continue
|
|
83
|
-
if
|
|
95
|
+
if (
|
|
96
|
+
4 + comment_offset + n_levels
|
|
97
|
+
<= i
|
|
98
|
+
< 4 + comment_offset + n_levels + n_rad_transitions
|
|
99
|
+
):
|
|
84
100
|
radtransdata = [float(string) for string in line.split()]
|
|
85
|
-
up = next(level for level in levels if level.
|
|
86
|
-
low = next(level for level in levels if level.
|
|
87
|
-
rad_trans_kwargs = {
|
|
101
|
+
up = next(level for level in levels if level.index == radtransdata[1] - 1)
|
|
102
|
+
low = next(level for level in levels if level.index == radtransdata[2] - 1)
|
|
103
|
+
rad_trans_kwargs = {"up": up, "low": low, "A21": radtransdata[3]}
|
|
88
104
|
if read_frequencies:
|
|
89
|
-
nu0 = radtransdata[4]*constants.giga
|
|
90
|
-
Delta_E = up.E-low.E
|
|
91
|
-
assert np.isclose(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
105
|
+
nu0 = radtransdata[4] * constants.giga
|
|
106
|
+
Delta_E = up.E - low.E
|
|
107
|
+
assert np.isclose(
|
|
108
|
+
nu0, Delta_E / constants.h, atol=0, rtol=1e-3
|
|
109
|
+
), "read frequency is inconsistent with level energies"
|
|
110
|
+
rad_trans_kwargs["nu0"] = nu0
|
|
111
|
+
rad_trans = atomic_transition.RadiativeTransition(**rad_trans_kwargs)
|
|
95
112
|
rad_transitions.append(rad_trans)
|
|
96
113
|
continue
|
|
97
|
-
if i == 4+comment_offset+n_levels+n_rad_transitions:
|
|
114
|
+
if i == 4 + comment_offset + n_levels + n_rad_transitions:
|
|
98
115
|
coll_partner_offset = 0
|
|
99
116
|
continue
|
|
100
|
-
if i == 5+comment_offset+n_levels+n_rad_transitions + coll_partner_offset:
|
|
117
|
+
if i == 5 + comment_offset + n_levels + n_rad_transitions + coll_partner_offset:
|
|
101
118
|
coll_ID = LAMDA_coll_ID[line[0]]
|
|
102
119
|
coll_transitions[coll_ID] = []
|
|
103
120
|
continue
|
|
104
|
-
if i == 6+comment_offset+n_levels+n_rad_transitions + coll_partner_offset:
|
|
121
|
+
if i == 6 + comment_offset + n_levels + n_rad_transitions + coll_partner_offset:
|
|
105
122
|
n_coll_transitions = int(line)
|
|
106
123
|
continue
|
|
107
|
-
if i == 7+comment_offset+n_levels+n_rad_transitions + coll_partner_offset:
|
|
108
|
-
continue
|
|
109
|
-
if i == 8+comment_offset+n_levels+n_rad_transitions + coll_partner_offset:
|
|
124
|
+
if i == 7 + comment_offset + n_levels + n_rad_transitions + coll_partner_offset:
|
|
125
|
+
continue # this lines contains the number of temperature elements
|
|
126
|
+
if i == 8 + comment_offset + n_levels + n_rad_transitions + coll_partner_offset:
|
|
110
127
|
coll_temperatures = np.array([float(string) for string in line.split()])
|
|
111
128
|
continue
|
|
112
|
-
last_coll_trans_i =
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
129
|
+
last_coll_trans_i = (
|
|
130
|
+
9
|
|
131
|
+
+ comment_offset
|
|
132
|
+
+ n_levels
|
|
133
|
+
+ n_rad_transitions
|
|
134
|
+
+ coll_partner_offset
|
|
135
|
+
+ n_coll_transitions
|
|
136
|
+
- 1
|
|
137
|
+
)
|
|
138
|
+
if (
|
|
139
|
+
9 + comment_offset + n_levels + n_rad_transitions + coll_partner_offset
|
|
140
|
+
<= i
|
|
141
|
+
<= last_coll_trans_i
|
|
142
|
+
):
|
|
116
143
|
coll_trans_data = [float(string) for string in line.split()]
|
|
117
|
-
up = next(
|
|
118
|
-
|
|
119
|
-
|
|
144
|
+
up = next(
|
|
145
|
+
level for level in levels if level.index == coll_trans_data[1] - 1
|
|
146
|
+
)
|
|
147
|
+
low = next(
|
|
148
|
+
level for level in levels if level.index == coll_trans_data[2] - 1
|
|
149
|
+
)
|
|
150
|
+
K21_data = np.array(coll_trans_data[3:]) * constants.centi**3
|
|
120
151
|
coll_trans = atomic_transition.CollisionalTransition(
|
|
121
|
-
|
|
122
|
-
|
|
152
|
+
up=up, low=low, K21_data=K21_data, Tkin_data=coll_temperatures
|
|
153
|
+
)
|
|
123
154
|
coll_transitions[coll_ID].append(coll_trans)
|
|
124
155
|
if i == last_coll_trans_i:
|
|
125
|
-
coll_partner_offset += 4+n_coll_transitions
|
|
156
|
+
coll_partner_offset += 4 + n_coll_transitions
|
|
126
157
|
continue
|
|
127
158
|
datafile.close()
|
|
128
|
-
return {
|
|
129
|
-
|
|
159
|
+
return {
|
|
160
|
+
"levels": levels,
|
|
161
|
+
"radiative transitions": rad_transitions,
|
|
162
|
+
"collisional transitions": coll_transitions,
|
|
163
|
+
"quantum numbers": quantum_numbers,
|
|
164
|
+
}
|