lightweaver 0.15.0__cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.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.

Potentially problematic release.


This version of lightweaver might be problematic. Click here for more details.

Files changed (69) hide show
  1. lightweaver/Data/AbundancesAsplund09.pickle +0 -0
  2. lightweaver/Data/AtomicMassesNames.pickle +0 -0
  3. lightweaver/Data/Barklem_dfdata.dat +41 -0
  4. lightweaver/Data/Barklem_pddata.dat +40 -0
  5. lightweaver/Data/Barklem_spdata.dat +46 -0
  6. lightweaver/Data/DefaultMolecules/C2.molecule +27 -0
  7. lightweaver/Data/DefaultMolecules/CH/CH_X-A.asc +46409 -0
  8. lightweaver/Data/DefaultMolecules/CH/CH_X-A_12.asc +28322 -0
  9. lightweaver/Data/DefaultMolecules/CH/CH_X-B.asc +4272 -0
  10. lightweaver/Data/DefaultMolecules/CH/CH_X-B_12.asc +2583 -0
  11. lightweaver/Data/DefaultMolecules/CH/CH_X-C.asc +20916 -0
  12. lightweaver/Data/DefaultMolecules/CH/CH_X-C_12.asc +13106 -0
  13. lightweaver/Data/DefaultMolecules/CH.molecule +35 -0
  14. lightweaver/Data/DefaultMolecules/CN.molecule +30 -0
  15. lightweaver/Data/DefaultMolecules/CO/vmax=3_Jmax=49_dv=1_26 +296 -0
  16. lightweaver/Data/DefaultMolecules/CO/vmax=9_Jmax=120_dv=1_26 +2162 -0
  17. lightweaver/Data/DefaultMolecules/CO.molecule +30 -0
  18. lightweaver/Data/DefaultMolecules/CO_NLTE.molecule +29 -0
  19. lightweaver/Data/DefaultMolecules/CaH.molecule +29 -0
  20. lightweaver/Data/DefaultMolecules/H2+.molecule +27 -0
  21. lightweaver/Data/DefaultMolecules/H2.molecule +27 -0
  22. lightweaver/Data/DefaultMolecules/H2O.molecule +27 -0
  23. lightweaver/Data/DefaultMolecules/HF.molecule +29 -0
  24. lightweaver/Data/DefaultMolecules/LiH.molecule +27 -0
  25. lightweaver/Data/DefaultMolecules/MgH.molecule +34 -0
  26. lightweaver/Data/DefaultMolecules/N2.molecule +28 -0
  27. lightweaver/Data/DefaultMolecules/NH.molecule +27 -0
  28. lightweaver/Data/DefaultMolecules/NO.molecule +27 -0
  29. lightweaver/Data/DefaultMolecules/O2.molecule +27 -0
  30. lightweaver/Data/DefaultMolecules/OH.molecule +27 -0
  31. lightweaver/Data/DefaultMolecules/SiO.molecule +26 -0
  32. lightweaver/Data/DefaultMolecules/TiO.molecule +30 -0
  33. lightweaver/Data/Quadratures.pickle +0 -0
  34. lightweaver/Data/pf_Kurucz.input +0 -0
  35. lightweaver/DefaultIterSchemes/.placeholder +0 -0
  36. lightweaver/DefaultIterSchemes/SimdImpl_AVX2FMA.cpython-312-x86_64-linux-gnu.so +0 -0
  37. lightweaver/DefaultIterSchemes/SimdImpl_AVX512.cpython-312-x86_64-linux-gnu.so +0 -0
  38. lightweaver/DefaultIterSchemes/SimdImpl_SSE2.cpython-312-x86_64-linux-gnu.so +0 -0
  39. lightweaver/LwCompiled.cpython-312-x86_64-linux-gnu.so +0 -0
  40. lightweaver/__init__.py +33 -0
  41. lightweaver/atmosphere.py +1640 -0
  42. lightweaver/atomic_model.py +852 -0
  43. lightweaver/atomic_set.py +1286 -0
  44. lightweaver/atomic_table.py +653 -0
  45. lightweaver/barklem.py +151 -0
  46. lightweaver/benchmark.py +113 -0
  47. lightweaver/broadening.py +605 -0
  48. lightweaver/collisional_rates.py +337 -0
  49. lightweaver/config.py +106 -0
  50. lightweaver/constants.py +22 -0
  51. lightweaver/crtaf.py +197 -0
  52. lightweaver/fal.py +440 -0
  53. lightweaver/iterate_ctx.py +241 -0
  54. lightweaver/iteration_update.py +134 -0
  55. lightweaver/libenkiTS.so +0 -0
  56. lightweaver/molecule.py +225 -0
  57. lightweaver/multi.py +113 -0
  58. lightweaver/nr_update.py +106 -0
  59. lightweaver/rh_atoms.py +19743 -0
  60. lightweaver/simd_management.py +42 -0
  61. lightweaver/utils.py +504 -0
  62. lightweaver/version.py +34 -0
  63. lightweaver/wittmann.py +1375 -0
  64. lightweaver/zeeman.py +157 -0
  65. lightweaver-0.15.0.dist-info/METADATA +81 -0
  66. lightweaver-0.15.0.dist-info/RECORD +69 -0
  67. lightweaver-0.15.0.dist-info/WHEEL +6 -0
  68. lightweaver-0.15.0.dist-info/licenses/LICENSE +21 -0
  69. lightweaver-0.15.0.dist-info/top_level.txt +1 -0
lightweaver/fal.py ADDED
@@ -0,0 +1,440 @@
1
+ from typing import Callable
2
+
3
+ import astropy.units as u
4
+ import numpy as np
5
+
6
+ import lightweaver.constants as Const
7
+ from .atmosphere import Atmosphere, ScaleType
8
+
9
+ cmass = 10**(np.array([
10
+ -4.93574095E+00,
11
+ -4.93562460E+00,
12
+ -4.93550158E+00,
13
+ -4.93532753E+00,
14
+ -4.93513727E+00,
15
+ -4.93503189E+00,
16
+ -4.93491840E+00,
17
+ -4.93479300E+00,
18
+ -4.93465710E+00,
19
+ -4.93458509E+00,
20
+ -4.93451309E+00,
21
+ -4.93443680E+00,
22
+ -4.93435478E+00,
23
+ -4.93426752E+00,
24
+ -4.93417501E+00,
25
+ -4.93407583E+00,
26
+ -4.93394947E+00,
27
+ -4.93383646E+00,
28
+ -4.93373585E+00,
29
+ -4.93359184E+00,
30
+ -4.93341446E+00,
31
+ -4.93324804E+00,
32
+ -4.93304968E+00,
33
+ -4.93279409E+00,
34
+ -4.93241310E+00,
35
+ -4.93190384E+00,
36
+ -4.93113708E+00,
37
+ -4.93013287E+00,
38
+ -4.92838764E+00,
39
+ -4.92132998E+00,
40
+ -4.90772057E+00,
41
+ -4.87617874E+00,
42
+ -4.82721663E+00,
43
+ -4.76904154E+00,
44
+ -4.70482588E+00,
45
+ -4.64561558E+00,
46
+ -4.56636095E+00,
47
+ -4.45723915E+00,
48
+ -4.31962919E+00,
49
+ -4.18329859E+00,
50
+ -4.00349617E+00,
51
+ -3.80158830E+00,
52
+ -3.60500216E+00,
53
+ -3.37798548E+00,
54
+ -3.14050150E+00,
55
+ -2.88156867E+00,
56
+ -2.67674541E+00,
57
+ -2.49282169E+00,
58
+ -2.33261061E+00,
59
+ -2.16479850E+00,
60
+ -1.98761845E+00,
61
+ -1.78171456E+00,
62
+ -1.58602309E+00,
63
+ -1.42560005E+00,
64
+ -1.28381574E+00,
65
+ -1.14168072E+00,
66
+ -9.79987085E-01,
67
+ -7.80323803E-01,
68
+ -5.83481908E-01,
69
+ -3.89997512E-01,
70
+ -2.00394467E-01,
71
+ -1.52082862E-02,
72
+ 7.59830400E-02,
73
+ 1.65459096E-01,
74
+ 2.52803594E-01,
75
+ 3.37693125E-01,
76
+ 4.19847399E-01,
77
+ 4.98901486E-01,
78
+ 5.44588983E-01,
79
+ 5.88704407E-01,
80
+ 6.17215991E-01,
81
+ 6.44935131E-01,
82
+ 6.71832442E-01,
83
+ 6.97803915E-01,
84
+ 7.22732782E-01,
85
+ 7.46601224E-01,
86
+ 7.69470692E-01,
87
+ 7.91397929E-01,
88
+ 8.12412739E-01,
89
+ 8.32580209E-01,
90
+ 8.52005064E-01,
91
+ 8.70782733E-01]))
92
+
93
+ temp = np.array([
94
+ 1.000000E+05,
95
+ 9.560000E+04,
96
+ 9.082000E+04,
97
+ 8.389000E+04,
98
+ 7.593000E+04,
99
+ 7.134000E+04,
100
+ 6.615000E+04,
101
+ 6.017000E+04,
102
+ 5.328000E+04,
103
+ 4.939000E+04,
104
+ 4.542000E+04,
105
+ 4.118000E+04,
106
+ 3.659000E+04,
107
+ 3.215000E+04,
108
+ 2.797000E+04,
109
+ 2.406000E+04,
110
+ 2.042000E+04,
111
+ 1.793000E+04,
112
+ 1.628000E+04,
113
+ 1.452000E+04,
114
+ 1.308000E+04,
115
+ 1.219000E+04,
116
+ 1.144000E+04,
117
+ 1.085000E+04,
118
+ 1.034000E+04,
119
+ 9.983000E+03,
120
+ 9.735000E+03,
121
+ 9.587000E+03,
122
+ 9.458000E+03,
123
+ 9.358000E+03,
124
+ 9.228000E+03,
125
+ 8.988000E+03,
126
+ 8.635000E+03,
127
+ 8.273000E+03,
128
+ 7.970000E+03,
129
+ 7.780000E+03,
130
+ 7.600000E+03,
131
+ 7.410000E+03,
132
+ 7.220000E+03,
133
+ 7.080000E+03,
134
+ 6.910000E+03,
135
+ 6.740000E+03,
136
+ 6.570000E+03,
137
+ 6.370000E+03,
138
+ 6.180000E+03,
139
+ 5.950000E+03,
140
+ 5.760000E+03,
141
+ 5.570000E+03,
142
+ 5.380000E+03,
143
+ 5.160000E+03,
144
+ 4.900000E+03,
145
+ 4.680000E+03,
146
+ 4.560000E+03,
147
+ 4.520000E+03,
148
+ 4.500000E+03,
149
+ 4.510000E+03,
150
+ 4.540000E+03,
151
+ 4.610000E+03,
152
+ 4.690000E+03,
153
+ 4.780000E+03,
154
+ 4.880000E+03,
155
+ 4.990000E+03,
156
+ 5.060000E+03,
157
+ 5.150000E+03,
158
+ 5.270000E+03,
159
+ 5.410000E+03,
160
+ 5.580000E+03,
161
+ 5.790000E+03,
162
+ 5.980000E+03,
163
+ 6.180000E+03,
164
+ 6.340000E+03,
165
+ 6.520000E+03,
166
+ 6.720000E+03,
167
+ 6.980000E+03,
168
+ 7.280000E+03,
169
+ 7.590000E+03,
170
+ 7.900000E+03,
171
+ 8.220000E+03,
172
+ 8.540000E+03,
173
+ 8.860000E+03,
174
+ 9.140000E+03,
175
+ 9.400000E+03])
176
+
177
+ ne = np.array([
178
+ 1.251891E+10,
179
+ 1.304293E+10,
180
+ 1.366348E+10,
181
+ 1.467464E+10,
182
+ 1.603707E+10,
183
+ 1.694766E+10,
184
+ 1.811689E+10,
185
+ 1.969550E+10,
186
+ 2.192829E+10,
187
+ 2.344633E+10,
188
+ 2.523785E+10,
189
+ 2.748732E+10,
190
+ 3.043595E+10,
191
+ 3.394113E+10,
192
+ 3.804151E+10,
193
+ 4.291177E+10,
194
+ 4.860836E+10,
195
+ 5.337548E+10,
196
+ 5.700496E+10,
197
+ 6.137226E+10,
198
+ 6.520094E+10,
199
+ 6.747161E+10,
200
+ 6.918466E+10,
201
+ 6.991762E+10,
202
+ 6.967801E+10,
203
+ 6.848673E+10,
204
+ 6.599262E+10,
205
+ 6.265075E+10,
206
+ 5.801540E+10,
207
+ 5.841143E+10,
208
+ 6.141942E+10,
209
+ 6.651616E+10,
210
+ 7.168647E+10,
211
+ 7.561758E+10,
212
+ 7.846423E+10,
213
+ 8.095357E+10,
214
+ 8.445100E+10,
215
+ 8.838377E+10,
216
+ 9.185673E+10,
217
+ 9.612962E+10,
218
+ 1.031897E+11,
219
+ 1.137706E+11,
220
+ 1.220873E+11,
221
+ 1.280117E+11,
222
+ 1.340907E+11,
223
+ 1.308237E+11,
224
+ 1.229867E+11,
225
+ 1.111659E+11,
226
+ 9.742137E+10,
227
+ 8.363294E+10,
228
+ 7.544027E+10,
229
+ 9.114873E+10,
230
+ 1.307890E+11,
231
+ 1.818187E+11,
232
+ 2.441017E+11,
233
+ 3.294358E+11,
234
+ 4.648930E+11,
235
+ 7.167248E+11,
236
+ 1.099721E+12,
237
+ 1.680047E+12,
238
+ 2.557346E+12,
239
+ 3.880555E+12,
240
+ 4.803401E+12,
241
+ 5.984860E+12,
242
+ 7.584832E+12,
243
+ 9.816085E+12,
244
+ 1.329338E+13,
245
+ 1.950519E+13,
246
+ 2.749041E+13,
247
+ 4.028244E+13,
248
+ 5.456858E+13,
249
+ 7.641340E+13,
250
+ 1.099800E+14,
251
+ 1.719226E+14,
252
+ 2.789487E+14,
253
+ 4.446967E+14,
254
+ 6.869667E+14,
255
+ 1.041290E+15,
256
+ 1.531806E+15,
257
+ 2.194603E+15,
258
+ 2.952398E+15,
259
+ 3.831726E+15])
260
+
261
+ vel = np.zeros_like(ne)
262
+
263
+ vturb = np.array([
264
+ 1.068096E+01,
265
+ 1.061132E+01,
266
+ 1.053191E+01,
267
+ 1.040904E+01,
268
+ 1.025485E+01,
269
+ 1.015883E+01,
270
+ 1.004315E+01,
271
+ 9.899261E+00,
272
+ 9.717166E+00,
273
+ 9.614243E+00,
274
+ 9.506225E+00,
275
+ 9.380583E+00,
276
+ 9.230186E+00,
277
+ 9.065828E+00,
278
+ 8.889256E+00,
279
+ 8.700418E+00,
280
+ 8.494678E+00,
281
+ 8.342731E+00,
282
+ 8.234054E+00,
283
+ 8.105730E+00,
284
+ 7.987370E+00,
285
+ 7.905294E+00,
286
+ 7.829440E+00,
287
+ 7.762707E+00,
288
+ 7.696761E+00,
289
+ 7.642009E+00,
290
+ 7.591289E+00,
291
+ 7.547351E+00,
292
+ 7.492713E+00,
293
+ 7.452542E+00,
294
+ 7.399466E+00,
295
+ 7.268274E+00,
296
+ 7.044414E+00,
297
+ 6.823160E+00,
298
+ 6.614389E+00,
299
+ 6.431674E+00,
300
+ 6.207403E+00,
301
+ 5.932102E+00,
302
+ 5.590575E+00,
303
+ 5.296849E+00,
304
+ 4.926045E+00,
305
+ 4.504405E+00,
306
+ 4.060300E+00,
307
+ 3.552633E+00,
308
+ 3.053286E+00,
309
+ 2.595622E+00,
310
+ 2.254545E+00,
311
+ 2.000838E+00,
312
+ 1.772230E+00,
313
+ 1.533542E+00,
314
+ 1.368657E+00,
315
+ 1.168133E+00,
316
+ 9.947371E-01,
317
+ 8.897392E-01,
318
+ 8.043894E-01,
319
+ 7.225354E-01,
320
+ 6.536559E-01,
321
+ 5.555816E-01,
322
+ 5.217747E-01,
323
+ 5.728015E-01,
324
+ 6.274118E-01,
325
+ 8.043706E-01,
326
+ 8.929698E-01,
327
+ 9.950050E-01,
328
+ 1.093189E+00,
329
+ 1.195529E+00,
330
+ 1.291880E+00,
331
+ 1.395714E+00,
332
+ 1.448816E+00,
333
+ 1.506637E+00,
334
+ 1.541506E+00,
335
+ 1.579327E+00,
336
+ 1.621151E+00,
337
+ 1.651916E+00,
338
+ 1.677151E+00,
339
+ 1.696164E+00,
340
+ 1.716951E+00,
341
+ 1.733641E+00,
342
+ 1.746632E+00,
343
+ 1.760494E+00,
344
+ 1.785877E+00,
345
+ 1.806787E+00])
346
+
347
+ nh = np.array([
348
+ [1.3575E+05, 6.8537E-02, 4.1543E-02, 5.2083E-02, 7.0588E-02, 1.0457E+10],
349
+ [1.8120E+05, 8.9778E-02, 5.2296E-02, 6.4357E-02, 8.6325E-02, 1.0940E+10],
350
+ [2.2180E+05, 1.0849E-01, 6.1845E-02, 7.5786E-02, 1.0157E-01, 1.1518E+10],
351
+ [3.0033E+05, 1.4368E-01, 7.9102E-02, 9.6471E-02, 1.2932E-01, 1.2472E+10],
352
+ [4.6242E+05, 2.1339E-01, 1.1066E-01, 1.3336E-01, 1.7819E-01, 1.3782E+10],
353
+ [6.9366E+05, 3.1003E-01, 1.5054E-01, 1.7684E-01, 2.3301E-01, 1.4666E+10],
354
+ [1.3849E+06, 5.9161E-01, 2.5732E-01, 2.8646E-01, 3.6466E-01, 1.5806E+10],
355
+ [4.2158E+06, 1.7082E+00, 6.3842E-01, 6.5716E-01, 7.9078E-01, 1.7348E+10],
356
+ [1.7438E+07, 6.7547E+00, 2.0988E+00, 2.0121E+00, 2.2989E+00, 1.9507E+10],
357
+ [4.1507E+07, 1.5910E+01, 4.3394E+00, 4.0155E+00, 4.4810E+00, 2.0955E+10],
358
+ [9.0420E+07, 3.5031E+01, 8.0639E+00, 7.2076E+00, 7.8911E+00, 2.2651E+10],
359
+ [1.9192E+08, 7.7556E+01, 1.4038E+01, 1.2016E+01, 1.2892E+01, 2.4761E+10],
360
+ [3.9573E+08, 1.7367E+02, 2.2333E+01, 1.7985E+01, 1.8816E+01, 2.7491E+10],
361
+ [7.6782E+08, 3.8073E+02, 3.2088E+01, 2.3695E+01, 2.4001E+01, 3.0720E+10],
362
+ [1.3781E+09, 7.8156E+02, 4.0771E+01, 2.6967E+01, 2.6251E+01, 3.4498E+10],
363
+ [2.2770E+09, 1.4505E+03, 4.5906E+01, 2.6811E+01, 2.5012E+01, 3.8972E+10],
364
+ [3.7225E+09, 2.6394E+03, 4.9540E+01, 2.5431E+01, 2.3463E+01, 4.4299E+10],
365
+ [5.2214E+09, 3.9059E+03, 5.0812E+01, 2.6042E+01, 2.4141E+01, 4.8930E+10],
366
+ [6.6626E+09, 5.1186E+03, 5.2395E+01, 2.7202E+01, 2.6187E+01, 5.2534E+10],
367
+ [8.8304E+09, 6.9532E+03, 5.5943E+01, 2.9634E+01, 2.9744E+01, 5.6932E+10],
368
+ [1.1553E+10, 9.2281E+03, 6.4637E+01, 3.4923E+01, 3.7451E+01, 6.0910E+10],
369
+ [1.4098E+10, 1.1403E+04, 7.3911E+01, 4.0362E+01, 4.4988E+01, 6.3407E+10],
370
+ [1.7114E+10, 1.4020E+04, 8.5943E+01, 4.5854E+01, 5.1452E+01, 6.5364E+10],
371
+ [2.0838E+10, 1.7311E+04, 1.0161E+02, 5.2368E+01, 5.8441E+01, 6.6372E+10],
372
+ [2.5891E+10, 2.1876E+04, 1.2297E+02, 6.0053E+01, 6.5132E+01, 6.6303E+10],
373
+ [3.1402E+10, 2.6917E+04, 1.4694E+02, 6.8666E+01, 7.2591E+01, 6.5146E+10],
374
+ [3.8232E+10, 3.3232E+04, 1.7632E+02, 7.7801E+01, 7.8598E+01, 6.2533E+10],
375
+ [4.5560E+10, 3.9880E+04, 2.0719E+02, 8.6650E+01, 8.3415E+01, 5.9011E+10],
376
+ [5.5102E+10, 4.8458E+04, 2.4757E+02, 9.7736E+01, 8.8989E+01, 5.4017E+10],
377
+ [5.7964E+10, 5.4260E+04, 2.8263E+02, 1.0840E+02, 9.7220E+01, 5.4344E+10],
378
+ [5.9182E+10, 6.1715E+04, 3.3533E+02, 1.2464E+02, 1.1103E+02, 5.7485E+10],
379
+ [6.5344E+10, 7.4390E+04, 4.4226E+02, 1.5492E+02, 1.3655E+02, 6.2829E+10],
380
+ [8.2151E+10, 8.9723E+04, 6.0246E+02, 1.9568E+02, 1.7001E+02, 6.8334E+10],
381
+ [1.1036E+11, 1.0429E+05, 7.9208E+02, 2.3960E+02, 2.0478E+02, 7.2705E+10],
382
+ [1.5001E+11, 1.1653E+05, 9.9266E+02, 2.8278E+02, 2.3757E+02, 7.6065E+10],
383
+ [1.9295E+11, 1.2641E+05, 1.1790E+03, 3.2206E+02, 2.6657E+02, 7.8977E+10],
384
+ [2.6230E+11, 1.3886E+05, 1.4373E+03, 3.7651E+02, 3.0599E+02, 8.2849E+10],
385
+ [3.8968E+11, 1.5218E+05, 1.7727E+03, 4.4648E+02, 3.5489E+02, 8.7015E+10],
386
+ [6.2100E+11, 1.6352E+05, 2.1393E+03, 5.2332E+02, 4.0632E+02, 9.0571E+10],
387
+ [9.5313E+11, 1.7702E+05, 2.5351E+03, 6.1111E+02, 4.6521E+02, 9.4755E+10],
388
+ [1.6358E+12, 2.0103E+05, 3.1704E+03, 7.5945E+02, 5.6539E+02, 1.0158E+11],
389
+ [2.9344E+12, 2.3968E+05, 4.1359E+03, 9.9542E+02, 7.2522E+02, 1.1172E+11],
390
+ [5.1240E+12, 2.7229E+05, 5.0498E+03, 1.2318E+03, 8.8165E+02, 1.1951E+11],
391
+ [9.6535E+12, 2.9688E+05, 5.8820E+03, 1.4659E+03, 1.0325E+03, 1.2464E+11],
392
+ [1.8438E+13, 3.2259E+05, 6.7349E+03, 1.7248E+03, 1.1997E+03, 1.2928E+11],
393
+ [3.6505E+13, 3.0568E+05, 6.6484E+03, 1.7553E+03, 1.2102E+03, 1.2320E+11],
394
+ [6.1457E+13, 2.6707E+05, 5.9364E+03, 1.6013E+03, 1.0998E+03, 1.1141E+11],
395
+ [9.7948E+13, 2.1143E+05, 4.7619E+03, 1.3051E+03, 8.9495E+02, 9.3966E+10],
396
+ [1.4797E+14, 1.5107E+05, 3.4275E+03, 9.4933E+02, 6.5079E+02, 7.3185E+10],
397
+ [2.2913E+14, 9.1943E+04, 2.0952E+03, 5.8468E+02, 4.0108E+02, 4.8909E+10],
398
+ [3.6573E+14, 4.4954E+04, 1.0268E+03, 2.8785E+02, 1.9781E+02, 2.4559E+10],
399
+ [6.2095E+14, 2.5504E+04, 5.8319E+02, 1.6405E+02, 1.1310E+02, 1.0707E+10],
400
+ [1.0059E+15, 2.1516E+04, 4.9230E+02, 1.3888E+02, 9.6129E+01, 5.9846E+09],
401
+ [1.4721E+15, 2.5057E+04, 5.7350E+02, 1.6223E+02, 1.1268E+02, 4.9014E+09],
402
+ [2.0529E+15, 3.1103E+04, 7.1209E+02, 2.0204E+02, 1.4078E+02, 4.4674E+09],
403
+ [2.8443E+15, 4.5788E+04, 1.0487E+03, 2.9876E+02, 2.0880E+02, 4.8749E+09],
404
+ [4.1045E+15, 7.8697E+04, 1.8038E+03, 5.1748E+02, 3.6298E+02, 6.0219E+09],
405
+ [6.4161E+15, 1.8279E+05, 4.2000E+03, 1.2231E+03, 8.6292E+02, 9.5137E+09],
406
+ [9.9334E+15, 4.3826E+05, 1.0139E+04, 3.0336E+03, 2.1574E+03, 1.6045E+10],
407
+ [1.5216E+16, 1.0786E+06, 2.5422E+04, 7.9600E+03, 5.7304E+03, 2.9160E+10],
408
+ [2.3024E+16, 2.7091E+06, 6.6875E+04, 2.2366E+04, 1.6388E+04, 5.7743E+10],
409
+ [3.4369E+16, 6.8981E+06, 1.8667E+05, 6.7490E+04, 5.0629E+04, 1.2481E+11],
410
+ [4.1710E+16, 1.1619E+07, 3.3576E+05, 1.2627E+05, 9.6131E+04, 1.9896E+11],
411
+ [5.0148E+16, 2.1014E+07, 6.5910E+05, 2.5792E+05, 1.9970E+05, 3.4826E+11],
412
+ [5.9713E+16, 4.2209E+07, 1.4620E+06, 5.9702E+05, 4.7139E+05, 6.9089E+11],
413
+ [7.0420E+16, 8.8974E+07, 3.4558E+06, 1.4750E+06, 1.1892E+06, 1.4460E+12],
414
+ [8.2158E+16, 2.0209E+08, 8.9288E+06, 3.9956E+06, 3.2940E+06, 3.2132E+12],
415
+ [9.4511E+16, 5.0160E+08, 2.5675E+07, 1.2109E+07, 1.0232E+07, 7.4971E+12],
416
+ [1.0142E+17, 1.0304E+09, 5.9280E+07, 2.9162E+07, 2.5133E+07, 1.4201E+13],
417
+ [1.0836E+17, 2.0887E+09, 1.3542E+08, 6.9500E+07, 6.1092E+07, 2.5616E+13],
418
+ [1.1260E+17, 3.5191E+09, 2.4944E+08, 1.3213E+08, 1.1787E+08, 3.8905E+13],
419
+ [1.1656E+17, 6.0988E+09, 4.7555E+08, 2.6052E+08, 2.3606E+08, 5.9653E+13],
420
+ [1.2019E+17, 1.0794E+10, 9.3061E+08, 5.2815E+08, 4.8646E+08, 9.1990E+13],
421
+ [1.2266E+17, 2.1229E+10, 2.0662E+09, 1.2237E+09, 1.1495E+09, 1.5246E+14],
422
+ [1.2435E+17, 4.3284E+10, 4.7954E+09, 2.9718E+09, 2.8511E+09, 2.5766E+14],
423
+ [1.2556E+17, 8.4898E+10, 1.0640E+10, 6.8842E+09, 6.7376E+09, 4.2126E+14],
424
+ [1.2674E+17, 1.5801E+11, 2.2182E+10, 1.4934E+10, 1.4887E+10, 6.6104E+14],
425
+ [1.2739E+17, 2.8457E+11, 4.4505E+10, 3.1118E+10, 3.1567E+10, 1.0125E+15],
426
+ [1.2768E+17, 4.8921E+11, 8.4550E+10, 6.1220E+10, 6.3118E+10, 1.4999E+15],
427
+ [1.2786E+17, 8.0810E+11, 1.5323E+11, 1.1461E+11, 1.1995E+11, 2.1593E+15],
428
+ [1.2836E+17, 1.2215E+12, 2.4986E+11, 1.9190E+11, 2.0333E+11, 2.9137E+15],
429
+ [1.2887E+17, 1.7545E+12, 3.8349E+11, 3.0146E+11, 3.2285E+11, 3.7897E+15],
430
+ ]).T
431
+
432
+ Falc82: Callable[[], Atmosphere] = lambda: Atmosphere.make_1d(
433
+ ScaleType.ColumnMass,
434
+ depthScale=(cmass << u.Unit('g cm-2')).to('kg m-2').value,
435
+ temperature=np.copy(temp),
436
+ ne=(ne << u.Unit('cm-3')).to('m-3').value,
437
+ vlos=(vel << u.Unit('km/s')).to('m/s').value,
438
+ vturb=(vturb << u.Unit('km/s')).to('m/s').value,
439
+ hydrogenPops=(nh << u.Unit('cm-3')).to('m-3').value,
440
+ )
@@ -0,0 +1,241 @@
1
+ import time
2
+ from typing import TYPE_CHECKING, Optional, Type
3
+
4
+ from .iteration_update import IterationUpdate
5
+
6
+ if TYPE_CHECKING:
7
+ from . import Context
8
+
9
+ class ConvergenceCriteria:
10
+ '''
11
+ Abstract base class for determining convergence inside `iterate_ctx_se`. A
12
+ derived variant of this class will be instantiated by `iterate_ctx_se`
13
+ dependent upon its arguments. The default implementation is
14
+ `DefaultConvergenceCriteria`.
15
+
16
+ Parameters
17
+ ----------
18
+ ctx : Context
19
+ The context being iterated.
20
+ JTol : float
21
+ The value of JTol passed to `iterate_ctx_se`.
22
+ popsTol : float
23
+ The value of popsTol passed to `iterate_ctx_se`.
24
+ rhoTol : float or None
25
+ The value of rhoTol passed to `iterate_ctx_se`.
26
+ '''
27
+ def __init__(self, ctx: 'Context', JTol: float, popsTol: float, rhoTol: Optional[float]):
28
+ raise NotImplementedError
29
+
30
+ def is_converged(self, JUpdate: IterationUpdate, popsUpdate: IterationUpdate,
31
+ prdUpdate: Optional[IterationUpdate]) -> bool:
32
+ '''
33
+ This function takes the IterationUpdate objects from
34
+ `ctx.formal_sol_gamma_matrices` and `ctx.stat_equil` and optionally from
35
+ `ctx.prd_redistribute` (or None). Should return a bool indicated
36
+ whether the Context is sufficiently converged.
37
+ '''
38
+ raise NotImplementedError
39
+
40
+
41
+ class DefaultConvergenceCriteria(ConvergenceCriteria):
42
+ '''
43
+ Default ConvergenceCriteria implementation. Usually sufficient for
44
+ statistical equilibrium problems, but you may occasionally need to override
45
+ this.
46
+
47
+ Parameters
48
+ ----------
49
+ ctx : Context
50
+ The context being iterated.
51
+ JTol : float
52
+ The value of JTol passed to `iterate_ctx_se`.
53
+ popsTol : float
54
+ The value of popsTol passed to `iterate_ctx_se`.
55
+ rhoTol : float or None
56
+ The value of rhoTol passed to `iterate_ctx_se`.
57
+ '''
58
+
59
+ def __init__(self, ctx: 'Context', JTol: float, popsTol: float, rhoTol: Optional[float]):
60
+ self.ctx = ctx
61
+ self.JTol = JTol
62
+ self.popsTol = popsTol
63
+ self.rhoTol = rhoTol
64
+
65
+ def is_converged(self, JUpdate: IterationUpdate, popsUpdate: IterationUpdate,
66
+ prdUpdate: Optional[IterationUpdate]) -> bool:
67
+ '''
68
+ Returns whether the context is converged.
69
+ '''
70
+ updates = [JUpdate, popsUpdate]
71
+ if prdUpdate is not None:
72
+ updates.append(prdUpdate)
73
+
74
+ terminate = True
75
+ for update in updates:
76
+ terminate = terminate and (update.dJMax < self.JTol)
77
+ terminate = terminate and (update.dPopsMax < self.popsTol)
78
+ if prdUpdate and self.rhoTol is not None:
79
+ terminate = terminate and (update.dRhoMax < self.rhoTol)
80
+ terminate = terminate and self.ctx.crswDone
81
+
82
+ return terminate
83
+
84
+
85
+ def iterate_ctx_se(ctx: 'Context', Nscatter: int=3, NmaxIter: int=2000,
86
+ prd: bool=False, JTol: float=5e-3, popsTol: float=1e-3,
87
+ rhoTol: Optional[float]=None, prdIterTol: float=1e-2,
88
+ maxPrdSubIter: int=3, printInterval: float=0.2,
89
+ quiet: bool=False,
90
+ convergence: Optional[Type[ConvergenceCriteria]]=None,
91
+ returnFinalConvergence: bool=False):
92
+ '''
93
+ Iterate a configured Context towards statistical equilibrium solution.
94
+
95
+ Parameters
96
+ ----------
97
+ ctx : Context
98
+ The context to iterate.
99
+ Nscatter : int, optional
100
+ The number of lambda iterations to perform for an initial estimate of J
101
+ (default: 3).
102
+ NmaxIter : int, optional
103
+ The maximum number of iterations (including Nscatter) to take (default:
104
+ 2000).
105
+ prd: bool, optional
106
+ Whether to perform PRD subiterations to estimate rho for PRD lines
107
+ (default: False).
108
+ JTol: float, optional
109
+ The maximum relative change in J from one iteration to the next
110
+ (default: 5e-3).
111
+ popsTol: float, optional
112
+ The maximum relative change in an atomic population from one iteration
113
+ to the next (default: 1e-3).
114
+ rhoTol: float, optional
115
+ The maximum relative change in rho for a PRD line on the final
116
+ subiteration from one iteration to the next. If None, the change in rho
117
+ will not be considered in judging convergence (default: None).
118
+ prdIterTol: float, optional
119
+ The maximum relative change in rho for a PRD line below which PRD
120
+ subiterations will cease for this iteration (default: 1e-2).
121
+ maxPrdSubIter : int, optional
122
+ The maximum number of PRD subiterations to make, whether or not rho has
123
+ reached the tolerance of prdIterTol (which isn't necessary every
124
+ iteration). (Default: 3)
125
+ printInterval : float, optional
126
+ The interval between printing the update size information in seconds. A
127
+ value of 0.0 will print every iteration (default: 0.2).
128
+ quiet : bool, optional
129
+ Overrides any other print arguments and iterates silently if True.
130
+ (Default: False).
131
+ convergence : derived ConvergenceCriteria class, optional
132
+ The ConvergenceCriteria version to be used in determining convergence.
133
+ Will be instantiated by this function, and the `is_converged` method
134
+ will then be used. (Default: DefaultConvergenceCriteria).
135
+ returnFinalConvergence : bool, optional
136
+ Whether to return the IterationUpdate objects used in the final
137
+ convergence decision, if True, these will be returned in a list as the
138
+ second return value. (Default: False).
139
+
140
+ Returns
141
+ -------
142
+ it : int
143
+ The number of iterations taken.
144
+ finalIterationUpdates : List[IterationUpdate], optional
145
+ The final IterationUpdates computed, if requested by `returnFinalConvergence`.
146
+ '''
147
+
148
+ prevPrint = 0.0
149
+ printNow = True
150
+ alwaysPrint = (printInterval == 0.0)
151
+ startTime = time.time()
152
+
153
+ if convergence is None:
154
+ convergence = DefaultConvergenceCriteria
155
+ conv = convergence(ctx, JTol, popsTol, rhoTol)
156
+
157
+ for it in range(NmaxIter):
158
+ JUpdate : IterationUpdate = ctx.formal_sol_gamma_matrices()
159
+ if (not quiet and
160
+ (alwaysPrint or ((now := time.time()) >= prevPrint + printInterval))):
161
+ printNow = True
162
+ if not alwaysPrint:
163
+ prevPrint = now
164
+
165
+ if not quiet and printNow:
166
+ print(f'-- Iteration {it}:')
167
+ print(JUpdate.compact_representation())
168
+
169
+ if it < Nscatter:
170
+ if not quiet and printNow:
171
+ print(' (Lambda iterating background)')
172
+ # NOTE(cmo): reset print state
173
+ printNow = False
174
+ continue
175
+
176
+ popsUpdate : IterationUpdate = ctx.stat_equil()
177
+ if not quiet and printNow:
178
+ print(popsUpdate.compact_representation())
179
+
180
+ dRhoUpdate : Optional[IterationUpdate]
181
+ if prd:
182
+ dRhoUpdate = ctx.prd_redistribute(maxIter=maxPrdSubIter, tol=prdIterTol)
183
+ if not quiet and printNow and dRhoUpdate is not None:
184
+ print(dRhoUpdate.compact_representation())
185
+ else:
186
+ dRhoUpdate = None
187
+
188
+ terminate = conv.is_converged(JUpdate, popsUpdate, dRhoUpdate)
189
+
190
+ if terminate:
191
+ if not quiet:
192
+ endTime = time.time()
193
+ duration = endTime - startTime
194
+ line = '-' * 80
195
+ if printNow:
196
+ print('Final Iteration shown above.')
197
+ else:
198
+ print(line)
199
+ print(f'Final Iteration: {it}')
200
+ print(line)
201
+ print(JUpdate.compact_representation())
202
+ print(popsUpdate.compact_representation())
203
+ if prd and dRhoUpdate is not None:
204
+ print(dRhoUpdate.compact_representation())
205
+ print(line)
206
+ print(f'Context converged to statistical equilibrium in {it}'
207
+ f' iterations after {duration:.2f} s.')
208
+ print(line)
209
+ if returnFinalConvergence:
210
+ finalConvergence = [JUpdate, popsUpdate]
211
+ if prd and dRhoUpdate is not None:
212
+ finalConvergence.append(dRhoUpdate)
213
+ return it, finalConvergence
214
+ else:
215
+ return it
216
+
217
+ # NOTE(cmo): reset print state
218
+ printNow = False
219
+ else:
220
+ if not quiet:
221
+ line = '-' * 80
222
+ endTime = time.time()
223
+ duration = endTime - startTime
224
+ print(line)
225
+ print(f'Final Iteration: {it}')
226
+ print(line)
227
+ print(JUpdate.compact_representation())
228
+ print(popsUpdate.compact_representation())
229
+ if prd and dRhoUpdate is not None:
230
+ print(dRhoUpdate.compact_representation())
231
+ print(line)
232
+ print(f'Context FAILED to converge to statistical equilibrium after {it}'
233
+ f' iterations (took {duration:.2f} s).')
234
+ print(line)
235
+ if returnFinalConvergence:
236
+ finalConvergence = [JUpdate, popsUpdate]
237
+ if prd and dRhoUpdate is not None:
238
+ finalConvergence.append(dRhoUpdate)
239
+ return it, finalConvergence
240
+ else:
241
+ return it