1 | import os |
---|
2 | import numpy as np |
---|
3 | import matplotlib.pyplot as plt |
---|
4 | import exo_k as xk |
---|
5 | |
---|
6 | ### choose spectral resolution for corrk |
---|
7 | R=500 |
---|
8 | wnedges=xk.wavenumber_grid_R(10000/100, 10000/.3, R) |
---|
9 | print("Spectral resolution asked: wn=", wnedges.min(), wnedges.max(), ", R =", R) |
---|
10 | |
---|
11 | ### folder where corrk will be saved |
---|
12 | data_path="datadir/" |
---|
13 | dir_out = data_path+f"corrk_data/R{R}_from_R15000/" |
---|
14 | |
---|
15 | ### folder with xsec data, downloaded from exomol.com for example |
---|
16 | xk.Settings().set_search_path(data_path+"exomol/taurex_R15000/") |
---|
17 | pattern = 'xsec.TauREx.h5' |
---|
18 | |
---|
19 | ### you can set your desired p and t grid here (otherwise, first molecule is used) |
---|
20 | logpgrid = None |
---|
21 | tgrid = None |
---|
22 | |
---|
23 | mols = [ |
---|
24 | # "C2H2", |
---|
25 | "C2H4", |
---|
26 | # "CH4", |
---|
27 | # "CO2", |
---|
28 | "CO", |
---|
29 | "H2O", |
---|
30 | "H2S", |
---|
31 | "HCN", |
---|
32 | "K", |
---|
33 | "MgH", |
---|
34 | "MgO", |
---|
35 | "NaH", |
---|
36 | "Na", |
---|
37 | "NaOH", |
---|
38 | "NH3", |
---|
39 | "O2", |
---|
40 | "OCS", |
---|
41 | "OH", |
---|
42 | "SiH2", |
---|
43 | "SiH4", |
---|
44 | "SiH", |
---|
45 | "SO2", |
---|
46 | "TiO", |
---|
47 | "VO", |
---|
48 | ] |
---|
49 | |
---|
50 | |
---|
51 | xk.Settings().set_mks(True) |
---|
52 | xk.Settings().set_log_interp(False) |
---|
53 | xk.Settings().set_case_sensitive(True) |
---|
54 | |
---|
55 | |
---|
56 | print (f"Generating R{R} in {dir_out}") |
---|
57 | for mol in mols: |
---|
58 | try: |
---|
59 | if os.path.exists(dir_out+mol+f"_R{R}.corrk.h5"): |
---|
60 | print("Already exists: "+mol) |
---|
61 | # continue # uncomment to skip molecules |
---|
62 | else: |
---|
63 | print(f"Reading: {mol}") |
---|
64 | |
---|
65 | xtable=xk.Xtable(pattern, mol=mol, remove_zeros=True) |
---|
66 | print(f"Initial spectral resolution = {xtable.Nw}") |
---|
67 | |
---|
68 | tmp_ktab=xk.Ktable(wnedges=wnedges, xtable=xtable) |
---|
69 | |
---|
70 | # print(f"Binning: {mol}") |
---|
71 | # tmp_ktab.bin_down(wnedges) |
---|
72 | |
---|
73 | |
---|
74 | if logpgrid is None or tgrid is None: # use first molecule to set p and t grid |
---|
75 | logpgrid = tmp_ktab.logpgrid |
---|
76 | tgrid = tmp_ktab.tgrid |
---|
77 | |
---|
78 | if (tmp_ktab.logpgrid != logpgrid).any() or (tmp_ktab.tgrid != tgrid).any(): |
---|
79 | print("Initial P grid:", tmp_ktab.pgrid) |
---|
80 | print("Initial T grid:", tmp_ktab.tgrid) |
---|
81 | print(f"Remapping {mol}") |
---|
82 | print("New P grid:", np.power(logpgrid,10)) |
---|
83 | print("New T grid:", tgrid) |
---|
84 | tmp_ktab.remap_logPT(logp_array=logpgrid, t_array=tgrid) |
---|
85 | |
---|
86 | print(tmp_ktab) |
---|
87 | print(f"Writing: {mol}") |
---|
88 | tmp_ktab.write_hdf5(dir_out+mol+f"_R{R}.corrk.h5") |
---|
89 | |
---|
90 | p_plot=1 |
---|
91 | t_plot=300. |
---|
92 | fig,ax=plt.subplots(figsize=(9,6.5)) |
---|
93 | tmp_ktab.plot_spectrum(ax,p=p_plot,t=t_plot,g=1.,yscale='log',xscale='log',label=mol) |
---|
94 | plt.title(f"{mol} @ P = {p_plot}, T = {t_plot}") |
---|
95 | fig.tight_layout() |
---|
96 | plt.legend() |
---|
97 | plt.savefig(dir_out+f"corrk_{R}_{mol}_p{p_plot}_t{t_plot}.pdf") |
---|
98 | except Exception as e: |
---|
99 | print(f"Skipping {mol}. {e}") |
---|
100 | |
---|