-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_grid_ndist.py
183 lines (156 loc) · 5.56 KB
/
read_grid_ndist.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
#!/usr/bin/env python
import numpy as np
#Column 1: tkin [K]
#Column 2: mean of density distribution [cm^-3]
#Column 3: 1sigma width of density distribution [dex]
#Column 4: power law tail implemented?
#Column 5: fraction of mass in powerlaw tail.
#Column 6: median density by mass
#Column 7: fraction of mass above 1e4.5 cm^-3
#Column 8: co10 emissivity (actual value K km/s per cm^-2)
#Column 9: median density by flux for co10
def limitarr(arr,index):
arr=np.array(arr)
out=[None for i in range(arr.shape[0])]
for i in range(arr.shape[0]):
a=arr[i]
out[i]=a[index]
del arr, a
return out
############################################################
def read_grid_ndist(transition,usertkin,userwidth,powerlaw):
m={}
if not powerlaw:
lratfile='lrat_table.txt'
else:
lratfile='lrat_table_powerlaw.txt'
gridfile='models/'+lratfile
Tkin,n_mean,width,pl,plmass,n_mean_mass,densefrac, \
ICO,n_mean_ICO,\
ICO21_ICO,n_mean_ICO21,\
ICO32_ICO,n_mean_ICO32,\
I13CO10_ICO,n_mean_I13CO10,\
I13CO21_ICO,n_mean_I13CO21,\
I13CO32_ICO,n_mean_I13CO32,\
IC18O10_ICO,n_mean_IC18O10,\
IC18O21_ICO,n_mean_IC18O21,\
IC18O32_ICO,n_mean_IC18O32,\
IC17O10_ICO,n_mean_IC17O10,\
IC17O21_ICO,n_mean_IC17O21,\
IC17O32_ICO,n_mean_IC17O32,\
IHCN10_ICO,n_mean_IHCN10,\
IHCN21_ICO,n_mean_IHCN21,\
IHCN32_ICO,n_mean_IHCN32,\
IHNC10_ICO,n_mean_IHNC10,\
IHNC21_ICO,n_mean_IHNC21,\
IHNC32_ICO,n_mean_IHNC32,\
IHCOP10_ICO,n_mean_IHCOP10,\
IHCOP21_ICO,n_mean_IHCOP21,\
IHCOP32_ICO,n_mean_IHCOP32,\
ICS10_ICO,n_mean_ICS10,\
ICS21_ICO,n_mean_ICS21,\
ICS32_ICO,n_mean_ICS32 \
= np.loadtxt(gridfile, skiprows=55,unpack=True)
# from variables to list
mygrid=[Tkin,n_mean,width,pl,plmass,n_mean_mass,densefrac, \
ICO,n_mean_ICO,\
ICO21_ICO,n_mean_ICO21,\
ICO32_ICO,n_mean_ICO32,\
I13CO10_ICO,n_mean_I13CO10,\
I13CO21_ICO,n_mean_I13CO21,\
I13CO32_ICO,n_mean_I13CO32,\
IC18O10_ICO,n_mean_IC18O10,\
IC18O21_ICO,n_mean_IC18O21,\
IC18O32_ICO,n_mean_IC18O32,\
IC17O10_ICO,n_mean_IC17O10,\
IC17O21_ICO,n_mean_IC17O21,\
IC17O32_ICO,n_mean_IC17O32,\
IHCN10_ICO,n_mean_IHCN10,\
IHCN21_ICO,n_mean_IHCN21,\
IHCN32_ICO,n_mean_IHCN32,\
IHNC10_ICO,n_mean_IHNC10,\
IHNC21_ICO,n_mean_IHNC21,\
IHNC32_ICO,n_mean_IHNC32,\
IHCOP10_ICO,n_mean_IHCOP10,\
IHCOP21_ICO,n_mean_IHCOP21,\
IHCOP32_ICO,n_mean_IHCOP32,\
ICS10_ICO,n_mean_ICS10,\
ICS21_ICO,n_mean_ICS21,\
ICS32_ICO,n_mean_ICS32]
# limit to reasonable range (defined by one-zone grid and width of distribution)
# compare to http://www.densegastoolbox.com/explorer/
n_lolim=10**1.8
n_uplim=10**5.0
n_mean=mygrid[1]
index=np.where(n_mean>n_lolim)[0]
mygrid=limitarr(mygrid,index)
n_mean=mygrid[1]
index=np.where(n_mean<n_uplim)[0]
mygrid=limitarr(mygrid,index)
# limit to values at user temperature
if usertkin>0:
Tkin=mygrid[0]
index=np.where(Tkin==usertkin)[0]
mygrid=limitarr(mygrid,index)
# limit to values at user temperature
if userwidth>0:
width=mygrid[2]
index=np.where(width==userwidth)[0]
mygrid=limitarr(mygrid,index)
# back from list to variables
Tkin,n_mean,width,pl,plmass,n_mean_mass,densefrac, \
ICO,n_mean_ICO,\
ICO21_ICO,n_mean_ICO21,\
ICO32_ICO,n_mean_ICO32,\
I13CO10_ICO,n_mean_I13CO10,\
I13CO21_ICO,n_mean_I13CO21,\
I13CO32_ICO,n_mean_I13CO32,\
IC18O10_ICO,n_mean_IC18O10,\
IC18O21_ICO,n_mean_IC18O21,\
IC18O32_ICO,n_mean_IC18O32,\
IC17O10_ICO,n_mean_IC17O10,\
IC17O21_ICO,n_mean_IC17O21,\
IC17O32_ICO,n_mean_IC17O32,\
IHCN10_ICO,n_mean_IHCN10,\
IHCN21_ICO,n_mean_IHCN21,\
IHCN32_ICO,n_mean_IHCN32,\
IHNC10_ICO,n_mean_IHNC10,\
IHNC21_ICO,n_mean_IHNC21,\
IHNC32_ICO,n_mean_IHNC32,\
IHCOP10_ICO,n_mean_IHCOP10,\
IHCOP21_ICO,n_mean_IHCOP21,\
IHCOP32_ICO,n_mean_IHCOP32,\
ICS10_ICO,n_mean_ICS10,\
ICS21_ICO,n_mean_ICS21,\
ICS32_ICO,n_mean_ICS32 = mygrid
# match variables from above to dict keys --> should be improved later
# i.e. populate model dictionary
m['CO10']=ICO
m['CO21']=ICO21_ICO*ICO
m['CO32']=ICO32_ICO*ICO
m['13CO10']=I13CO10_ICO*ICO
m['13CO21']=I13CO21_ICO*ICO
m['13CO32']=I13CO32_ICO*ICO
m['C18O10']=IC18O10_ICO*ICO
m['C18O21']=IC18O21_ICO*ICO
m['C18O32']=IC18O32_ICO*ICO
m['C17O10']=IC17O10_ICO*ICO
m['C17O21']=IC17O21_ICO*ICO
m['C17O32']=IC17O32_ICO*ICO
m['HCN10']=IHCN10_ICO*ICO
m['HCN21']=IHCN21_ICO*ICO
m['HCN32']=IHCN32_ICO*ICO
m['HNC10']=IHNC10_ICO*ICO
m['HNC21']=IHNC21_ICO*ICO
m['HNC32']=IHNC32_ICO*ICO
m['HCOP10']=IHCOP10_ICO*ICO
m['HCOP21']=IHCOP21_ICO*ICO
m['HCOP32']=IHCOP32_ICO*ICO
m['CS10']=ICS10_ICO*ICO
m['CS21']=ICS21_ICO*ICO
m['CS32']=ICS32_ICO*ICO
m['T']=Tkin
m['n']=n_mean_mass
m['width']=width
m['densefrac']=densefrac
return m