-
Notifications
You must be signed in to change notification settings - Fork 8
/
exomol_Xsec.py
169 lines (121 loc) · 4.22 KB
/
exomol_Xsec.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# **********************************************************************************************
# This script downloads all available xsec files for a given temperature T and resolution dnu, and
# includes the linelist name in the filename.
# For some molecules, the temperature has to be changed, because the maximal xsec temperature on
# the EXOMOL website is not the same as the maximal temperature of the line list data.
#
# Parameters are:
# -T : temperature in K, default 1500
# -dnu : wavelength resolution in cm^-1, default 0.1
# -S : species name (optional), if not specified then all files are downloaded
#
# The scripts uses the Firefox browser for the webpage navigation
#
# Date: May 2019
# Author: Simon Grimm
#
# *********************************************************************************************
import argparse
import numpy as np
from bs4 import BeautifulSoup
import requests
import pandas as pd
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import wget
import os
import exomol2
def main(T, dnu, S):
url="http://exomol.com/data/molecules/"
page = requests.get(url).text
soup = BeautifulSoup(page, "html.parser")
List = soup.find_all('a', attrs={"class" : "list-group-item link-list-group-item"})
exfile = "Exomol_xsec_species.dat"
#check if Exomol file exists and create it otherwise
exists = os.path.isfile(exfile)
if(exists == 0):
exomol2.main()
xList, xmList = np.loadtxt(exfile, usecols=(1,3), unpack=True, dtype=np.str)
#for i in range(len(xList)):
# print(xList[i], xmList[i])
for i in range(0, len(xList)):
print(i)
x = xList[i]
xm = xmList[i]
#Download ony one specific molecule:
if(len(S) > 0):
if(x != S):
continue
print("xsec", x, xm)
url = "http://exomol.com/xsec/" + x + "/"
#scan for the numin and numax values
page = requests.get(url).text
soup = BeautifulSoup(page, "html.parser")
List = soup.find_all('label', attrs={"for" : "id_numin"})
if(len(List) <= 0):
print("********Error xsec not available **********")
continue
l = str(List[0])
l = l.split("<sub>min</sub> (")[1]
l = l.split("cm<sup>-1</sup>")[0]
numin = int(l.split(" - ")[0])
numax = int(l.split(" - ")[1])
print(l, numin, numax)
#scan for the temperature values
List = soup.find_all('label', attrs={"for" : "id_T"})
l = str(List[0])
l = l.split("<em>T</em> (")[1]
l = l.split("K)")[0]
Tmin = int(l.split(" - ")[0])
Tmax = int(l.split(" - ")[1])
TT = T
if(Tmin > T):
TT = Tmin
if(Tmax < T):
TT = Tmax
#modify here the Temperature for molecules where the maximal temperature of the line list
#is less than the maximal temperature of the xsec data
if(x == "1H-14N-16O3"):
TT = 500
print("***************** modify T for 1H-14N-16O3 ***************")
print(l, Tmin, Tmax, TT)
driver = webdriver.Firefox()
driver.get(url)
spectra = driver.find_element_by_name("dnu")
spectra.send_keys(str(dnu))
spectra = driver.find_element_by_name("numin")
spectra.send_keys(numin)
spectra = driver.find_element_by_name("numax")
spectra.send_keys(numax - 1)
spectra = driver.find_element_by_name("T")
spectra.send_keys(TT)
spectra = driver.find_element_by_name("spoon_feed")
spectra.click()
spectra = driver.find_element_by_xpath("//input[@type='submit' and @value='Submit']")
spectra.click()
#filename on the EXOMOL webiste
filename = ("%s_%d-%d_%dK_%.6f.sigma" % (x, numin, numax - 1, TT, dnu))
#filename containing the line list name
xm2 = xm.replace("HITEMP", "HITEMP2010")
filename2 = ("%s_%d-%d_%dK_%.6f.sigma" % (xm2, numin, numax - 1, TT, dnu))
url = "http://exomol.com/results/" + filename
print(filename)
file = wget.download(url, filename2)
print("")
driver.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-T', '--T', type=int,
help='Temperature', default = 1500)
parser.add_argument('-dnu', '--dnu', type=float,
help='wavelength resolution', default = 0.1)
parser.add_argument('-S', '--S', type=str,
help='Species, e.g. 1H-14N-16O3', default = '')
args = parser.parse_args()
T = args.T
dnu = args.dnu
S = args.S
print(T)
print(dnu)
print(S)
main(T, dnu, S)