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
Mgas = halostats[12] Vmax = halostats[9] print Rvir, Vsig, M, 'before' Rvir, Vsig, M = SF.check_Rvir_growth(halo_to_do, a, Rvir, Vsig, M, therod=use_fixed_halos) print Rvir, Vsig, M, 'after' if (use_OuterBoundary): Rvir = OuterBoundary_physical * h / a #setting the locations of each spherical shell, as a fraction of Rvir R_bin_array_min = np.array([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]) R_bin_array_max = R_bin_array_min+0.1 Gclose = OR.prepare_X_close(G, Rvir, haloX, haloY, haloZ) Gdists = SF.calcdist2(haloX, haloY, haloZ, G['p'][:,0][Gclose], G['p'][:,1][Gclose], G['p'][:,2][Gclose], boxsize) Ghalo = Gdists < Rvir #Hubble = hubble_param(a, omega_matter, h) GprelX = G['p'][:,0][Gclose][Ghalo] - haloX GprelY = G['p'][:,1][Gclose][Ghalo] - haloY GprelZ = G['p'][:,2][Gclose][Ghalo] - haloZ GvrelX = G['v'][:,0][Gclose][Ghalo] * np.sqrt(a) - haloVX + GprelX*a*Hubble/(h*1000) GvrelY = G['v'][:,1][Gclose][Ghalo] * np.sqrt(a) - haloVY + GprelY*a*Hubble/(h*1000) GvrelZ = G['v'][:,2][Gclose][Ghalo] * np.sqrt(a) - haloVZ + GprelZ*a*Hubble/(h*1000) #rescale positions so that magnitude = 1 (unit vectors) GprelX_RS = GprelX / Gdists[Ghalo] GprelY_RS = GprelY / Gdists[Ghalo]
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
M = halostats[8] Mstar = halostats[13] Mgas = halostats[12] Vmax = halostats[9] print Rvir, Vsig, M, 'before' Rvir, Vsig, M = SF.check_Rvir_growth(halo_to_do, a, Rvir, Vsig, M, therod=use_fixed_halos) print Rvir, Vsig, M, 'after' Gclose = OR.prepare_X_close(G, Rvir, haloX, haloY, haloZ) Gdists = SF.calcdist2(haloX, haloY, haloZ, G['p'][:, 0][Gclose], G['p'][:, 1][Gclose], G['p'][:, 2][Gclose], boxsize) Ghalo = Gdists < Rvir TempCutISM = PhysTemp[Gclose][Ghalo] < TempBound1 TempCutCGMCool = PhysTemp[Gclose][Ghalo] < TempBound2 TempCutCGMWarm = (PhysTemp[Gclose][Ghalo] >= TempBound2) * (PhysTemp[Gclose][Ghalo] < TempBound3) TempCutCGMHot = PhysTemp[Gclose][Ghalo] >= TempBound3 ISMDensCut = PhysRho[Gclose][Ghalo] > 0.1 MISM1 = np.sum(G['m'][Gclose][Ghalo][ISMDensCut]) * 1e10 / h MISM2 = np.sum(G['m'][Gclose][Ghalo][ISMDensCut * TempCutISM]) * 1e10 / h MCGM1 = np.sum( G['m'][Gclose][Ghalo][TempCutCGMCool * np.invert(ISMDensCut)]) * 1e10 / h
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] AHF_haloX = x[count] AHF_haloY = y[count] AHF_haloZ = z[count] AHF_Rvir = Rvir[count] AHF_a = 1.0 / (1.0 + Zs[count]) if (adaptive_Rstar): Rstars = Inner_SF_thresh * Rvir[count] RstarsPhys = Rstars * AHF_a / h Sdists = SF.calcdist2(AHF_haloX, AHF_haloY, AHF_haloZ, S['p'][:, 0], S['p'][:, 1], S['p'][:, 2], boxsize) Sinner = Sdists < Rstars S_COM = SF.gaussian_KDE_center(S['p'][:, 0][Sinner], S['p'][:, 1][Sinner], S['p'][:, 2][Sinner], downsample=True) Shalo = Sdists < AHF_Rvir S_COM_grand = SF.gaussian_KDE_center(S['p'][:, 0][Shalo], S['p'][:, 1][Shalo], S['p'][:, 2][Shalo], downsample=True) iSinX.append(S_COM[0]) iSinY.append(S_COM[1]) iSinZ.append(S_COM[2]) ShalX.append(S_COM_grand[0])
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
redshift = S['header'][3] boxsize = S['header'][9] omega_matter = S['header'][10] omega_L = S['header'][11] h = S['header'][12] AHF_haloX = x[count] AHF_haloY = y[count] AHF_haloZ = z[count] AHF_Rvir = Rvir[count] AHF_a = 1.0 / (1.0 + Zs[count]) if (adaptive_Rstar): Rstars = Inner_SF_thresh*Rvir[count] RstarsPhys = Rstars * AHF_a / h Sdists = SF.calcdist2(AHF_haloX, AHF_haloY, AHF_haloZ, S['p'][:,0], S['p'][:,1], S['p'][:,2], boxsize) Sinner = Sdists<Rstars S_COM = SF.gaussian_KDE_center(S['p'][:,0][Sinner], S['p'][:,1][Sinner], S['p'][:,2][Sinner], downsample=True) Shalo = Sdists < AHF_Rvir S_COM_grand = SF.gaussian_KDE_center(S['p'][:,0][Shalo], S['p'][:,1][Shalo], S['p'][:,2][Shalo], downsample=True) iSinX.append(S_COM[0]) iSinY.append(S_COM[1]) iSinZ.append(S_COM[2]) ShalX.append(S_COM_grand[0]) ShalY.append(S_COM_grand[1]) ShalZ.append(S_COM_grand[2]) D = readsnap(the_snapdir, Nsnapstring, 1, snapshot_name=the_prefix, extension=the_suffix) Ddists = SF.calcdist2(AHF_haloX, AHF_haloY, AHF_haloZ, D['p'][:,0], D['p'][:,1], D['p'][:,2], boxsize) Dinner = Ddists < Rstars
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
haloZ = halostats[4] Mstar = halostats[13] Vsig = halostats[10] Mgas = halostats[12] M = halostats[4] Rvir, Vsig, M = SF.check_Rvir_growth(halo_to_do[workcount], a, Rvir, Vsig, M, therod=use_fixed_halos) if (adaptive_Rstar): Rstars = Inner_SF_thresh*Rvir RstarsPhys = Rstars * a / h Sdists = SF.calcdist2(haloX, haloY, haloZ, S['p'][:,0], S['p'][:,1], S['p'][:,2], boxsize) Sinner_young = Sdists[Syoung] < Rstars if (use_KDE_cent): Sinner = Sdists<Rstars S_COM = SF.gaussian_KDE_center(S['p'][:,0][Sinner], S['p'][:,1][Sinner], S['p'][:,2][Sinner], downsample=True) [haloX, haloY, haloZ] = [S_COM[0], S_COM[1], S_COM[2]] Sdists = SF.calcdist2(haloX, haloY, haloZ, S['p'][:,0], S['p'][:,1], S['p'][:,2], boxsize) Sinner_young = Sdists[Syoung] < Rstars elif (use_darkKDE_cent): #dark matter fun Ddists = SF.calcdist2(haloX, haloY, haloZ, D['p'][:,0], D['p'][:,1], D['p'][:,2], boxsize) Dinner = Ddists<Rstars D_COM = SF.gaussian_KDE_center(D['p'][:,0][Dinner], D['p'][:,1][Dinner], D['p'][:,2][Dinner], downsample=True) [haloX, haloY, haloZ] = [D_COM[0], D_COM[1], D_COM[2]] Sdists = SF.calcdist2(haloX, haloY, haloZ, S['p'][:,0], S['p'][:,1], S['p'][:,2], boxsize)