def calc_stellar_dens(Stars, haloX, haloY, haloZ, theRvir, rvirFac, boxsize): dists = SF.calcdist2(haloX, haloY, haloZ, Stars['p'][:, 0], Stars['p'][:, 1], Stars['p'][:, 2], boxsize) cut = dists < theRvir * rvirFac StellarMass = np.sum(Stars['m'][cut]) StellarDens = StellarMass / ((4.0 / 3.0) * 3.14159 * (theRvir * rvirFac)**3.0) return StellarDens
Sx = Sp[:, 0] Sy = Sp[:, 1] Sz = Sp[:, 2] header = readsnapcr(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr, h0=1, cosmological=1, header_only=1) h0 = header['hubble'] atime = header['time'] if usepep == 1: halosA = SF.read_halo_history_pep(rundir, finalno, beginno=beginno,\ singlesnap=0, firever=firever,halonostr=halostr, hubble=h0, comoving=1, maindir=maindir) afactor = atime else: halosA = SF.read_halo_history(rundir, maindir=maindir, halonostr=halostr, hubble=h0, comoving=0) afactor = 1.0 redlist = halosA['redshift'] haloid = halosA['ID'] a_scale = 1.0 / (1.0 + redlist) xcenl = halosA['x'] * afactor ycenl = halosA['y'] * afactor zcenl = halosA['z'] * afactor Rvirl = halosA['R'] * afactor
G = readsnap(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix) a = G['header'][2] z = 1.0 / a - 1.0 redshift = G['header'][3] boxsize = G['header'][9] omega_matter = G['header'][10] omega_L = G['header'][11] h = G['header'][12] redshiftstring = "{0:.3f}".format(redshift) Hubble = hubble_param(a, omega_matter, h) PhysTemp, PhysRho = SF.convertTemp(G['u'], G['ne'], G['rho'], h) halostats = SF.find_halo_now(halo_to_do, a, therod=use_fixed_halos) print 'halo stats', halostats haloN = halostats[1] #read halo catalog, assign halo properties Rvir = halostats[11] Vsig = halostats[10] haloX = halostats[2] haloY = halostats[3] haloZ = halostats[4] haloVX = halostats[5] haloVY = halostats[6] haloVZ = halostats[7]
else: plotupt.append('') print 'labelneed', labelneed if multifile=='y': fname=the_snapdir+'/snapdir_'+Nsnapstring+'/snapshot_'+Nsnapstring+'.0.hdf5' else: fname=the_snapdir+'/snapshot_'+Nsnapstring+'.hdf5' print 'fname', fname print 'usepep', usepep if cosmo==1: header=readsnapcr(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr,h0=1,cosmological=1,header_only=1) h0 = header['hubble'] atime = header['time'] print 'halostr', halostr if usepep==1: halosA = SF.read_halo_history_pep(rundir, Nsnap, singlesnap=1, firever=firever,halonostr=halostr, hubble=h0, comoving=1, maindir=maindir) redlist = halosA['redshift'] haloid = halosA['ID'] xcen = halosA['x']*atime ycen = halosA['y']*atime zcen = halosA['z']*atime vxcen = halosA['xv'] vycen = halosA['yv'] vzcen = halosA['zv'] else: halosA = SF.read_halo_history(rundir, maindir=maindir, halonostr=halostr,\ hubble=h0, comoving=0, snumadd=snumadd) redlist = halosA['redshift'] haloid = halosA['ID'] a_scale = 1.0/(1.0+redlist) xcenl = halosA['x']
import numpy as np import Sasha_functions as SF import matplotlib.pyplot as plt from scipy.interpolate import interp1d from datetime import date today = date.today() Nhalo = 0 H = SF.read_halo_history(Nhalo) Zs = H['redshift'] IDs = H['ID'] Vsig = H['Vsig'] M = H['M'] Rvir = H['Rvir'] Vmax = H['Vmax'] newtonG = 6.67384e-8 little_h = 0.7 As = 1.0 / (1.0 + Zs) Vcirc = np.sqrt( (newtonG * M * 2e33 / little_h) / (Rvir * As * 3.08e21 / little_h)) / 1e5 Vsig1D = Vsig / np.sqrt(3) Ns = [] for theZ in Zs: theN = SF.N_for_z(theZ) Ns.append(theN) Ns = np.array(Ns)
vesc_order = np.argsort(vesc_ar[count]) mass_sorted_cumsum = np.cumsum(sig_ar[count][vesc_order]) mass_sorted_cumsum /= mass_sorted_cumsum[-1] vesc_med = np.interp(0.5, mass_sorted_cumsum,vesc_ar[count][vesc_order] ) vesc_25 = np.interp(0.25, mass_sorted_cumsum,vesc_ar[count][vesc_order] ) vesc_75 = np.interp(0.75, mass_sorted_cumsum,vesc_ar[count][vesc_order] ) print 'name of ep ',ep_name_ar[count] print 'num of snaps in ep', Neps_ar[count] print 'vesc ',len(vesc_ar[count]) print 'sig ',len(sig_ar[count]) weight_avg_vesc = np.average(vesc_ar[count], weights=sig_ar[count]) print 'weighted average vesc ',weight_avg_vesc print '25th, 50th, 75th percentile vesc ',vesc_25, vesc_med, vesc_75 weighted_avg_sig = np.average(sig_ar[count], weights=sig_ar[count])/area_of_cell print 'weighted average sig ',weighted_avg_sig unweighted_avg_sig = np.mean(sig_ar[count])/area_of_cell print 'unweighted average sig ',unweighted_avg_sig myline = [count, ep_name_ar[count], Neps_ar[count], weight_avg_vesc, vesc_25, vesc_med, vesc_75, weighted_avg_sig, unweighted_avg_sig, maxSF_ar[count], totMass_ar[count], duration_ar[count] ] mystring = SF.line_to_string(myline) f.write(mystring) print count, average_weighted_sig shell_histresults = np.histogram(vesc_ar[count], num_bins, range=(0, 1000), weights=np.array(mass_ar[count])/totalmass) [histx, histy] = ssp.create_plottable_hist(shell_histresults) plt.plot(histx,histy, color=color_ar[count], ls = ls_ar[count], lw=2) count+=1 f.close() plt.legend(my_special_legend, loc='best') plt.savefig(str(today) +'normedeps'+'.pdf')
def surface_density_bycells(S, agecut, poscut, a, h, cell_length=0.3, surface_frac=0.8, density_max_cell_center=True): #r = np.random.randn(100,3) r = [S['p'][:,0][agecut][poscut], S['p'][:,1][agecut][poscut], S['p'][:,2][agecut][poscut]] minx = np.min(S['p'][:,0][agecut][poscut])*a/h maxx = np.max(S['p'][:,0][agecut][poscut])*a/h miny = np.min(S['p'][:,1][agecut][poscut])*a/h maxy = np.max(S['p'][:,1][agecut][poscut])*a/h minz = np.min(S['p'][:,2][agecut][poscut])*a/h maxz = np.max(S['p'][:,2][agecut][poscut])*a/h numxcells = int((maxx-minx)/cell_length)+1 numycells = int((maxy-miny)/cell_length)+1 numzcells = int((maxz-minz)/cell_length)+1 xrange = [minx*h/a, (minx*h/a + float(numxcells)*cell_length*h/a)] yrange = [miny*h/a, (miny*h/a + float(numycells)*cell_length*h/a)] zrange = [minz*h/a, (minz*h/a + float(numzcells)*cell_length*h/a)] # print 'diagnostic x',(xrange[1] - xrange[0])/(cell_length*h/a), numxcells # print 'diagnostic y',(yrange[1] - yrange[0])/(cell_length*h/a), numycells # print 'diagnostic x',(zrange[1] - zrange[0])/(cell_length*h/a), numzcells #rad should be in physical kpc #num_cells=int(rad*2.0/cell_length) H, edges = np.histogramdd(r, bins = (numxcells, numycells, numzcells), range=(xrange,yrange,zrange), weights=S['m'][agecut][poscut]) cut = H>0 ix, iy, iz = np.where(cut) count = 0 Nums = [] cenx = [] ceny = [] cenz = [] #print 'iy ', iy #print 'len iy ',len(iy) #print 'edges ',edges #print 'len edges ',len(edges) while (count < len(ix)): theNum = H[ix[count],iy[count],iz[count]] thecenx = (edges[0][ix[count]] + edges[0][ix[count]+1])/2.0 theceny = (edges[1][iy[count]] + edges[1][iy[count]+1])/2.0 thecenz = (edges[2][iz[count]] + edges[2][iz[count]+1])/2.0 if (density_max_cell_center): cellxmin_cut = S['p'][:,0][agecut][poscut] > edges[0][ix[count]] cellxmax_cut = S['p'][:,0][agecut][poscut] < edges[0][ix[count]+1] cellymin_cut = S['p'][:,1][agecut][poscut] > edges[1][iy[count]] cellymax_cut = S['p'][:,1][agecut][poscut] < edges[1][iy[count]+1] cellzmin_cut = S['p'][:,2][agecut][poscut] > edges[2][iz[count]] cellzmax_cut = S['p'][:,2][agecut][poscut] < edges[2][iz[count]+1] allcut = cellxmin_cut* cellxmax_cut* cellymin_cut* cellymax_cut * cellzmin_cut * cellzmax_cut #print 'test test ',len(S['p'][:,0][agecut][poscut][allcut]), S['p'][:,0][agecut][poscut][allcut] if (len(S['p'][:,0][agecut][poscut][allcut]) > 5): #print 'first center ',[thecenx, theceny, thecenz], theNum S_COM = SF.gaussian_KDE_center(S['p'][:,0][agecut][poscut][allcut], S['p'][:,1][agecut][poscut][allcut] , S['p'][:,2][agecut][poscut][allcut] , downsample=False) [thecenx, theceny, thecenz] = S_COM #print 'adjusting center ',[thecenx, theceny, thecenz] Nums.append(theNum) cenx.append(thecenx) ceny.append(theceny) cenz.append(thecenz) count+=1 cenx = np.array(cenx) ceny = np.array(ceny) cenz = np.array(cenz) Nums = np.array(Nums) order_of_densities = np.argsort(Nums)[::-1] #cumsumdens = np.cumsum(Nums[order_of_densities]) sum_of_densities = np.sum(Nums) current_sum = 0 count = 0 final_x = [] final_y = [] final_z = [] final_Nums = [] #print 'densities in order ',Nums[order_of_densities] while (current_sum <= surface_frac * sum_of_densities): current_sum += Nums[order_of_densities][count] final_x.append(cenx[order_of_densities][count]) final_y.append(ceny[order_of_densities][count]) final_z.append(cenz[order_of_densities][count]) final_Nums.append( Nums[order_of_densities][count]) count+=1 return [final_x, final_y, final_z, final_Nums]
import numpy as np import Sasha_functions as SF import matplotlib.pyplot as plt from scipy.interpolate import interp1d from datetime import date today = date.today() Nhalo = 0 H = SF.read_halo_history(Nhalo) Zs = H['redshift'] IDs = H['ID'] Vsig = H['Vsig'] M = H['M'] Rvir = H['Rvir'] Vmax = H['Vmax'] newtonG = 6.67384e-8 little_h = 0.7 As = 1.0 / (1.0 + Zs) Vcirc = np.sqrt( (newtonG * M * 2e33 /little_h )/(Rvir * As * 3.08e21 / little_h)) / 1e5 Vsig1D = Vsig / np.sqrt(3) Ns = [] for theZ in Zs: theN = SF.N_for_z(theZ) Ns.append(theN) Ns = np.array(Ns) count = 0
boxsize = header[9] if wanted == 'rhoTwind': cutz = (np.absolute(partZ)>zdown) & (np.absolute(partZ)<zup) #kpc cutxy = partX*partX+partY*partY<withinr*withinr if cosmo==1: cutv = partXV*partX+partYV*partY\ +partZV*partZ>vcut*np.sqrt(partX*partX+partY*partY+partZ*partZ) #outflowing gas else: cutv = partZV*partZ/np.absolute(partZ)>vcut #outflowing gas cut = cutz*cutxy*cutv Tb = Tb[cut] rho = rho[cut] Neb = Neb[cut] Gmass = Gmass[cut] TrueTemp, converted_rho = SF.convertTemp(Tb, Neb, rho) if wanted == 'rhoT': if needcontour==1: totalname = 'CRplot/rhoT/rhoT_'+runtodo+'_sn'+str(startno)+'_'+str(Nsnap)+'_contour.pdf' else: totalname = 'CRplot/rhoT/rhoT_'+runtodo+'_sn'+str(startno)+'_'+str(Nsnap)+'.pdf' elif wanted == 'rhoTwind': if needcontour==1: totalname = 'CRplot/rhoTwind/rhoTwind_'+runtodo+'_sn'+str(startno)+'_'+str(Nsnap)+'_contour.pdf' else: totalname = 'CRplot/rhoTwind/rhoTwind_'+runtodo+'_sn'+str(startno)+'_'+str(Nsnap)+'.pdf' y = np.log10(TrueTemp) x = np.log10(converted_rho) gridxx = np.linspace(extent[0],extent[1],nobin) gridyy = np.linspace(extent[2],extent[3],nobin) #gridxx = np.linspace(np.amin(x),np.amax(x),nobin)
def surface_density_bycells(S, agecut, poscut, a, h, cell_length=0.3, surface_frac=0.8, density_max_cell_center=True): #r = np.random.randn(100,3) r = [ S['p'][:, 0][agecut][poscut], S['p'][:, 1][agecut][poscut], S['p'][:, 2][agecut][poscut] ] minx = np.min(S['p'][:, 0][agecut][poscut]) * a / h maxx = np.max(S['p'][:, 0][agecut][poscut]) * a / h miny = np.min(S['p'][:, 1][agecut][poscut]) * a / h maxy = np.max(S['p'][:, 1][agecut][poscut]) * a / h minz = np.min(S['p'][:, 2][agecut][poscut]) * a / h maxz = np.max(S['p'][:, 2][agecut][poscut]) * a / h numxcells = int((maxx - minx) / cell_length) + 1 numycells = int((maxy - miny) / cell_length) + 1 numzcells = int((maxz - minz) / cell_length) + 1 xrange = [ minx * h / a, (minx * h / a + float(numxcells) * cell_length * h / a) ] yrange = [ miny * h / a, (miny * h / a + float(numycells) * cell_length * h / a) ] zrange = [ minz * h / a, (minz * h / a + float(numzcells) * cell_length * h / a) ] # print 'diagnostic x',(xrange[1] - xrange[0])/(cell_length*h/a), numxcells # print 'diagnostic y',(yrange[1] - yrange[0])/(cell_length*h/a), numycells # print 'diagnostic x',(zrange[1] - zrange[0])/(cell_length*h/a), numzcells #rad should be in physical kpc #num_cells=int(rad*2.0/cell_length) H, edges = np.histogramdd(r, bins=(numxcells, numycells, numzcells), range=(xrange, yrange, zrange), weights=S['m'][agecut][poscut]) cut = H > 0 ix, iy, iz = np.where(cut) count = 0 Nums = [] cenx = [] ceny = [] cenz = [] #print 'iy ', iy #print 'len iy ',len(iy) #print 'edges ',edges #print 'len edges ',len(edges) while (count < len(ix)): theNum = H[ix[count], iy[count], iz[count]] thecenx = (edges[0][ix[count]] + edges[0][ix[count] + 1]) / 2.0 theceny = (edges[1][iy[count]] + edges[1][iy[count] + 1]) / 2.0 thecenz = (edges[2][iz[count]] + edges[2][iz[count] + 1]) / 2.0 if (density_max_cell_center): cellxmin_cut = S['p'][:, 0][agecut][poscut] > edges[0][ix[count]] cellxmax_cut = S['p'][:, 0][agecut][poscut] < edges[0][ix[count] + 1] cellymin_cut = S['p'][:, 1][agecut][poscut] > edges[1][iy[count]] cellymax_cut = S['p'][:, 1][agecut][poscut] < edges[1][iy[count] + 1] cellzmin_cut = S['p'][:, 2][agecut][poscut] > edges[2][iz[count]] cellzmax_cut = S['p'][:, 2][agecut][poscut] < edges[2][iz[count] + 1] allcut = cellxmin_cut * cellxmax_cut * cellymin_cut * cellymax_cut * cellzmin_cut * cellzmax_cut #print 'test test ',len(S['p'][:,0][agecut][poscut][allcut]), S['p'][:,0][agecut][poscut][allcut] if (len(S['p'][:, 0][agecut][poscut][allcut]) > 5): #print 'first center ',[thecenx, theceny, thecenz], theNum S_COM = SF.gaussian_KDE_center( S['p'][:, 0][agecut][poscut][allcut], S['p'][:, 1][agecut][poscut][allcut], S['p'][:, 2][agecut][poscut][allcut], downsample=False) [thecenx, theceny, thecenz] = S_COM #print 'adjusting center ',[thecenx, theceny, thecenz] Nums.append(theNum) cenx.append(thecenx) ceny.append(theceny) cenz.append(thecenz) count += 1 cenx = np.array(cenx) ceny = np.array(ceny) cenz = np.array(cenz) Nums = np.array(Nums) order_of_densities = np.argsort(Nums)[::-1] #cumsumdens = np.cumsum(Nums[order_of_densities]) sum_of_densities = np.sum(Nums) current_sum = 0 count = 0 final_x = [] final_y = [] final_z = [] final_Nums = [] #print 'densities in order ',Nums[order_of_densities] while (current_sum <= surface_frac * sum_of_densities): current_sum += Nums[order_of_densities][count] final_x.append(cenx[order_of_densities][count]) final_y.append(ceny[order_of_densities][count]) final_z.append(cenz[order_of_densities][count]) final_Nums.append(Nums[order_of_densities][count]) count += 1 return [final_x, final_y, final_z, final_Nums]
def calculate_escape_velocity(halo_pos, particle_pos, G, S, D, rmax): newtonG = 6.67384e-8 pc = 3.08567758e18 kpc = pc * 1e3 a = G['header'][2] h = G['header'][12] boxsize = G['header'][9] UnitMass_in_g = 1.989e43 / h do_plots = False Gdists = SF.calcdist2(halo_pos[0], halo_pos[1], halo_pos[2], G['p'][:, 0], G['p'][:, 1], G['p'][:, 2], boxsize) Sdists = SF.calcdist2(halo_pos[0], halo_pos[1], halo_pos[2], S['p'][:, 0], S['p'][:, 1], S['p'][:, 2], boxsize) Ddists = SF.calcdist2(halo_pos[0], halo_pos[1], halo_pos[2], D['p'][:, 0], D['p'][:, 1], D['p'][:, 2], boxsize) particle_dists = SF.calcdist2(halo_pos[0], halo_pos[1], halo_pos[2], particle_pos[0], particle_pos[1], particle_pos[2], boxsize) #print 'particle dist ',particle_dist Gcut = Gdists < rmax Scut = Sdists < rmax Dcut = Ddists < rmax Gdist_ord = np.argsort(Gdists[Gcut]) Ddist_ord = np.argsort(Ddists[Dcut]) Sdist_ord = np.argsort(Sdists[Scut]) #print Gdists[Gcut][Gdist_ord] GMenc_vsr = np.cumsum(G['m'][Gcut][Gdist_ord]) SMenc_vsr = np.cumsum(S['m'][Scut][Sdist_ord]) DMenc_vsr = np.cumsum(D['m'][Dcut][Ddist_ord]) # GM_for_r = interp1d(Gdists[Gcut][Gdist_ord], GMenc_vsr, kind='linear', bounds_error=False) # SM_for_r = interp1d(Sdists[Scut][Sdist_ord], SMenc_vsr, kind='linear', bounds_error=False) # DM_for_r = interp1d(Ddists[Dcut][Ddist_ord], DMenc_vsr, kind='linear', bounds_error=False) rspace = np.linspace(min(particle_dists) / 200.0, rmax, num=1000000) GM_for_r = np.interp(rspace, Gdists[Gcut][Gdist_ord], GMenc_vsr) SM_for_r = np.interp(rspace, Sdists[Scut][Sdist_ord], SMenc_vsr) DM_for_r = np.interp(rspace, Ddists[Dcut][Ddist_ord], DMenc_vsr) #print 'rspace ',rspace #print 'Ddists[Dcut][Ddist_ord] ',Ddists[Dcut][Ddist_ord] rspace_physical = rspace * a / h theM = GM_for_r + SM_for_r + DM_for_r initpot = (newtonG * theM[0]) / rspace_physical[0] dpot_array = newtonG * theM / rspace_physical**2.0 if (do_plots): fig1 = plt.figure(figsize=(10, 9)) plt.plot(rspace, theM, ':r') plt.savefig('alpha_test_mass.pdf') fig2 = plt.figure(figsize=(10, 9)) plt.plot(rspace, dpot_array, ':k') plt.savefig('alpha_test_pot.pdf') dr = (rspace_physical[-1] - rspace_physical[0]) / 1000000.0 #thepot_ar = scipy.integrate. thepot_ar = scipy.integrate.cumtrapz(dpot_array, x=rspace_physical, dx=dr, initial=initpot) #this is 0 to r thepot_cge_ar = thepot_ar * UnitMass_in_g / kpc mypot = thepot_cge_ar[-1] - np.interp(particle_dists, rspace, thepot_cge_ar) testpot = np.interp(1.0, rspace, thepot_cge_ar) print 'test pot alpha ', testpot vesc_cge = np.sqrt(mypot) / 1e5 #convert to km/s return vesc_cge
today = date.today() print today z_int_tolerance = 0.5 fhires_tolerance = 0.94 npart_tolerance = 5e4 doplots = 'y' if (len(sys.argv) < 2): print 'syntax blah.py haloN' sys.exit() haloN = int(sys.argv[1]) H = SF.read_halo_history(haloN) Zs = H['redshift'] ID = H['ID'] x = H['x'] y = H['y'] z = H['z'] vx = H['vx'] vy = H['vy'] vz = H['vz'] M = H['M'] Mstar = H['Mstar'] Mgas = H['Mgas'] host = H['host'] fhires = H['fhires'] ngas = H['ngas']
sys.exit() finname1 = str(sys.argv[1]) f = open(finname1) dars = np.loadtxt(f) f.close() SF_start = dars[:,13] SF_end = dars[:,15] Mstar = dars[:,8] eta = dars[:,17] epN = dars[:,0] cut1 = Mstar > Mstarlowlim cut2 = Mstar < Mstarupperlim cut = cut1*cut2 foutname = today+'relevant_snaps.txt' f = open(foutname, 'w') count = 0 while (count < len(SF_start[cut])): Nstart = N_for_T(SF_start[cut][count]) Nend = N_for_T(SF_end[cut][count]) print epN[cut][count], Mstar[cut][count]/1e10, Nstart, Nend, eta[cut][count] line = [epN[cut][count], Mstar[cut][count]/1e10, Nstart, Nend, eta[cut][count]] thestring = SF.line_to_string(line) f.write(thestring) count+=1 f.close()
D = readsnap(the_snapdir, Nsnapstring, 1, snapshot_name=the_prefix, extension=the_suffix) thetime = S['header'][2] redshift = S['header'][3] boxsize = S['header'][9] omega_matter = S['header'][10] omega_L = S['header'][11] h = S['header'][12] a = float(thetime) print 'using a = ',a theredshift = (1.0/a - 1) redshiftstring = "{0:.3f}".format(theredshift) print 'z = ',"{0:.3f}".format(theredshift) SFR_time_range, age_in_Gyr = SF.cut_stellar_age(a, Nsnap, S['age'], omega_matter, h) stellar_age_cut = age_in_Gyr < SFR_time_range/1e9 Syoung = stellar_age_cut Rstars = where_do_we_go * h / a RstarsPhys = where_do_we_go workcount = 0 Hubble = hubble_param(a, omega_matter, h) ########### #Work function ########### C = SF.read_halo_catalog(Nsnapstring, redshiftstring)
Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix) a = G['header'][2] redshift = G['header'][3] redshift1 = redshift boxsize = G['header'][9] omega_matter = G['header'][10] omega_L = G['header'][11] h = G['header'][12] redshiftstring = "{0:.3f}".format(redshift) Hubble = hubble_param(a, omega_matter, h) halostats = SF.find_halo_now(halo_to_do, a, therod=use_fixed_halos) haloN = halostats[1] #read halo catalog, assign halo properties Rvir = halostats[11] Vsig = halostats[10] haloX = halostats[2] haloY = halostats[3] haloZ = halostats[4] haloVX = halostats[5] haloVY = halostats[6] haloVZ = halostats[7] M = halostats[8] Mstar = halostats[13] Mgas = halostats[12] Vmax = halostats[9]
weight_avg_vesc = np.average(vesc_ar[count], weights=sig_ar[count]) print 'weighted average vesc ', weight_avg_vesc print '25th, 50th, 75th percentile vesc ', vesc_25, vesc_med, vesc_75 weighted_avg_sig = np.average(sig_ar[count], weights=sig_ar[count]) / area_of_cell print 'weighted average sig ', weighted_avg_sig unweighted_avg_sig = np.mean(sig_ar[count]) / area_of_cell print 'unweighted average sig ', unweighted_avg_sig myline = [ count, lasta_ar[count], Neps_ar[count], weight_avg_vesc, vesc_25, vesc_med, vesc_75, weighted_avg_sig, unweighted_avg_sig, maxSF_ar[count], totMass_ar[count], duration_ar[count] ] thar.append('z=' + str(lasta_ar[count])) mystring = SF.line_to_string(myline) f.write(mystring) shell_histresults = np.histogram(vesc_ar[count], num_bins, range=(0, 1000), weights=np.array(mass_ar[count]) / totalmass) [histx, histy] = ssp.create_plottable_hist(shell_histresults) plt.plot(histx, histy, color=color_ar[count], ls=ls_ar[count], lw=2, alpha=0.5) count += 1 plt.legend(thar, loc='best')
def gammasfrsnaptestinpput(subdict): dirneed=subdict['dirneed'] wanted=subdict['wanted'] startno=subdict['startno'] Nsnap=subdict['Nsnap'] snapsep=subdict['snapsep'] the_prefix=subdict['the_prefix'] the_suffix=subdict['the_suffix'] fmeat=subdict['fmeat'] if wanted=='dirgammasfr' or wanted=='dirgamma' or wanted=='dirsfr' or wanted=='dirsm': plt.figure(figsize=(5,4)) Rfrac=0.25 #Rfrac=0.03 xaxis_snapno=0 normalizedsm=subdict['normalizedsm'] M1labelneed=subdict['M1labelneed'] M1runlabelneed=subdict['M1runlabelneed'] resoneed=subdict['resoneed'] diffusionsolverneed=subdict['diffusionsolverneed'] newlabelneed=subdict['newlabelneed'] strlabelneed=subdict['strlabelneed'] showstarburst=subdict['showstarburst'] legendneed=subdict['legendneed'] correctIa=subdict['correctIa'] refereelabelneed=subdict['refereelabelneed'] for runtodo in dirneed: print 'runtodo', runtodo snaplist=[] enclist=[] englist=[] enllist=[] sml=[] diskml=[] bulgeml=[] nsml=[] timel=[] Lgcalist=[] pretime=0 presnap=startno havecr=0 if wanted=='dirgammasfr' or wanted=='dirgamma': info=outdirname(runtodo, Nsnap) havecr=info['havecr'] if havecr==0: continue for i in range(startno,Nsnap, snapsep): info=outdirname(runtodo, i) rundir=info['rundir'] maindir=info['maindir'] halostr=info['halostr'] runtitle=info['runtitle'] slabel=info['slabel'] snlabel=info['snlabel'] dclabel=info['dclabel'] resolabel=info['resolabel'] the_snapdir=info['the_snapdir'] Nsnapstring=info['Nsnapstring'] havecr=info['havecr'] Fcal=info['Fcal'] iavesfr=info['iavesfr'] timestep=info['timestep'] cosmo=info['cosmo'] color=info['color'] withinRv=info['withinRv'] usepep=info['usepep'] beginno=info['beginno'] finalno=info['finalno'] firever=info['firever'] initsnap=info['initsnap'] haveB=info['haveB'] M1speed=info['M1speed'] Rvirguess=info['Rvir'] newlabel=info['newlabel'] strlabel=info['strlabel'] labelneed=dclabel if newlabelneed==1: labelneed="\n".join(wrap(newlabel,17)) if strlabelneed==1: labelneed="\n".join(wrap(strlabel,40)) ptitle=title if runtitle=='SMC': ptitle='Dwarf' elif runtitle=='SBC': ptitle='Starburst' elif runtitle=='MW': ptitle=r'$L\star$ Galaxy' if cosmo==0: inittime=initsnap else: inittime=0 print 'set initial time' print 'the_snapdir', the_snapdir print 'Nsnapstring', Nsnapstring print 'havecr', havecr print 'withinRv', withinRv print 'cosmo', cosmo try: if cosmo==1: G = readsnapcr(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr,h0=1,cosmological=1) S = readsnapcr(the_snapdir, Nsnapstring, 4, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr,h0=1,cosmological=1) if correctIa==1: Disk = readsnapcr(the_snapdir, Nsnapstring, 2, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr,h0=1,cosmological=1) Bulge = readsnapcr(the_snapdir, Nsnapstring, 3, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr,h0=1,cosmological=1) else: G = readsnapcr(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr) S = readsnapcr(the_snapdir, Nsnapstring, 4, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr) if correctIa==1: Disk = readsnapcr(the_snapdir, Nsnapstring, 2, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr) Bulge = readsnapcr(the_snapdir, Nsnapstring, 3, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr) if havecr>4: cregyl = G['cregyl']*1e10*solar_mass_in_g*km_in_cm*km_in_cm #in erg (originally in code unit: 1e10Msun*(km/s)^2) cregyg = G['cregyg']*1e10*solar_mass_in_g*km_in_cm*km_in_cm if havecr > 0: cregy_codeunit = G['cregy'] cregy = cregy_codeunit*1e10*solar_mass_in_g*km_in_cm*km_in_cm Grho = G['rho'] Neb = G['ne'] except KeyError: print 'Keyerror' break try: header=S['header'] timeneed=header[2] print 'timeneed', timeneed Smi=S['m'] Sage=S['age'] if withinRv ==1 and cosmo==1: Sp = S['p'] Sx = Sp[:,0] Sy = Sp[:,1] Sz = Sp[:,2] header=readsnapcr(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr,h0=1,cosmological=1,header_only=1) h0 = header['hubble'] atime = header['time'] if usepep==1: halosA = SF.read_halo_history_pep(rundir, finalno, beginno=beginno,\ singlesnap=0, firever=firever,halonostr=halostr, hubble=h0, comoving=1, maindir=maindir) afactor=atime else: halosA = SF.read_halo_history(rundir, maindir=maindir, halonostr=halostr, hubble=h0, comoving=0) afactor=1.0 redlist = halosA['redshift'] haloid = halosA['ID'] a_scale = 1.0/(1.0+redlist) xcenl = halosA['x']*afactor ycenl = halosA['y']*afactor zcenl = halosA['z']*afactor Rvirl = halosA['R']*afactor xcen = np.interp(atime,a_scale,xcenl) ycen = np.interp(atime,a_scale,ycenl) zcen = np.interp(atime,a_scale,zcenl) Rvir = np.interp(atime,a_scale,Rvirl) Sxrel = Sx-xcen Syrel = Sy-ycen Szrel = Sz-zcen Sr = np.sqrt(Sxrel*Sxrel+Syrel*Syrel+Szrel*Szrel) cutrvs = Sr<Rvir*Rfrac Smi = Smi[cutrvs] Sage = Sage[cutrvs] Sm = np.sum(Smi)*1e10 #in solar mass tcut=Sage>pretime Nsm = np.sum(Smi[tcut])*1e10 if correctIa==1: diskm = np.sum(Disk['m'])*1e10 bulgem = np.sum(Bulge['m'])*1e10 except KeyError: print 'key error' Sm = 0. Nsm = 0. timeneed=0 if correctIa==1: diskm = 0. bulgem = 0. if withinRv ==1: Gp = G['p'] Gx = Gp[:,0] Gy = Gp[:,1] Gz = Gp[:,2] header=readsnapcr(the_snapdir, Nsnapstring, 0, snapshot_name=the_prefix, extension=the_suffix, havecr=havecr,h0=1,cosmological=1,header_only=1) h0 = header['hubble'] atime = header['time'] if cosmo==1: if usepep==1: halosA = SF.read_halo_history_pep(rundir, finalno,\ beginno=beginno, singlesnap=0, firever=firever,halonostr=halostr,\ hubble=h0, comoving=1, maindir=maindir, snapsep=snapsep) afactor=atime else: halosA = SF.read_halo_history(rundir, maindir=maindir, halonostr=halostr, hubble=h0, comoving=0) afactor=1.0 redlist = halosA['redshift'] haloid = halosA['ID'] a_scale = 1.0/(1.0+redlist) xcenl = halosA['x']*afactor ycenl = halosA['y']*afactor zcenl = halosA['z']*afactor Rvirl = halosA['R']*afactor xcen = np.interp(atime,a_scale,xcenl) ycen = np.interp(atime,a_scale,ycenl) zcen = np.interp(atime,a_scale,zcenl) Rvir = np.interp(atime,a_scale,Rvirl) else: xcen=0 ycen=0 zcen=0 Rvir=Rvirguess Gxrel = Gx-xcen Gyrel = Gy-ycen Gzrel = Gz-zcen Gr = np.sqrt(Gxrel*Gxrel+Gyrel*Gyrel+Gzrel*Gzrel) cutrv = Gr<Rvir*Rfrac Grho = Grho[cutrv] Neb = Neb[cutrv] if havecr>0: cregy = cregy[cutrv] cregy_codeunit = cregy_codeunit[cutrv] if havecr>4: cregyl = cregyl[cutrv] cregyg = cregyg[cutrv] if cosmo==1: readtimelist=readtime(firever=2) snap2list=readtimelist['snaplist'] time2list=readtimelist['timelist'] a2list=readtimelist['alist'] tnow = np.interp(timeneed,a2list,time2list)*1e9 pret = np.interp(pretime,a2list,time2list)*1e9 if havecr>4: cregygt=np.sum(cregyg) cregylt=np.sum(cregyl) if havecr>0: cregyt =np.sum(cregy) Lout = outLgamma_nism(Grho,Neb,cregy_codeunit) Lgcal = np.sum(Lout['Lgamma']) print 'Lgcal', Lgcal snaplist.append(float(i)) if cosmo==1: timel.append(tnow) else: timel.append(float(i)*0.98*1e6) if havecr>0: enclist.append(cregyt) if havecr>4: englist.append(cregygt) enllist.append(cregylt) if havecr>0: Lgcalist.append(Lgcal) sml.append(Sm) if correctIa==1: diskml.append(diskm) bulgeml.append(bulgem) nsml.append(Nsm) pretime=timeneed del G, S sml=np.array(sml) if correctIa==1: diskml=np.array(diskml) bulgeml=np.array(bulgeml) nsml=np.array(nsml) if havecr>0: enclist=np.array(enclist) if havecr>4: englist=np.array(englist) enllist=np.array(enllist) snaplist=np.array(snaplist) if havecr>0: Lgcalist=np.array(Lgcalist) timel=np.array(timel) #in yr #above is the coefficient for Salpeter only; for Kroupa, the coefficient is 50% larger: avesfrl=(nsml[1:])/(timel[1:]-timel[:-1]) #in Msun/yr print 'nsml',nsml print 'avesfrl', avesfrl Lsfr = Kroupa_Lsf*avesfrl*solar_mass_in_g/yr_in_sec*cspeed_in_cm_s*cspeed_in_cm_s #times 1.5? 6.2e-4 for Kroupa 3.8e-4 for Salpeter if correctIa==1: IaeffSFR=5.3e-8/3.0e-4*(sml[1:]+diskml[1:]+bulgeml[1:])/0.03753/1e9 print 'IaeffSFR', IaeffSFR LsfrnoIa = Kroupa_Lsf*(avesfrl+IaeffSFR)*solar_mass_in_g/yr_in_sec*cspeed_in_cm_s*cspeed_in_cm_s print 'Lsfr', Lsfr print 'timel', timel if havecr>4: Lgamma = (enllist[1:]-enllist[:-1])/((timel[1:]-timel[:-1])*yr_in_sec)/(hadronicdecayrate+coulombdecayrate)*hadronicdecayrate*betapi/nopi_per_gamma Lgamma_sfr = Lgamma/Lsfr if havecr>0: Lgcal_sfr = Lgcalist[1:]/Lsfr if correctIa==1: Lgamma_sfr_noIa = Lgamma/LsfrnoIa if haveB>0: lsn='dashed' else: lsn='solid' if M1labelneed>1 or M1runlabelneed==1: if M1speed>499: lsn='solid' if M1speed>999: lsn='dashed' if M1speed>1999: lsn='dashdot' if M1speed>3999: lsn='dotted' if M1labelneed==1: if M1speed>499: labelneed=r'$\tilde{c}=500$' if M1speed>999: labelneed=r'$\tilde{c}=1000$' if M1speed>1999: labelneed=r'$\tilde{c}=2000$' if M1speed>3999: labelneed=r'$\tilde{c}=4000$' if resoneed==1: if resolabel=='llr': labelneed='Lowest res' lsn = 'solid' if resolabel=='lr': labelneed='Low res' lsn = 'dashed' if resolabel=='mr': labelneed='Standard res' lsn = 'dashdot' if diffusionsolverneed==1: if runtodo=='bwmwlrdc27ds': labelneed='Zeroth moment' lsn = 'dashed' else: labelneed='Two moment' lsn = 'solid' if refereelabelneed==1: if runtodo=='bwsmclrdc28mhdref' or runtodo=='bwmwlrdc28mhdref': labelneed='Modified' else: labelneed='Original' if xaxis_snapno==1: xaxisl = snaplist[1:] xlab = 'snapshot number' else: xaxisl = timel[1:]/1e6+inittime xlab = 'Myr' if showstarburst==1 and runtitle=='SBC': if runtodo=='bwsbclr': pstartno=600 if runtodo=='bwsbclrdc0': pstartno=590 if runtodo=='bwsbclrdc27': pstartno=440 if runtodo=='bwsbclrdc28': pstartno=505 if runtodo=='bwsbclrdc29': pstartno=370 print 'labelneed', labelneed if wanted=='dirgammasfr': if havecr>4: #plt.plot(xaxisl, np.absolute(Lgamma_sfr), color=color,ls=lsn,lw=2, label=labelneed) if (M1labelneed==1 and color=='r'): plt.plot(xaxisl, np.absolute(Lgamma_sfr), color=color,ls=lsn,lw=2) elif (M1labelneed==2 and lsn=='solid'): plt.plot(xaxisl, np.absolute(Lgamma_sfr), color=color,ls=lsn,lw=2, label=labelneed) else: plt.plot(xaxisl, np.absolute(Lgamma_sfr), color=color,ls=lsn,lw=2, label=labelneed) #print 'M1speed', M1speed print 'Lgamma_sfr', Lgamma_sfr elif havecr>0: plt.plot(xaxisl, np.absolute(Lgcal_sfr), color=color,ls=lsn,lw=2, label=labelneed) print 'Lgcal_sfr', Lgcal_sfr if correctIa==1 and havecr>0: plt.plot(xaxisl, np.absolute(Lgamma_sfr_noIa),ls=lsn,lw=2, color=color) print 'Lgamma_sfr_noIa', Lgamma_sfr_noIa if wanted=='dirgamma': if havecr>4: plt.plot(xaxisl, np.absolute(Lgamma), color=color,ls=lsn,lw=2, label=labelneed) elif havecr>0: plt.plot(xaxisl, np.absolute(Lgcalist[1:]), color=color,ls=lsn,lw=2, label=labelneed) if wanted=='dirsfr': if M1labelneed==1 and color=='r': plt.plot(xaxisl, np.absolute(avesfrl), color=color,ls=lsn,lw=2) elif M1speed<501 and (M1runlabelneed==1 or M1labelneed==1): plt.plot(xaxisl, np.absolute(avesfrl), color=color,ls=lsn,lw=2, label=labelneed) else: plt.plot(xaxisl, np.absolute(avesfrl), color=color,ls=lsn,lw=2, label=labelneed) if showstarburst==1 and runtitle=='SBC': plt.axvline(x=pstartno, color=color,ls=lsn,lw=1) if wanted=='dirsm': if M1labelneed==1 and color=='r': if normalizedsm==1: plt.plot(xaxisl, sml[:-1]-sml[0], color=color,ls=lsn,lw=2) else: plt.plot(xaxisl, sml[1:], color=color,ls=lsn,lw=2) else: if normalizedsm==1: plt.plot(xaxisl, sml[:-1]-sml[0], color=color,ls=lsn,lw=2, label=labelneed) else: plt.plot(xaxisl, sml[1:], color=color,ls=lsn,lw=2, label=labelneed) if showstarburst==1 and runtitle=='SBC': plt.axvline(x=pstartno, color=color,ls='dashed',lw=1) if wanted=='dirgammasfr': plt.axhline(y=0.0002,ls='--',color='k') plt.yscale('log') if runtitle=='SMC' and legendneed==1: plt.legend(loc='best', fontsize=8) elif legendneed==1 and M1runlabelneed==1: plt.legend(loc='best', fontsize=8,ncol=2) plt.xlabel(xlab, fontsize=16) plt.ylabel(r'$L_{\gamma}/L_{\rm SF}$', fontsize=16) figname=plotloc+'CRplot/dirgammasfr/gammasfrsnap_'+fmeat+'.pdf' if wanted=='dirgamma': plt.yscale('log') if runtitle=='SMC' or legendneed==1: plt.legend(loc='best', fontsize=8,ncol=3) if legendneed==1 and M1runlabelneed: plt.legend(loc='best', fontsize=8,ncol=2) plt.xlabel(xlab, fontsize=16) plt.ylabel(r'$L_{\gamma} {\rm erg/s}$', fontsize=16) figname=plotloc+'CRplot/dirgamma/gammasnap_'+fmeat+'.pdf' if wanted=='dirsfr': plt.yscale('log') if runtitle=='SMC' or legendneed==1: plt.legend(loc='best', fontsize=8,ncol=3) if M1labelneed==1 and legendneed==1: plt.legend(loc='best', fontsize=8,ncol=2) plt.xlabel(xlab, fontsize=16) plt.ylabel(r'${\rm SFR (M_{\odot}/yr)} $', fontsize=16) figname=plotloc+'CRplot/dirsfr/sfrsnap_'+fmeat+'.pdf' if wanted=='dirsm': if runtitle=='SMC' and legendneed==1: if strlabelneed==1 or M1labelneed==1: plt.legend(loc='best', fontsize=10,ncol=2) else: plt.legend(loc='best', fontsize=8,ncol=3) plt.xlabel('Myr', fontsize=16) plt.ticklabel_format(style='sci',axis='y',scilimits=(0,0)) if normalizedsm==1: plt.ylabel(r'${\rm M_{*,new} (M_{\odot})} $', fontsize=16) else: plt.ylabel(r'${\rm M_* (M_{\odot})} $', fontsize=16) if normalizedsm==1: figname=plotloc+'CRplot/dirsm/nsm_'+fmeat+'.pdf' else: figname=plotloc+'CRplot/dirsm/sm_'+fmeat+'.pdf' print 'Saving ', figname plt.title(ptitle,fontsize=16) plt.tick_params(axis='both', which='both',direction='in',bottom=True,top=True,left=True,right=True,labelsize=16) plt.subplots_adjust(left = 0.18, bottom=0.15, right=0.95, top=0.9) #plt.tight_layout() plt.savefig(figname) plt.clf() return None
dists = SF.calcdist2(haloX, haloY, haloZ, Stars['p'][:,0], Stars['p'][:,1], Stars['p'][:,2], boxsize) cut = dists < theRvir * rvirFac StellarMass = np.sum(Stars['m'][cut]) StellarDens = StellarMass / ((4.0/3.0) * 3.14159 * (theRvir* rvirFac)**3.0) return StellarDens if (len(sys.argv)<2): print 'syntax blah.py haloN [Zmin]' sys.exit() haloN = int(sys.argv[1]) halo_number_string = str(haloN) if (haloN < 10): halo_number_string='0'+halo_number_string H = SF.read_halo_history(haloN, rod=use_fixed_halos) Zs = H['redshift'] ID = H['ID'] x = H['x'] y = H['y'] z = H['z'] vx = H['vx'] vy = H['vy'] vz = H['vz'] M = H['M'] Mstar = H['Mstar'] Mgas = H['Mgas'] host = H['host'] fhires = H['fhires'] ngas = H['ngas']
def calculate_escape_velocity(halo_pos, particle_pos, G, S, D, rmax): newtonG = 6.67384e-8 pc = 3.08567758e18 kpc = pc * 1e3 a = G['header'][2] h = G['header'][12] boxsize = G['header'][9] UnitMass_in_g=1.989e43 / h do_plots = False Gdists = SF.calcdist2(halo_pos[0], halo_pos[1], halo_pos[2], G['p'][:,0], G['p'][:,1], G['p'][:,2], boxsize) Sdists = SF.calcdist2(halo_pos[0], halo_pos[1], halo_pos[2], S['p'][:,0], S['p'][:,1], S['p'][:,2], boxsize) Ddists = SF.calcdist2(halo_pos[0], halo_pos[1], halo_pos[2], D['p'][:,0], D['p'][:,1], D['p'][:,2], boxsize) particle_dists = SF.calcdist2(halo_pos[0], halo_pos[1], halo_pos[2], particle_pos[0], particle_pos[1], particle_pos[2], boxsize) #print 'particle dist ',particle_dist Gcut = Gdists < rmax Scut = Sdists < rmax Dcut = Ddists < rmax Gdist_ord = np.argsort(Gdists[Gcut]) Ddist_ord = np.argsort(Ddists[Dcut]) Sdist_ord = np.argsort(Sdists[Scut]) #print Gdists[Gcut][Gdist_ord] GMenc_vsr = np.cumsum(G['m'][Gcut][Gdist_ord]) SMenc_vsr = np.cumsum(S['m'][Scut][Sdist_ord]) DMenc_vsr = np.cumsum(D['m'][Dcut][Ddist_ord]) # GM_for_r = interp1d(Gdists[Gcut][Gdist_ord], GMenc_vsr, kind='linear', bounds_error=False) # SM_for_r = interp1d(Sdists[Scut][Sdist_ord], SMenc_vsr, kind='linear', bounds_error=False) # DM_for_r = interp1d(Ddists[Dcut][Ddist_ord], DMenc_vsr, kind='linear', bounds_error=False) rspace = np.linspace(min(particle_dists)/200.0, rmax, num=1000000) GM_for_r = np.interp(rspace, Gdists[Gcut][Gdist_ord], GMenc_vsr) SM_for_r = np.interp(rspace, Sdists[Scut][Sdist_ord], SMenc_vsr) DM_for_r = np.interp(rspace, Ddists[Dcut][Ddist_ord], DMenc_vsr) #print 'rspace ',rspace #print 'Ddists[Dcut][Ddist_ord] ',Ddists[Dcut][Ddist_ord] rspace_physical = rspace*a / h theM = GM_for_r + SM_for_r + DM_for_r initpot = (newtonG * theM[0])/rspace_physical[0] dpot_array = newtonG * theM / rspace_physical**2.0 if (do_plots): fig1 = plt.figure(figsize=(10,9)) plt.plot(rspace, theM, ':r') plt.savefig('alpha_test_mass.pdf') fig2 = plt.figure(figsize=(10,9)) plt.plot(rspace, dpot_array, ':k') plt.savefig('alpha_test_pot.pdf') dr = (rspace_physical[-1] - rspace_physical[0])/1000000.0 #thepot_ar = scipy.integrate. thepot_ar = scipy.integrate.cumtrapz(dpot_array, x=rspace_physical, dx=dr, initial=initpot) #this is 0 to r thepot_cge_ar = thepot_ar * UnitMass_in_g / kpc mypot = thepot_cge_ar[-1] - np.interp(particle_dists, rspace, thepot_cge_ar) testpot = np.interp(1.0, rspace, thepot_cge_ar) print 'test pot alpha ',testpot vesc_cge = np.sqrt(mypot) / 1e5 #convert to km/s return vesc_cge
def calc_stellar_dens(Stars, haloX, haloY, haloZ, theRvir, rvirFac, boxsize): dists = SF.calcdist2(haloX, haloY, haloZ, Stars['p'][:,0], Stars['p'][:,1], Stars['p'][:,2], boxsize) cut = dists < theRvir * rvirFac StellarMass = np.sum(Stars['m'][cut]) StellarDens = StellarMass / ((4.0/3.0) * 3.14159 * (theRvir* rvirFac)**3.0) return StellarDens
today = date.today() print today z_int_tolerance = 0.5 fhires_tolerance = 0.94 npart_tolerance = 5e4 doplots = 'y' if (len(sys.argv)<2): print 'syntax blah.py haloN' sys.exit() haloN = int(sys.argv[1]) H = SF.read_halo_history(haloN) Zs = H['redshift'] ID = H['ID'] x = H['x'] y = H['y'] z = H['z'] vx = H['vx'] vy = H['vy'] vz = H['vz'] M = H['M'] Mstar = H['Mstar'] Mgas = H['Mgas'] host = H['host'] fhires = H['fhires'] ngas = H['ngas']
StellarMass = np.sum(Stars['m'][cut]) StellarDens = StellarMass / ((4.0 / 3.0) * 3.14159 * (theRvir * rvirFac)**3.0) return StellarDens if (len(sys.argv) < 2): print 'syntax blah.py haloN [Zmin]' sys.exit() haloN = int(sys.argv[1]) halo_number_string = str(haloN) if (haloN < 10): halo_number_string = '0' + halo_number_string H = SF.read_halo_history(haloN, rod=use_fixed_halos) Zs = H['redshift'] ID = H['ID'] x = H['x'] y = H['y'] z = H['z'] vx = H['vx'] vy = H['vy'] vz = H['vz'] M = H['M'] Mstar = H['Mstar'] Mgas = H['Mgas'] host = H['host'] fhires = H['fhires'] ngas = H['ngas']
Total_metal_mass = (np.sum(Stellar_met*S['m']) + np.sum(Metallicity*G['m'])) OxyYield = (np.sum(Stellar_oxygen*S['m']) + np.sum(Gas_oxygen*G['m'])) / np.sum(S['m']) EmpiricalYield = Total_metal_mass / np.sum(S['m']) a = G['header'][2] z = 1.0/a - 1.0 redshift = G['header'][3] boxsize = G['header'][9] omega_matter = G['header'][10] omega_L = G['header'][11] h = G['header'][12] redshiftstring = "{0:.3f}".format(redshift) Hubble = hubble_param(a, omega_matter, h) PhysTemp, PhysRho = SF.convertTemp(G['u'], G['ne'], G['rho'], h) halostats = SF.find_halo_now(halo_to_do, a, therod=use_fixed_halos) print 'halo stats', halostats haloN = halostats[1] #read halo catalog, assign halo properties Rvir = halostats[11] Vsig = halostats[10] haloX = halostats[2] haloY = halostats[3] haloZ = halostats[4] haloVX =halostats[5] haloVY = halostats[6] haloVZ = halostats[7]
f = open(finname1) dars = np.loadtxt(f) f.close() SF_start = dars[:, 13] SF_end = dars[:, 15] Mstar = dars[:, 8] eta = dars[:, 17] epN = dars[:, 0] cut1 = Mstar > Mstarlowlim cut2 = Mstar < Mstarupperlim cut = cut1 * cut2 foutname = today + 'relevant_snaps.txt' f = open(foutname, 'w') count = 0 while (count < len(SF_start[cut])): Nstart = N_for_T(SF_start[cut][count]) Nend = N_for_T(SF_end[cut][count]) print epN[cut][count], Mstar[cut][count] / 1e10, Nstart, Nend, eta[cut][ count] line = [ epN[cut][count], Mstar[cut][count] / 1e10, Nstart, Nend, eta[cut][count] ] thestring = SF.line_to_string(line) f.write(thestring) count += 1 f.close()