-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnapshot_extinction.py
More file actions
287 lines (206 loc) · 5.65 KB
/
snapshot_extinction.py
File metadata and controls
287 lines (206 loc) · 5.65 KB
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/usr/bin/python
import os
import sys
import numpy
from numpy import *
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import matplotlib.pylab as pylab
from pylab import *
from matplotlib import colors
from matplotlib import rc
rc('font',**{'family':'serif','serif':['Times New Roman'],'size':12})
rc('text',usetex=True)
rc('patch',antialiased=False)
#matplotlib.use('Agg')
import imager_HIIR
import im_sinks_in_front
import fort_dump
import constants
from constants import *
#look for files to process
diri='./'
dirc='../r19t/'
try:
finfo=sys.argv[1]
except:
print 'Need filename or filename root'
raise IndexError
file_list=[]
if len(sys.argv[1])==7:
fname=sys.argv[1]
file_list.append(fname)
else:
fnameroot=sys.argv[1]
for i in os.listdir(dir):
if i[:4] == fnameroot:
file_list.append(i)
file_list.sort()
nfiles=len(file_list)
if nfiles < 1:
print 'No files found to process'
raise IndexError
else:
print 'Processing ',nfiles,' files'
#variables for screenshots - NB imcol expects units in CODE UNITS
subplots_adjust(hspace=0.001)
subplots_adjust(wspace=0.001)
xmin=-10.
xmax=10.
ymin=-10.
ymax=10.
zmin=-100.
zmax=100.
islice='n'
icolmap='roy'
logsigmax=1
logrange=4
logsigmin=logsigmax-logrange
htemp=57940.
print 'USING HOTTEMP OF ',htemp
#speed of sound
cs=2e4
gcm2_msunpc2=4.783e3
cm2_kpc2=9.523e42
extfactor=1./1.67e-24/1.e21/gcm2_msunpc2
angle1=0.
angle2=0.
angle3=0.
set_cmap('hot')
xlab='x(pc)'
ylab='y(pc)'
#plt.tight_layout()
shr=0.73
extent=(xmin,xmax,ymin,ymax)
for fname in file_list:
outfile='snap_'+fname
hottemp=-1.
#call wrapper for imcol
fnamec=dirc+fname
fnamei=diri+fname
coldensnc=imager_HIIR.imager(fnamec,xmin,xmax,ymin,ymax,zmin,zmax,islice,icolmap,logsigmax,logrange,logsigmin,hottemp)
coldensni=imager_HIIR.imager(fnamei,xmin,xmax,ymin,ymax,zmin,zmax,islice,icolmap,logsigmax,logrange,logsigmin,hottemp)
outsinkc=im_sinks_in_front.im_sinks_in_front(fnamec,angle1,angle2,angle3)
outsinki=im_sinks_in_front.im_sinks_in_front(fnamei,angle1,angle2,angle3)
sigmascc=outsinkc[0]
sigmascc=[sc*extfactor for sc in sigmascc]
sigmasci=outsinki[0]
sigmasci=[sc*extfactor for sc in sigmasci]
out=fort_dump.fort_dump(fnamec)
#move variables from out into more useful places
umass=out[0]
utime=out[1]
udist=out[2]
npart=out[3]
gt=out[4]
tkin=out[5]
tgrav=out[6]
tterm=out[7]
escap=out[8]
rhotemp=out[9]
potentemp=out[10]
iphasetemp=zeros((npart),dtype=int8)
xtemp=out[11]
ytemp=out[12]
ztemp=out[13]
mtemp=out[14]
htemp=out[15]
vxtemp=out[16]
vytemp=out[17]
vztemp=out[18]
utemp=out[19]
iphasetemp=out[20]
sinkxc=[]
sinkyc=[]
sinkzc=[]
sinkmc=[]
for i in range(npart):
if iphasetemp[i]>0:
sinkxc.append(xtemp[i])
sinkyc.append(ytemp[i])
sinkzc.append(ztemp[i])
sinkmc.append(mtemp[i])
out=fort_dump.fort_dump(fnamei)
#move variables from out into more useful places
umass=out[0]
utime=out[1]
udist=out[2]
npart=out[3]
gt=out[4]
tkin=out[5]
tgrav=out[6]
tterm=out[7]
escap=out[8]
rhotemp=out[9]
potentemp=out[10]
iphasetemp=zeros((npart),dtype=int8)
xtemp=out[11]
ytemp=out[12]
ztemp=out[13]
mtemp=out[14]
htemp=out[15]
vxtemp=out[16]
vytemp=out[17]
vztemp=out[18]
utemp=out[19]
iphasetemp=out[20]
sinkxi=[]
sinkyi=[]
sinkzi=[]
sinkmi=[]
for i in range(npart):
if iphasetemp[i]>0:
sinkxi.append(xtemp[i])
sinkyi.append(ytemp[i])
sinkzi.append(ztemp[i])
sinkmi.append(mtemp[i])
fig=plt.figure(figsize=(12,12))
nsinkc=len(sinkxc)
nsinki=len(sinkxi)
plt.subplot(2,2,1)
normsig=colors.Normalize(vmin=logsigmin,vmax=logsigmax)
imgplot=plt.imshow(coldensnc,extent=extent,origin='lower',interpolation='nearest')
imgplot.set_norm(normsig)
for isink in range(nsinkc):
msize=2.*log10(sinkmc[isink])
plt.plot(sinkxc[isink],sinkyc[isink],'.',markersize=msize,color='white',alpha=exp(-sigmascc[isink]))
# plt.plot(sinkx[isink],sinky[isink],'o',markersize=msize,markeredgewidth=0.0,markeredgecolor=None,color='white',aa=True,alpha=exp(-sigmasc[isink]))
plt.xlim(xmin, xmax)
plt.ylim(ymin, ymax)
xlabel(xlab)
ylabel(ylab)
plt.subplot(2,2,2)
imgplot=plt.imshow(coldensni,extent=extent,origin='lower',interpolation='nearest')
imgplot.set_norm(normsig)
for isink in range(nsinki):
msize=2.*log10(sinkmi[isink])
plt.plot(sinkxi[isink],sinkyi[isink],'.',markersize=msize,color='white',alpha=exp(-sigmasci[isink]))
plt.xlim(xmin, xmax)
plt.ylim(ymin, ymax)
xlabel(xlab)
ylabel(ylab)
plt.subplot(2,2,3)
imgplot=plt.imshow(coldensnc,extent=extent,origin='lower',interpolation='nearest')
imgplot.set_norm(normsig)
for isink in range(nsinkc):
msize=2.*log10(sinkmc[isink])
plt.plot(sinkxc[isink],sinkyc[isink],'.',markersize=msize,color='white',alpha=1.00)
plt.xlim(xmin, xmax)
plt.ylim(ymin, ymax)
xlabel(xlab)
ylabel(ylab)
plt.subplot(2,2,4)
imgplot=plt.imshow(coldensni,extent=extent,origin='lower',interpolation='nearest')
imgplot.set_norm(normsig)
for isink in range(nsinki):
msize=2.*log10(sinkmi[isink])
plt.plot(sinkxi[isink],sinkyi[isink],'.',markersize=msize,color='white',alpha=1.00)
plt.xlim(xmin, xmax)
plt.ylim(ymin, ymax)
xlabel(xlab)
ylabel(ylab)
cax = plt.axes([0.91, 0.105, 0.01, 0.79])
cb=plt.colorbar(imgplot, cax=cax)
cb.set_label('Column density (g cm$^{-2}$)')
plt.savefig('snap_extinction_'+fname+'.png',dpi=300,bbox_inches='tight')
print 'Done!'