/
oh2co_density_grid.py
203 lines (178 loc) · 6.97 KB
/
oh2co_density_grid.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import os
import pyradex
import pyradex.fjdu
import pylab as pl
import numpy as np
import matplotlib
# for pretty on-screen plots
if os.path.exists('/Users/adam/.matplotlib/ggplotrc'):
matplotlib.rc_file('/Users/adam/.matplotlib/ggplotrc')
ndens = 100
#temperatures = np.linspace(10,50,nabund)
temperature = 50.
densities = np.logspace(1.5,7.,ndens)
abundances = np.array([-10, -9,-8],dtype='float')
opr = 1. # assume an even mix
fortho = opr/(1.+opr)
# background is... not obviously working
#background = 10.0 # instead of 2.73
nabund = abundances.size
taugrid_6cm = np.empty([ndens,nabund])
texgrid_6cm = np.empty([ndens,nabund])
tbgrid_6cm = np.empty([ndens,nabund])
fluxgrid_6cm = np.empty([ndens,nabund])
taugrid_2cm = np.empty([ndens,nabund])
texgrid_2cm = np.empty([ndens,nabund])
tbgrid_2cm = np.empty([ndens,nabund])
fluxgrid_2cm = np.empty([ndens,nabund])
taugrid_1cm = np.empty([ndens,nabund])
texgrid_1cm = np.empty([ndens,nabund])
tbgrid_1cm = np.empty([ndens,nabund])
fluxgrid_1cm = np.empty([ndens,nabund])
columngrid = np.empty([ndens,nabund])
if not os.path.exists('oh2co-h2.dat'):
import urllib
urllib.urlretrieve('http://home.strw.leidenuniv.nl/~moldata/datafiles/oh2co-h2.dat')
Radex = pyradex.fjdu.Fjdu
Radex = pyradex.Radex
R = Radex(species='oh2co-h2', collider_densities={'H2':1e6},
column=1e12, temperature=temperature)
R.run_radex()
# get the table so we can look at the frequency grid
table = R.get_table()
# Target frequencies:
table[np.array([0,2,5])].pprint()
R.temperature = temperature
for ii,aa in enumerate(10.**abundances):
for jj,dd in enumerate(densities):
R.density = {'oH2':dd*fortho,'pH2':dd*(1-fortho)}
R.abundance = aa
R.run_radex(reuse_last=False, reload_molfile=True)
TI = R.source_line_brightness_temperature
taugrid_6cm[jj,ii] = R.tau[0]
texgrid_6cm[jj,ii] = R.tex[0].value
tbgrid_6cm[jj,ii] = R.T_B[0].value
fluxgrid_6cm[jj,ii] = TI[0].value
taugrid_2cm[jj,ii] = R.tau[2]
texgrid_2cm[jj,ii] = R.tex[2].value
tbgrid_2cm[jj,ii] = R.T_B[2].value
fluxgrid_2cm[jj,ii] = TI[2].value
taugrid_1cm[jj,ii] = R.tau[5]
texgrid_1cm[jj,ii] = R.tex[5].value
tbgrid_1cm[jj,ii] = R.T_B[5].value
fluxgrid_1cm[jj,ii] = TI[5].value
columngrid[jj,ii] = R.column.value
pl.figure(1)
pl.clf()
ax1 = pl.subplot(2,1,1)
ax1.loglog(densities,taugrid_6cm[:,0],label='$X=10^{%i}$' % abundances[0])
ax1.loglog(densities,taugrid_2cm[:,0])
ax1.loglog(densities,taugrid_6cm[:,1],linestyle='--',label='$X=10^{%i}$' % abundances[1])
ax1.loglog(densities,taugrid_2cm[:,1],linestyle='--')
ax1.loglog(densities,taugrid_6cm[:,2],linestyle=':',label='$X=10^{%i}$' % abundances[2])
ax1.loglog(densities,taugrid_2cm[:,2],linestyle=':')
ax1.set_xticks([])
ax1.set_ylabel("$\\tau$")
pl.legend(loc='best',fontsize=14)
ax2 = pl.subplot(2,1,2)
ax2.semilogx(densities,taugrid_6cm[:,0]/taugrid_2cm[:,0])
ax2.semilogx(densities,taugrid_6cm[:,1]/taugrid_2cm[:,1],linestyle='--')
ax2.set_xlabel("log n(H$_2$) [cm$^{-3}$]")
ax2.set_ylabel("Ratio")
pl.subplots_adjust(hspace=0)
pl.show()
pl.figure(2)
pl.clf()
ax1 = pl.subplot(2,1,1)
ax1.semilogx(densities,texgrid_6cm[:,0],label='$X=10^{%i}$' % abundances[0])
ax1.semilogx(densities,texgrid_2cm[:,0])
ax1.semilogx(densities,texgrid_6cm[:,1],linestyle='--',label='$X=10^{%i}$' % abundances[1])
ax1.semilogx(densities,texgrid_2cm[:,1],linestyle='--')
ax1.semilogx(densities,texgrid_6cm[:,2],linestyle=':',label='$X=10^{%i}$' % abundances[2])
ax1.semilogx(densities,texgrid_2cm[:,2],linestyle=':')
ax1.set_xticks([])
ax1.set_ylabel("$T_{ex}$")
ax1.hlines(2.73,10,1e7,color='k', linewidth=3, alpha=0.3, zorder=-1)
ax1.set_ylim(0,4)
ax1.set_xlim(densities.min(),densities.max())
pl.legend(loc='best', fontsize=14)
ax2 = pl.subplot(2,1,2)
ax2.semilogx(densities,texgrid_6cm[:,0]/texgrid_2cm[:,0])
ax2.semilogx(densities,texgrid_6cm[:,1]/texgrid_2cm[:,1],linestyle='--')
ax2.set_xlabel("log n(H$_2$) [cm$^{-3}$]")
ax2.set_ylabel("Ratio")
ax2.set_ylim(0,1)
pl.subplots_adjust(hspace=0)
pl.show()
pl.figure(3)
pl.clf()
ax1 = pl.subplot(2,1,1)
ax1.semilogx(densities,tbgrid_6cm[:,0],label='$X=10^{%i}$' % abundances[0])
ax1.semilogx(densities,tbgrid_2cm[:,0])
ax1.semilogx(densities,tbgrid_6cm[:,1],linestyle='--',label='$X=10^{%i}$' % abundances[1])
ax1.semilogx(densities,tbgrid_2cm[:,1],linestyle='--')
ax1.semilogx(densities,tbgrid_6cm[:,2],linestyle=':',label='$X=10^{%i}$' % abundances[2])
ax1.semilogx(densities,tbgrid_2cm[:,2],linestyle=':')
ax1.set_xticks([])
ax1.set_ylabel("$T_{B}$")
ax1.hlines(2.73,10,1e7,color='k', linewidth=3, alpha=0.3, zorder=-1)
ax1.set_ylim(-3,10)
ax1.set_xlim(densities.min(),densities.max())
pl.legend(loc='best', fontsize=14)
ax2 = pl.subplot(2,1,2)
ax2.semilogx(densities,tbgrid_6cm[:,0]/tbgrid_2cm[:,0])
ax2.semilogx(densities,tbgrid_6cm[:,1]/tbgrid_2cm[:,1],linestyle='--')
ax2.set_xlabel("log n(H$_2$) [cm$^{-3}$]")
ax2.set_ylabel("Ratio")
ax2.set_ylim(-1,10)
pl.subplots_adjust(hspace=0)
pl.show()
fig4 = pl.figure(4)
fig4.clf()
ax1 = pl.subplot(2,1,1)
cm2, = ax1.loglog(densities,taugrid_2cm[:,0],label='$X=10^{%i}$' % abundances[0])
cm1, = ax1.loglog(densities,taugrid_1cm[:,0])
ax1.loglog(densities,taugrid_2cm[:,1],linestyle='--',label='$X=10^{%i}$' % abundances[1],
color=cm2.get_color())
ax1.loglog(densities,taugrid_1cm[:,1],linestyle='--',
color=cm1.get_color())
ax1.loglog(densities,taugrid_2cm[:,2],linestyle=':',label='$X=10^{%i}$' % abundances[2],
color=cm2.get_color())
ax1.loglog(densities,taugrid_1cm[:,2],linestyle=':',
color=cm1.get_color())
ax1.set_xticks([])
ax1.set_ylabel("$\\tau$")
ax1.set_ylim(1e-5, 1e2)
pl.legend(loc='best',fontsize=14)
ax2 = pl.subplot(2,1,2)
ax2.semilogx(densities,1./(taugrid_2cm[:,0]/taugrid_1cm[:,0]))
ax2.semilogx(densities,1./(taugrid_2cm[:,1]/taugrid_1cm[:,1]),linestyle='--')
ax2.semilogx(densities,1./(taugrid_2cm[:,2]/taugrid_1cm[:,2]),linestyle=':')
ax2.set_xlabel("log n(H$_2$) [cm$^{-3}$]")
ax2.set_ylabel("Ratio")
pl.subplots_adjust(hspace=0)
pl.show()
pl.figure(6)
pl.clf()
ax1 = pl.subplot(2,1,1)
ax1.semilogx(densities,tbgrid_2cm[:,0],label='$X=10^{%i}$' % abundances[0])
ax1.semilogx(densities,tbgrid_1cm[:,0])
ax1.semilogx(densities,tbgrid_2cm[:,1],linestyle='--',label='$X=10^{%i}$' % abundances[1])
ax1.semilogx(densities,tbgrid_1cm[:,1],linestyle='--')
ax1.semilogx(densities,tbgrid_2cm[:,2],linestyle=':',label='$X=10^{%i}$' % abundances[2])
ax1.semilogx(densities,tbgrid_1cm[:,2],linestyle=':')
ax1.set_xticks([])
ax1.set_ylabel("$T_{B}$")
ax1.hlines(2.73,10,1e7,color='k', linewidth=3, alpha=0.3, zorder=-1)
ax1.set_ylim(-3,10)
ax1.set_xlim(densities.min(),densities.max())
pl.legend(loc='best', fontsize=14)
ax2 = pl.subplot(2,1,2)
ax2.semilogx(densities,tbgrid_2cm[:,0]/tbgrid_1cm[:,0])
ax2.semilogx(densities,tbgrid_2cm[:,1]/tbgrid_1cm[:,1],linestyle='--')
ax2.semilogx(densities,tbgrid_2cm[:,2]/tbgrid_1cm[:,2],linestyle=':')
ax2.set_xlabel("log n(H$_2$) [cm$^{-3}$]")
ax2.set_ylabel("Ratio")
ax2.set_ylim(-1,10)
pl.subplots_adjust(hspace=0)
pl.show()