def virial_radius(logMhalo, redshift, delta=200., rhocrit=True, BryanNorman=False, WMAP=False, COSHalos=False): """Calculate the virial radius of a galaxy. --- Inputs: --- logMhalo: Halo mass(es). redshift: Galaxy redshift delta=200: Overdensity (Default=200) rhocrit: Use the critical density (Default=True); alternately the mean density of the universe. WMAP: Use WMAP9 cosmology. (Default=False) BryanNorman: Use the Bryan & Norman (1998) scaling (Default=False) COSHalos: Use the COS-Halos assumptions (Default=False) """ import numpy as np import astropy.units as u import astropy.constants as c # Set some terms based on the COSHalos flag, which matches the calculations # from the COS-Halos work (Prochaska+ 2017). # # This overrides the other user-set flags. if COSHalos: BryanNorman=True WMAP=True rhocrit=True # Choose the cosmology. Default is Plank15. if WMAP: from astropy.cosmology import WMAP9 as cosmo else: from astropy.cosmology import Planck15 as cosmo # Use the Bryan & Norman (2008) definition of Rvir? Default: False # # This overrides user-set flags for delta and rhocrit. if BryanNorman: # Overdensity depends on redshift: x = cosmo.Om(redshift)-1. delta = (18.*np.pi**2+82.*x-39.*x**2) # Also assume critical density scaling: rhocrit = True # Choose whether to scale by mean or critical density. Default: Critical if rhocrit == True: rho = cosmo.critical_density(redshift) else: rho = cosmo.Om(redshift)*cosmo.critical_density(redshift) # Linear halo mass (requires logMhalo in numpy array for calculations. Mhalo = (10.**np.array(logMhalo))*u.M_sun # Calculate the virial radius. Rvir3 = (3./(4.*np.pi))*(Mhalo/(delta*rho.to('Msun/kpc3'))) Rvir = (Rvir3)**(1./3.) return Rvir
def mstar_mhalo(z, mhalo): ## Moster+09, eqns 16,17 in PS11 mhalo0 = np.power(10, 11.88 + 0.018 * (1 + z)) mMz = 0.0282 * np.power(1 + z, -0.72) gammaz = 0.556 * np.power(1 + z, -0.26) betaz = 0.17 * z + 1.06 denom = np.power(mhalo / mhalo0, -1.0 * betaz) + np.power( mhalo / mhalo0, gammaz) mstar = mhalo * 2 * mMz / denom ## vvir, eqn 19 PS11 d = cosmo.Om(z) - 1 Delta = 18 * pi * pi + 82 * d - 39 * d * d factor = np.power( (cosmo.Om0 / 0.25) * (1 / cosmo.Om(z)) * (Delta / (18 * pi * pi)), 1 / 6.) vvir = 112.6 * np.power(mhalo / 1e12, 1 / 3.) * factor * np.sqrt(1 + z) # +0.05 for Chabrier return (np.log10(mstar) + 0.05), vvir
def test_delta_vir(self): """ Compute the calculated value of `~halotools.empirical_models.profile_helpers.delta_vir` at high-redshift where :math:`\\Omega_{\\rm m} = 1` should be a good approximation, and compare it to the analytical top-hat collapse result in this regime. """ bn98_result = delta_vir(WMAP9, 10.0) assert np.allclose(bn98_result, 18. * np.pi**2, rtol=0.01) # Choose a high-redshift where Om = 1 is a good approximation z = 10 rho_crit = WMAP9.critical_density(z) rho_crit = rho_crit.to(u.Msun / u.Mpc**3).value / WMAP9.h**2 rho_m = WMAP9.Om(z) * rho_crit wmap9_delta_vir_z10 = density_threshold(WMAP9, z, 'vir') / rho_m assert np.allclose(wmap9_delta_vir_z10, bn98_result, rtol=0.01)
def test_density_threshold(self): """ Verify that the `~halotools.empirical_models.profile_helpers.density_threshold` method returns the correct multiple of the appropriate density contrast over a range of redshifts and cosmologies. """ zlist = [0, 1, 5, 10] for z in zlist: for cosmo in (WMAP9, Planck13): rho_crit = WMAP9.critical_density(z) rho_crit = rho_crit.to(u.Msun / u.Mpc**3).value / WMAP9.h**2 rho_m = WMAP9.Om(z) * rho_crit wmap9_200c = density_threshold(WMAP9, z, '200c') / rho_crit assert np.allclose(wmap9_200c, 200.0, rtol=0.01) wmap9_2500c = density_threshold(WMAP9, z, '2500c') / rho_crit assert np.allclose(wmap9_2500c, 2500.0, rtol=0.01) wmap9_200m = density_threshold(WMAP9, z, '200m') / rho_m assert np.allclose(wmap9_200m, 200.0, rtol=0.01)
import numpy.random as rm import scipy.stats as stats from multiprocessing import Pool, Process, freeze_support import multiprocessing import argparse G = ct.G c = ct.c Msun = 1.989e30 pi = ct.pi noisecurvepts = 900 Hubble_Parameter = WMAP9.H(0.0).value #km/sec/Mpc h = Hubble_Parameter / 100.0 Omega_M = WMAP9.Om(0.0) Omega_vac = 1.0 - Omega_M #this is to cut out scale factors that occur before the first real mergers????? def scaleadjustfunc(scale_factor): change = (scale_factor <= 1.0 / 138.0) keep = (scale_factor > 1.0 / 138.0) return scale_factor * keep + (1.0 / 138.0) * change def Least_squared_binned_fit(counts): atest = np.linspace(0.001, 20.0, 10000) chisquared = np.zeros(len(atest)) for i in np.arange(len(counts[0])): if counts[0][i] != 0: