-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotmassloading.py
executable file
·268 lines (256 loc) · 10.9 KB
/
plotmassloading.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
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
import os
import numpy as np
import matplotlib
matplotlib.use('agg')
import numpy as np
import numpy.linalg as la
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from pylab import *
import matplotlib.colors
import matplotlib.cm
import matplotlib.pyplot as plt
import math
import h5py
import re
import sys
import glob
from numpy.linalg import inv
rcParams['figure.figsize'] = 8, 6
rcParams.update({'figure.autolayout': True})
rcParams.update({'font.size': 24})
rcParams['axes.unicode_minus'] = False
import matplotlib.patches as patches
rcParams['axes.linewidth'] = 2
rcParams['pdf.fonttype'] = 42
rcParams['ps.fonttype'] = 42
rcParams['ps.useafm'] = True
rcParams['pdf.use14corefonts'] = True
rcParams['xtick.major.width'] = 2
rcParams['ytick.major.width'] = 2
rcParams['xtick.minor.width'] = 2
rcParams['ytick.minor.width'] = 2
rcParams['text.usetex'] = True
import colormaps as cmaps
plt.register_cmap(name='viridis', cmap=cmaps.viridis)
plt.register_cmap(name='inferno', cmap=cmaps.inferno)
plt.register_cmap(name='plasma', cmap=cmaps.plasma)
from readsnap_samson import *
from Sasha_functions import *
from gadget_lib.cosmo import *
from samson_functions import *
from crtestfunction import *
#dirneed=['m12icr_b_70', 'm12imhdcv', 'm12icr_700', 'f553']
dirneed=[
'bwsmclrdc28mhd','bwmwmrdc28mhd','bwsbclrdc28mhd',
#'bwsmclrdc29','bwmwmrdc29','bwsbclrdc29',
#'bwsmclrdc28','bwmwmrdc28','bwsbclrdc28',
#'bwsmclr','bwmwmr','bwsbclrmhd',
#'bwsmclrmhd', 'bwmwmrmhd', 'bwsbclrmhd',
#'m11dmhdcv',\
#'m11bcr_b_70','m11bmhdcv','m11bcr_700',\
#'476',\
#'bwsmclr','bwsmclrdc0','bwsmclrdc27','bwsmclrdc28','bwsmclrdc29','bwsmclrstr','bwsmclrdc28mhd'
#'m09','m10','m11','m12v','B1','m12qq','383','476',\
#'fm10qmd','fm10vmd','fm11dmd','fm11emd', 'fm11hmd','fm11imd', 'fm11qmd','fm12fmd','fm12imd',\
#'m10qcr_b_70','m10vcr_b_70', 'm11bcr_b_70','m11dcr_b_70','m11vcr_b_70','m11v1cr_b_70',\
#'m12icr_b_70','m11fcr_b_70','m11hcr_b_70','m11gcr_b_70',\
#'m12fmhdcv','m12mmhdcv',\
#'m10qmhdcv','m10vmhdcv', 'm11bmhdcv','m11dmhdcv','m12imhdcv','m11fmhdcv','m11hmhdcv','m11gmhdcv',\
#'m12fcr_700','m12mcr_700',\
#'m10vcr_700', 'm11bcr_700','m11dcr_700','m11fcr_700','m11gcr_700','m11hcr_700','m12icr_700',
#'fm12m','fm12b','fm10q','fm11d','f553','f573','f476','f383','fm11q','fm11v','fm11v1','fm11v2','f1146','f46','f61',
]
galcen=0
hubble=0.702
#Nsnaplist=range(300,441,10)
#Nsnaplist=range(590,601,10)
#Nsnaplist=range(500,601,10)
Nsnaplist=range(450,500,1)
#Nsnaplist=[570,580,590,600]
#fmeat='test'
#fmeat='md'
#fmeat='all'
#fmeat='FIRE1'
#fmeat='FIRE2'
fmeat='dc28mhd'
#fmeat='hydro'
#fmeat='mhdcv'
#fmeat='cr_b_70'
#fmeat='cr_700'
#fmeat='crhydroave'
#fmeat='hydrosn600'
#Nsnaplist=[580,590,600]
tsep=10.0
needmsmv=1
needSFRMs=1
needmlms=1
avesnap=1
sfrl=np.array([])
mll =np.array([]) #massloading factor
mvl =np.array([])
mwl =np.array([]) #outflow rate
msl =np.array([])
runtodol = np.array([])
dcl = np.array([])
nsml = np.array([])
for runtodo in dirneed:
for Nsnap in Nsnaplist:
#haloinfo=cosmichalo(runtodo)
haloinfo=outdirname(runtodo)
rundir=haloinfo['rundir']
maindir=haloinfo['maindir']
print 'maindir', maindir
subdir=haloinfo['subdir']
halostr=haloinfo['halostr']
snumadd=haloinfo['snumadd']
usepep=haloinfo['usepep']
hubble=haloinfo['h0']
firever=haloinfo['firever']
highres=haloinfo['highres']
Rvir=haloinfo['Rvir']
cosmo=haloinfo['cosmo']
Ms = haloinfo['Msini']
Mv = haloinfo['Mhini']
if cosmo==1:
try:
if usepep==0:
halosA = read_halo_history(rundir, halonostr=halostr,comoving=0,hubble=hubble,maindir=maindir,snumadd=snumadd)
else:
halosA = read_halo_history_pep(rundir, Nsnap, singlesnap=1, firever=firever, halonostr=halostr, comoving=0, maindir=maindir)
redlist = halosA['redshift']
Rvirlist = halosA['R']
Mslist = halosA['Ms']
Mvlist = halosA['M']
#print 'Mslist', Mslist
#print 'Mvlist', Mvlist
except (IOError,KeyError):
continue
try:
Rvir = Rvirlist[-1]
Ms = Mslist[-1]
Mv = Mvlist[-1]
except TypeError:
Rvir=Rvirlist; Ms = Mslist; Mv = Mvlist;
Rup = Rvir*0.3
Rdown = Rvir*0.2
try:
emdata=gaswindphase(runtodo,Nsnap,rotface=0,withinr=100.0,zup=Rup,zdown=Rdown,userad=1)
sfrdata=outsfr(runtodo, Nsnap,tsep=tsep)
vr = emdata['vr'] #in km/s
Gmass = emdata['Gmass'] #in 1e10Msun
print 'np.median(vr)', np.median(vr)
print 'np.sum(Gmass)', np.sum(Gmass)
SFR = sfrdata['SFR']# in Msun/yr
Nsm = sfrdata['Nsm']# in solar mass
print 'runtodo', runtodo
print 'dc', highres
print 'Gmass', np.sum(Gmass)
print 'SFR', SFR
print 'Rvir', Rvir
mwind = np.sum(Gmass*1e10*vr*km_in_cm)/(Rup-Rdown)/kpc_in_cm*yr_in_sec #Msun/yr
ml = mwind/SFR
msl=np.append(msl,Ms)
mvl=np.append(mvl,Mv)
nsml = np.append(nsml,Nsm)
mwl = np.append(mwl,mwind)
mll=np.append(mll,ml)
sfrl=np.append(sfrl,SFR)
runtodol= np.append(runtodol,runtodo)
dcl=np.append(dcl,highres)
except (IOError,KeyError):
continue
print 'dcl', dcl
print 'dcl==0', dcl==0
if avesnap==1:
print 'runtodol', runtodol
print 'mvl', mvl
print 'sfrl', sfrl
cutinf = np.isfinite(mvl)
mvlold=mvl[cutinf];mslold=msl[cutinf];mllold=mll[cutinf];sfrlold=sfrl[cutinf];
runtodolold=runtodol[cutinf];mwlold=mwl[cutinf];dclold=dcl[cutinf];
nsmoldl=nsml[cutinf]
mvl=msl=mll=runtodol=mwl=dcl=sfrl=avensml=np.array([])
for runtodo in dirneed:
print 'runtodo', runtodo
print 'mvlold', mvlold[runtodolold==runtodo],
print 'ave', np.average(mvlold[runtodolold==runtodo])
numoftimes = len(mvlold[runtodolold==runtodo])
mvl=np.append(mvl,np.average(mvlold[runtodolold==runtodo]))
msl=np.append(msl,np.average(mslold[runtodolold==runtodo]))
mll=np.append(mll,np.average(mllold[runtodolold==runtodo]))
mwl=np.append(mwl,np.average(mwlold[runtodolold==runtodo]))
dcl=np.append(dcl,np.median(dclold[runtodolold==runtodo]))
sfrl=np.append(sfrl,np.average(sfrlold[runtodolold==runtodo]))
runtodol=np.append(runtodol,np.unique(runtodolold[runtodolold==runtodo]))
avensml = np.append(avensml,np.average(nsmoldl[runtodolold==runtodo]))
mlla = mwl/(avensml/numoftimes/tsep/1e6)
print 'runtodol', runtodol
print 'mvl', mvl
print 'sfrl', sfrl
print 'mlla', mlla
plt.plot(mvl[dcl==0],mll[dcl==0],marker='o',ls='none',color='y',label='Hydro')
plt.plot(mvl[dcl==1],mll[dcl==1],marker='s',ls='none',color='b',label='MHD')
plt.plot(mvl[dcl==2],mll[dcl==2],marker='^',ls='none',color='g',label=r'$\kappa$=3e28')
plt.plot(mvl[dcl==3],mll[dcl==3],marker='d',ls='none',color='k',label=r'$\kappa$=3e29')
plt.plot(mvl[dcl==4],mll[dcl==4],marker='*',ls='none',color='brown',label='metal diffusion')
plt.xscale('log')
plt.yscale('log')
plt.xlabel(r'$M_{\rm vir}\,[{\rm M}_{\odot}]$')
plt.ylabel(r'$\eta=\dot{M}_{\rm w}/\dot{M}_{*}$')
plt.legend(loc='best',fontsize=12)
filename='figures/Massloading_'+fmeat+'.pdf'
print 'filename', filename
plt.savefig(filename)
plt.clf()
if needmlms==1:
plt.plot(msl[dcl==0],mll[dcl==0],marker='o',ls='none',color='y',label='Hydro')
plt.plot(msl[dcl==1],mll[dcl==1],marker='s',ls='none',color='b',label='MHD')
plt.plot(msl[dcl==2],mll[dcl==2],marker='^',ls='none',color='g',label=r'$\kappa$=3e28')
plt.plot(msl[dcl==3],mll[dcl==3],marker='d',ls='none',color='k',label=r'$\kappa$=3e29')
plt.plot(msl[dcl==4],mll[dcl==4],marker='*',ls='none',color='brown',label='metal diffusion')
plt.xscale('log')
plt.yscale('log')
plt.xlabel(r'$M_{*}\,[{\rm M}_{\odot}]$')
plt.ylabel(r'$\eta=\dot{M}_{\rm w}/\dot{M}_{*}$')
plt.legend(loc='best',fontsize=12)
filename='figures/MsMv_'+fmeat+'.pdf'
print 'mvl', mvl
print 'msl', msl
print 'filename', filename
plt.savefig(filename)
plt.clf()
if needmsmv==1:
plt.plot(mvl[dcl==0],msl[dcl==0],marker='o',ls='none',color='y',label='Hydro')
plt.plot(mvl[dcl==1],msl[dcl==1],marker='s',ls='none',color='b',label='MHD')
plt.plot(mvl[dcl==2],msl[dcl==2],marker='^',ls='none',color='g',label=r'$\kappa$=3e28')
plt.plot(mvl[dcl==3],msl[dcl==3],marker='d',ls='none',color='k',label=r'$\kappa$=3e29')
plt.plot(mvl[dcl==4],msl[dcl==4],marker='*',ls='none',color='brown',label='metal diffusion')
plt.xscale('log')
plt.yscale('log')
plt.xlabel(r'$M_{\rm vir}\,[{\rm M}_{\odot}]$')
plt.ylabel(r'$M_{*}\,[{\rm M}_{\odot}]$')
plt.legend(loc='best',fontsize=12)
filename='figures/MsMv_'+fmeat+'.pdf'
print 'mvl', mvl
print 'msl', msl
print 'filename', filename
plt.savefig(filename)
plt.clf()
if needSFRMs==1:
plt.plot(msl[dcl==0],sfrl[dcl==0],marker='o',ls='none',color='y',label='Hydro')
plt.plot(msl[dcl==1],sfrl[dcl==1],marker='s',ls='none',color='b',label='MHD')
plt.plot(msl[dcl==2],sfrl[dcl==2],marker='^',ls='none',color='g',label=r'$\kappa$=3e28')
plt.plot(msl[dcl==3],sfrl[dcl==3],marker='d',ls='none',color='k',label=r'$\kappa$=3e29')
plt.plot(msl[dcl==4],sfrl[dcl==4],marker='*',ls='none',color='brown',label='metal diffusion')
plt.xscale('log')
plt.yscale('log')
plt.xlabel(r'$M_{*}\,[{\rm M}_{\odot}]$')
plt.ylabel(r'SFR $[{\rm M}_{\odot}]$')
plt.legend(loc='best',fontsize=12)
filename='figures/SFRMs_'+fmeat+'.pdf'
#print 'msl', msl
#print 'sfrl', sfrl
print 'filename', filename
plt.savefig(filename)
plt.clf()