-
Notifications
You must be signed in to change notification settings - Fork 1
/
line_finder.py
152 lines (112 loc) · 5.06 KB
/
line_finder.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from db import *
from astroquery.nist import Nist
from astroquery.atomic import AtomicLineList
def atline(lwl, rwl, unit, elements=None, source='ALL'):
'''
Function to retrieve spectral lines from the Atomic Line databases.
Input and output is given in Air conditions.
Example: atline(lwl=4550,rwl=4576,unit='aa',elements='Si III',source='ALL')
Parameters
----------
lwl : float/int
Sets the start wavelength.
rwl : float/int
Sets the end wavelength.
unit : str
Units of the input wavelengths in lwl and rwl (nm/angstrom).
elements : str, optional
Enter a string with the elements associated to the lines.
If 'OB' it will pick the most characteristic lines of OB stars.
source : str, optional
Choose between 'ALL' and 'NIST' databases. Default is 'ALL'
Note
----
The wavelength type is set to 'Air' and the wavelength accuracy to 20.
Returns
-------
List with the spectral lines.
'''
if lwl > rwl:
print('ERROR: left wavelength must be smaller than right wavelength. Exiting...')
return None
if unit in ['angstrom','aa','A']:
wavelength_range = (lwl*u.AA,rwl*u.AA)
elif unit in ['nanometer','nm']:
wavelength_range = (lwl*u.nm,rwl*u.nm)
else:
print('ERROR: wrong input units for the wavelength range. Exitting...')
return None
source = source.upper()
if elements == 'OB':
elements = 'H I, He I-II, O I-IV, C I-IV, Ne I-III, Fe I-III, N I-IV, \
Si I-IV, Mg I-IV, S I-IV, V I-II, Cr I-II, Ni I-II, Sc I-II, Ti I-II, \
Ca I-II, Na I-II'
if source == 'ALL':
columns = ('spec', 'type', 'conf', 'term', 'angm', 'prob')
query = AtomicLineList.query_object(wavelength_range=wavelength_range, wavelength_type='Air',
wavelength_accuracy=20, element_spectrum=elements, output_columns=columns,
cache=False)
if 'A_ki' in query.colnames and query['A_ki'].dtype != 'float64':
query['A_ki'] = [float(i.replace('None','nan')) for i in query['A_ki']]
elif source == 'NIST':
Nist.TIMEOUT = 60
query = Nist.query(minwav=wavelength_range[0], maxwav=wavelength_range[1],
wavelength_type='vac+air', linename=elements)
return query
def find_configurations(table, source, element, ion, configuration=None, term=None, lwl=None, rwl=None):
'''
Function to find the configurations of a given element and ion.
Example: find_configurations(table,'Si','III','3s.4p-3s.4d')
Example: find_configurations(table=tabla,source='ALL',element='Si',ion='III',
configuration='3s.4s-3s.4p',lwl=4550,rwl=4576)
Parameters
----------
table : astropy.table.Table
Table with the atomic lines.
source : str
Source of the atomic lines, 'NIST' or 'ALL'.
element : str
Element of the atomic lines.
ion : str
Ion of the atomic lines.
configuration : str, optional
Configuration of the atomic lines.
term : str, optional
Term of the atomic lines.
lwl : float/int, optional
Sets the start wavelength. Default is None.
rwl : float/int, optional
Sets the end wavelength. Default is None.
Returns
-------
List with the atomic lines.
'''
if source == 'NIST':
table.rename_column('Ritz','wl')
table.rename_column('Spectrum','spc')
table['config'] = [i['Lower level'].split('|')[0].strip() + '-' + i['Upper level'].split('|')[0].strip() for i in table]
table['term'] = [i['Lower level'].split('|')[1].strip().replace('*','o') + '-' + i['Upper level'].split('|')[1].strip().replace('*','o') for i in table]
elif source == 'ALL':
table.rename_column('LAMBDA AIR ANG','wl')
table.rename_column('SPECTRUM','spc')
table.rename_column('CONFIGURATION','config')
table.rename_column('TERM','term')
table['elem'] = [i.split(' ')[0] for i in table['spc']]
table['ion'] = [i.split(' ')[1] for i in table['spc']]
if configuration != None and term == None:
sub_table = table[(table['elem'] == element) & (table['ion'] == ion) & (table['config'] == configuration)]
elif term != None and configuration == None:
sub_table = table[(table['elem'] == element) & (table['ion'] == ion) & (table['term'] == term)]
elif term != None and configuration != None:
sub_table = table[(table['elem'] == element) & (table['ion'] == ion) & (table['config'] == configuration) & (table['term'] == term)]
sub_table.sort('term')
terms = list(set(sub_table['term']))
configs = list(set(sub_table['config']))
if lwl != None and rwl != None:
if lwl > rwl:
print('ERROR: left wavelength must be smaller than right wavelength. Exiting...')
return None
sub_table = sub_table[(sub_table['wl'] > lwl) & (sub_table['wl'] < rwl)]
if len(sub_table) == 0:
print('WARNING: no lines found in the given wavelength range.')
return sub_table, terms, configs