def RhoNorm(self, Mvir): ''' Return the normaliztion for mass function ''' lnmarr = np.linspace(np.log(Mvir * 0.99), np.log(Mvir * 1.01), 10) marr = np.exp(lnmarr).astype(np.float64) cosmo0 = CosmologyFunctions(0, config_file, cosmo_dict) #Byt giving m * h to sigm_m gives the sigma_m at z=0 sigma_m0 = np.array([cosmo0.sigma_m(m * cosmo0._h) for m in marr]) rho_norm = cosmo0.rho_bar() lnMassSigmaSpl = InterpolatedUnivariateSpline(lnmarr, sigma_m0) return rho_norm, lnMassSigmaSpl
N = int(M / 0.01) if N == 0: return 2. * arnaud_profile_2d(x, 0, Rs, M500, R500, zi, rho_crit, hz, omega_b0, omega_m0, cosmo_h) else: xx = np.linspace(0, M, N) f = 0.0 for x1 in xx: f += arnaud_profile_2d(x, x1, Rs, M500, R500, zi, rho_crit, hz, omega_b0, omega_m0, cosmo_h) #print xx f *= (2 * (xx[1] - xx[0])) return f if __name__=='__main__': from scipy.interpolate import interp1d z = 1. #0.0231 cosmo = CosmologyFunctions(z, 'wlsz.ini', 'battaglia') omega_b0 = cosmo._omega_b0 omega_m0 = cosmo._omega_m0 cosmo_h = cosmo._h BryanDelta = cosmo.BryanDelta() rho_critical = cosmo.rho_crit() * cosmo._h * cosmo._h rarr = np.logspace(-3, 3, 100) Mvir = 1.e15 #/ cosmo_h Mvir, Rvir, M200, R200, rho_s, Rs = MvirToMRfrac(Mvir, z, BryanDelta, rho_critical, cosmo_h) print('%.2e %.2f %.2e %.2f %.2e %.2f'%(Mvir, Rvir, M200, R200, rho_s, Rs)) M200 = 8.915e14 R200 = 1.392 Rs = 0.53
def massfunction(self): ''' p21 and Eqns. 56-59 of CS02 m^2 n(m,z) * dm * nu = m * bar(rho) * nu f(nu) * dnu n(m,z) = bar(rho) * nu f(nu) * (dlnnu / dlnm) / m^2 n(z) = bar(rho) * nu f(nu) * (dlnnu / dlnm) / m Mvir -solar unit nu, nuf - unitless rho_norm - is the rho_crit * Omega_m * h^2 in the unit of solar Mpc^(-3) at redshift of z mass_function - Mpc^(-3) ''' cosmo = CosmologyFunctions(self.redshift, config_file, cosmo_dict) mass_array = np.logspace(np.log10(self.Mvir * 0.9999), np.log10(self.Mvir * 1.0001), 2) ln_mass_array = np.log(mass_array) ln_sigma_m_array = np.log( np.array([self.lnMassSigmaSpl(np.log(m)) for m in mass_array])) #spl = UnivariateSpline(ln_mass_array, ln_nu_array, k=3) #print(spl.derivatives(np.log(Mvir))[1] #Derivatives of dln_nu/dln_mass at ln_mass ln_sigma_m_ln_mass_derivative = abs( (ln_sigma_m_array[1] - ln_sigma_m_array[0]) / (ln_mass_array[1] - ln_mass_array[0])) #1 for first derivate #print('ln_sigma_m_ln_mass_derivative ', Mvir, ln_sigma_m_ln_mass_derivative if self.mf == 'ST99': #This is (delta_c/sigma(m))^2. Here delta_c is slightly dependence on #Omega_m across redshift. cosmo._growth is the growth fucntion #This means delta_c increases as a function of redshift #lnMassSigmaSpl returns the sigma(m) at z=0 when gives the log(Mvir) nu = cosmo.delta_c() * cosmo.delta_c( ) / cosmo._growth / cosmo._growth / self.lnMassSigmaSpl( np.log(self.Mvir)) / self.lnMassSigmaSpl(np.log(self.Mvir)) nu_d = 0.707 * nu nuf_1 = (1. + 1. / nu_d**0.3) nuf_2 = (2. * nu_d)**0.5 nuf_3 = np.exp(-nu_d / 2.) / np.sqrt(np.pi) nuf = 0.322 * nuf_1 * nuf_2 * nuf_3 if self.mf == 'CS02': #This is from CS02 paper not from ST99 paper. The halo mass function implimented in CHOMP is from ST99 paper p = 0.3 A = 0.3222 q = 0.75 nuf_1 = A * (1. + (q * self.nu)**-0.3) nuf_2 = (q * self.nu / (2. * np.pi))**0.5 nuf_3 = np.exp(-q * self.nu / 2.) #nuf = nu*f(nu) nuf = nuf_1 * nuf_2 * nuf_3 if self.mf == 'PS74': nuf = np.sqrt(1. / 2. / np.pi / self.nu) * np.exp(-self.nu / 2.) #print(Mvir, rho_norm * cosmo._h * cosmo._h, cosmo.delta_c()/cosmo._growth, lnMassSigmaSpl(np.log(Mvir)),ln_sigma_m_ln_mass_derivative mass_function = nuf * self.rho_norm * cosmo._h * cosmo._h * ln_sigma_m_ln_mass_derivative / self.Mvir if self.bias == 0: return mass_function elif self.bias == 1: return self.halo_bias_st(nu) elif self.bias == 2: return mass_function * self.halo_bias_st(nu) else: return
def bias_mass_func_bocquet(redshift, config_file, cosmo_dict, lM200, uM200, mspace, bias=True, Delta=200, mtune=False, marr=None): ''' Wrote on Feb 20, 2017 Mass function of mass determined from critical density of the Universe redshift : Redshift of mass function lM200 : Lower limit of M200c, i.e. critical M200 uM200 : Upper limit of M200c mspace : mass space bias : if weighted by ST bias (Doesn't work now) M200 -solar unit/h Both the output have no little h mass function in dn/dlnM200 in 1/Mpc^3 marr solar unit/h ''' cosmo0 = CosmologyFunctions(0, config_file, cosmo_dict) cosmo_h = cosmo0._h g0 = 3.54e-2 + cosmo0._omega_m0**0.09 g1 = 4.56e-2 + 2.68e-2 / cosmo0._omega_m0 g2 = 0.721 + 3.50e-2 / cosmo0._omega_m0 g3 = 0.628 + 0.164 / cosmo0._omega_m0 d0 = -1.67e-2 + 2.18e-2 * cosmo0._omega_m0 d1 = 6.52e-3 - 6.86e-3 * cosmo0._omega_m0 dd = d0 + d1 * redshift gg = g0 + g1 * np.exp(-1. * ((g2 - redshift) / g3)**2.) if mtune: lnmarr = np.linspace(np.log(lM200), np.log(1e13), 30) marr13 = np.exp(lnmarr).astype(np.float64) marr14 = np.linspace(2e13, 1e14, 10) marr15 = np.linspace(1.1e14, 1e15, 30) #marr16 = np.linspace(1.2e15, 1e16, 30) marr16 = np.linspace(1.1e15, 1e16, 30) #marr17 = np.linspace(2**16, 10**17, 10) marr = np.hstack([marr13, marr14, marr15, marr16]) lnmarr = np.log(marr) elif marr is not None: marr = marr / cosmo_h lnmarr = np.log(marr) else: dlnm = np.float64(np.log(uM200 / lM200) / mspace) lnmarr = np.linspace(np.log(lM200), np.log(uM200), mspace) marr = np.exp(lnmarr).astype(np.float64) #print('dlnm ', dlnm #No little h #Mass is in the unit of Solar/h and get the sigma without little h sigma_m0 = np.array([cosmo0.sigma_m(m * cosmo_h) for m in marr]) rho_norm0 = cosmo0.rho_bar() #print(marr, sigma_m0 cosmo = CosmologyFunctions(redshift, config_file, cosmo_dict) lnMassSigmaSpl = InterpolatedUnivariateSpline(lnmarr, sigma_m0 * cosmo._growth, k=3) if Delta == 200: A = 0.222 * (1. + cosmo.redshift())**0.269 a = 1.71 * (1. + cosmo.redshift())**0.321 b = 2.24 * (1. + cosmo.redshift())**-0.621 c = 1.46 * (1. + cosmo.redshift())**-0.153 if Delta == 500: raise Exception('Not implemeted') A = 0.241 * (1. + cosmo.redshift())**0.370 a = 2.18 * (1. + cosmo.redshift())**0.251 b = 2.35 * (1. + cosmo.redshift())**-0.698 c = 2.02 * (1. + cosmo.redshift())**-0.310 mf, sarr, fsarr = [], [], [] for M200 in marr: M1dM = gg + dd * np.log(M200) mlow = M200 * 0.99 mhigh = M200 * 1.01 slow = lnMassSigmaSpl(np.log(mlow)) shigh = lnMassSigmaSpl(np.log(mhigh)) ds_dm = (shigh - slow) / (mhigh - mlow) sigma = lnMassSigmaSpl(np.log(M200)) #print('%.2e %.2f %.2e'%(M200, sigma, ds_dm) fsigma = A * np.exp(-c / sigma**2.) * ((sigma / b)**-a + 1.) #print('%.2e %.2e %.2f %.2f %.2f %.2f %.2f'%(M200, fsigma, A, a, b, c, sigma) mf.append(-1 * M1dM * fsigma * rho_norm0 * cosmo._h * cosmo._h * ds_dm / sigma) ##mf.append(-1 * fsigma * rho_norm0 * ds_dm / sigma) #if need h^2/Mpc^3 sarr.append(sigma) fsarr.append(fsigma) mf = np.array(mf) sarr = np.array(sarr) fsarr = np.array(fsarr) if 0: return marr, mass_function * halo_bias_st( delta_c_sigma_m2), sigma, fsigma else: return marr, mf, sarr, fsarr
def bias_mass_func_tinker(redshift, config_file, cosmo_dict, lM, uM, mspace, bias=True, Delta=200, mtune=False, marr=None, reduced=False): ''' Wrote on Jan 26, 2017 Mass function of mass determined from mean density of the Universe (i.e. omega_m(z) critical density) redshift : Redshift of mass function lM : Lower limit of marr uM : Upper limit of marr mspace : mass space bias : if weighted by ST bias (Doesn't work now) marr : Solar mass/h M200 -solar unit/h Both the output have no little h mass function in dn/dlnM200 in 1/Mpc^3 marr solar unit / h ''' DeltaTinker = np.log( (200., 300., 400., 600., 800., 1200., 1600., 2400., 3200.)) # A ATinker = (1.858659e-01, 1.995973e-01, 2.115659e-01, 2.184113e-01, 2.480968e-01, 2.546053e-01, 2.600000e-01, 2.600000e-01, 2.600000e-01) Aspl = interp1d(DeltaTinker, ATinker, kind='cubic') #fill_value='extrapolate') # a aTinker = (1.466904e+00, 1.521782e+00, 1.559186e+00, 1.614585e+00, 1.869936e+00, 2.128056e+00, 2.301275e+00, 2.529241e+00, 2.661983e+00) aspl = interp1d(DeltaTinker, aTinker, kind='cubic') #fill_value='extrapolate') # b bTinker = (2.571104e+00, 2.254217e+00, 2.048674e+00, 1.869559e+00, 1.588649e+00, 1.507134e+00, 1.464374e+00, 1.436827e+00, 1.405210e+00) bspl = interp1d(DeltaTinker, bTinker, kind='cubic') #fill_value='extrapolate') # c cTinker = (1.193958e+00, 1.270316e+00, 1.335191e+00, 1.446266e+00, 1.581345e+00, 1.795050e+00, 1.965613e+00, 2.237466e+00, 2.439729e+00) cspl = interp1d(DeltaTinker, cTinker, kind='cubic') #fill_value='extrapolate') cosmo0 = CosmologyFunctions(0, config_file, cosmo_dict) cosmo_h = cosmo0._h if mtune: lnmarr = np.linspace(np.log(lM), np.log(1e13), 30) marr13 = np.exp(lnmarr).astype(np.float64) marr14 = np.linspace(2e13, 1e14, 10) marr15 = np.linspace(1.1e14, 1e15, 30) #marr16 = np.linspace(1.2e15, 1e16, 30) marr16 = np.linspace(1.1e15, 1e16, 30) #marr17 = np.linspace(2**16, 10**17, 10) marr = np.hstack([marr13, marr14, marr15, marr16]) lnmarr = np.log(marr) elif marr is not None: lnmarr = np.log(marr) else: dlnm = np.float64(np.log(uM / lM) / mspace) lnmarr = np.linspace(np.log(lM), np.log(uM), mspace) marr = np.exp(lnmarr).astype(np.float64) #print('dlnm ', dlnm #Should give mass in Msun/h to sigma_m() in CosmologyFunctions.py. #See the note in that function sigma_m0 = np.array([cosmo0.sigma_m(m) for m in marr]) rho_norm0 = cosmo0.rho_bar() #print(marr, sigma_m0 if redshift >= 3: cosmo = CosmologyFunctions(3., config_file, cosmo_dict) else: cosmo = CosmologyFunctions(redshift, config_file, cosmo_dict) lnMassSigmaSpl = InterpolatedUnivariateSpline(lnmarr, sigma_m0 * cosmo._growth, k=3) if 0: #Delta == 200: A = 0.186 * (1. + cosmo.redshift())**-0.14 a = 1.47 * (1. + cosmo.redshift())**-0.06 alpha = 10**(-(0.75 / np.log10(200. / 75.))**1.2) b = 2.57 * (1. + cosmo.redshift())**-alpha c = 1.19 if 0: #Delta == 400: A = 0.212 * (1. + cosmo.redshift())**-0.14 a = 1.56 * (1. + cosmo.redshift())**-0.06 alpha = 10**(-(0.75 / np.log10(400. / 75.))**1.2) b = 2.05 * (1. + cosmo.redshift())**-alpha c = 1.34 if Delta > 0: A = Aspl(np.log(Delta)) a = aspl(np.log(Delta)) b = bspl(np.log(Delta)) c = cspl(np.log(Delta)) else: A = 0.1 * np.log10(Delta) - 0.05 a = 1.43 + (np.log10(Delta) - 2.3)**1.5 b = 1.0 + (np.log10(Delta) - 1.6)**-1.5 c = 1.2 + (np.log10(Delta) - 2.35)**1.6 alpha = 10**(-(0.75 / np.log10(Delta / 75.))**1.2) mf, sarr, fsarr = [], [], [] for tm in marr: mlow = tm * 0.99 mhigh = tm * 1.01 slow = lnMassSigmaSpl(np.log(mlow)) shigh = lnMassSigmaSpl(np.log(mhigh)) ds_dm = (shigh - slow) / (mhigh - mlow) #this will have one h sigma = lnMassSigmaSpl(np.log(tm)) #print('%.2e %.2f %.2e'%(tm, sigma, ds_dm) fsigma = A * np.exp(-c / sigma**2.) * ((sigma / b)**-a + 1.) #print('%.2e %.2e %.2f %.2f %.2f %.2f %.2f'%(tm, fsigma, A, a, b, c, sigma) if reduced: mf.append(-1 * fsigma * rho_norm0 * ds_dm / sigma) #if need h^2/Mpc^3 else: mf.append( -1 * fsigma * rho_norm0 * cosmo._h**3 * ds_dm / sigma ) #It will have h^3/Mpc^3 if the dn/dlnM has M in Msol unit sarr.append(sigma) fsarr.append(fsigma) mf = np.array(mf) sarr = np.array(sarr) fsarr = np.array(fsarr) if 0: return marr, mass_function * halo_bias_st( delta_c_sigma_m2), sigma, fsigma else: return marr, mf, sarr, fsarr
def bias_mass_func_st(redshift, config_file, cosmo_dict, lMvir, uMvir, mspace, bias=True, marr=None): ''' Sheth & Torman 1999 & Eq. 56-50 of CS02 in p21 Output: MF = dn/dlnMvir (1/Mpc^3) mass = Solar mass ''' cosmo0 = CosmologyFunctions(0, config_file, cosmo_dict) cosmo_h = cosmo0._h if marr is not None: lnmarr = np.log(marr) else: dlnm = np.float64(np.log(uMvir / lMvir) / mspace) lnmarr = np.linspace(np.log(lMvir), np.log(uMvir), mspace) marr = np.exp(lnmarr).astype(np.float64) #print('dlnm ', dlnm #No little h #Need to give mass * h and get the sigma without little h sigma_m0 = np.array([cosmo0.sigma_m(m * cosmo0._h) for m in marr]) rho_norm0 = cosmo0.rho_bar() #print(marr, sigma_m0 lnMassSigma0Spl = InterpolatedUnivariateSpline(lnmarr, sigma_m0, k=3) cosmo = CosmologyFunctions(redshift, config_file, cosmo_dict) mf, nuarr, fnuarr = [], [], [] for m in marr: mlow = m * 0.99 mhigh = m * 1.01 mass_array = np.logspace(np.log10(mlow), np.log10(mhigh), 2) ln_mass_array = np.log(mass_array) ln_sigma_m_array = np.log( np.array([lnMassSigma0Spl(np.log(m1)) for m1 in mass_array])) #Derivatives of dln_nu/dln_mass at ln_mass lnSigma_m_lnM_derivative = abs( (ln_sigma_m_array[1] - ln_sigma_m_array[0]) / (ln_mass_array[1] - ln_mass_array[0])) #1 for first derivate nu = cosmo.nu_m(m) #This is (delta_c/sigma(m))^2. Here delta_c is slightly dependence on #Omega_m across redshift. cosmo._growth is the growth fucntion #This means delta_c increases as a function of redshift #lnMassSigmaSpl returns the sigma(m) at z=0 when gives the log(Mvir) delta_c_sigma_m2 = cosmo.delta_c( ) * cosmo.delta_c() / cosmo._growth / cosmo._growth / lnMassSigma0Spl( np.log(m)) / lnMassSigma0Spl(np.log(m)) nu_d = 0.707 * delta_c_sigma_m2 nuf_1 = (1. + 1. / nu_d**0.3) nuf_2 = (2. * nu_d)**0.5 nuf_3 = np.exp(-nu_d / 2.) / np.sqrt(np.pi) nuf = 0.322 * nuf_1 * nuf_2 * nuf_3 if bias: mf.append( halo_bias_st(delta_c_sigma_m2) * nuf * rho_norm0 * cosmo._h * cosmo._h * lnSigma_m_lnM_derivative / m) else: mf.append(nuf * rho_norm0 * cosmo._h * cosmo._h * lnSigma_m_lnM_derivative / m) mf = np.array(mf) return marr, mf
def cl_WL_tSZ(config_file, cosmology, fwhm_k, fwhm_y, kk, yy, ky, zsfile, P01, P02, P03, xc1, xc2, xc3, beta1, beta2, beta3, omega_m0, sigma_8, odir, ofile): ''' Compute WL X tSZ halomodel for a given source redshift distribution ''' if ky: sigma_k = fwhm_k * np.pi / 2.355 / 60. /180. #angle in radian sigma_y = fwhm_y * np.pi / 2.355 / 60. /180. #angle in radian sigmasq = sigma_k * sigma_y elif kk: sigma_k = fwhm_k * np.pi / 2.355 / 60. /180. #angle in radian sigmasq = sigma_k * sigma_k elif yy: sigma_y = fwhm_y * np.pi / 2.355 / 60. /180. #angle in radian sigmasq = sigma_y * sigma_y else: raise ValueError('Either kk, yy or ky should be True') config = ConfigParser() config.read(config_file) if omega_m0 is None: omega_m0 = config.getfloat(cosmology, 'omega_m0') if sigma_8 is None: sigma_8 = config.getfloat(cosmology, 'sigma_8') omega_l0 = 1. - omega_m0 omega_b0 = config.getfloat(cosmology, 'omega_b0') h = config.getfloat(cosmology, 'h') n_scalar = config.getfloat(cosmology, 'n_scalar') cosmo_dict = {'omega_m0':omega_m0, 'omega_l0':omega_l0, 'omega_b0':omega_b0, 'h':h, 'sigma_8':sigma_8, 'n_scalar':n_scalar} cosmo0 = CosmologyFunctions(0, config_file, cosmo_dict) cosmo_h = cosmo0._h save_clfile = config.getboolean('halomodel', 'save_clfile') print_cl = config.getboolean('halomodel', 'print_cl') light_speed = config.getfloat('halomodel', 'light_speed') #km/s mpctocm = config.getfloat('halomodel', 'mpctocm') kB_kev_K = config.getfloat('halomodel', 'kB_kev_K') sigma_t_cm = config.getfloat('halomodel', 'sigma_t_cm') #cm^2 rest_electron_kev = config.getfloat('halomodel', 'rest_electron_kev') #keV constk = 3. * omega_m0 * (cosmo_h * 100. / light_speed)**2. / 2. #Mpc^-2 consty = mpctocm * sigma_t_cm / rest_electron_kev zsarr, Ns = np.genfromtxt(zsfile, unpack=True) if np.isscalar(zsarr): zsarr = np.array([zsarr]) Ns = np.array([Ns]) else: zint = np.sum(Ns) * (zsarr[1] - zsarr[0]) Ns /= zint if P01 is None: P01 = config.getfloat('halomodel', 'P01') if P02 is None: P02 = config.getfloat('halomodel', 'P02') if P03 is None: P03 = config.getfloat('halomodel', 'P03') if xc1 is None: xc1 = config.getfloat('halomodel', 'xc1') if xc2 is None: xc2 = config.getfloat('halomodel', 'xc2') if xc3 is None: xc3 = config.getfloat('halomodel', 'xc3') if beta1 is None: beta1 = config.getfloat('halomodel', 'beta1') if beta2 is None: beta2 = config.getfloat('halomodel', 'beta2') if beta3 is None: beta3 = config.getfloat('halomodel', 'beta3') kRmax = config.getfloat('halomodel', 'kRmax') kRspace = config.getint('halomodel', 'kRspace') yRmax = config.getfloat('halomodel', 'yRmax') yRspace = config.getint('halomodel', 'yRspace') kmin = config.getfloat('halomodel', 'kmin') #1/Mpc kmax = config.getfloat('halomodel', 'kmax') kspace = config.getint('halomodel', 'kspace') ellmin = config.getint('halomodel', 'ellmin') ellmax = config.getfloat('halomodel', 'ellmax') ellspace = config.getint('halomodel', 'ellspace') mmin = config.getfloat('halomodel', 'mmin') mmax = config.getfloat('halomodel', 'mmax') mspace = config.getfloat('halomodel', 'mspace') zmin = config.getfloat('halomodel', 'zmin') zmax = config.getfloat('halomodel', 'zmax') zspace = config.getfloat('halomodel', 'zspace') dlnk = np.log(kmax/kmin) / kspace lnkarr = np.linspace(np.log(kmin), np.log(kmax), kspace) karr = np.exp(lnkarr).astype(np.float64) #No little h #Input Mpc/h to power spectra and get Mpc^3/h^3 pk_arr = np.array([cosmo0.linear_power(k/cosmo0._h) for k in karr]).astype(np.float64) / cosmo0._h / cosmo0._h / cosmo0._h #np.savetxt('pk_vinu.dat', np.transpose((karr/cosmo0._h, pk_arr*cosmo0._h**3))) #sys.exit() #kc, pkc = np.genfromtxt('matterpower.dat', unpack=True) #pkspl = InterpolatedUnivariateSpline(kc, pkc, k=2) #pkh_arr = pkspl(karr/cosmo0._h) #pk_arr = pkh_arr / cosmo0._h / cosmo0._h / cosmo0._h pkspl = InterpolatedUnivariateSpline(karr, pk_arr, k=2) #pl.loglog(karr, pk_arr) #pl.show() dlnm = np.log(mmax/mmin) / mspace lnmarr = np.linspace(np.log(mmin), np.log(mmax), mspace) marr = np.exp(lnmarr).astype(np.float64) lnzarr = np.linspace(np.log(1.+zmin), np.log(1.+zmax), zspace) zarr = np.exp(lnzarr) - 1.0 dlnz = np.log((1.+zmax)/(1.+zmin)) / zspace print('dlnk, dlnm dlnz', dlnk, dlnm, dlnz) if doPrintCl: print('dlnk, dlnm dlnz', dlnk, dlnm, dlnz) #No little h #Need to give mass * h and get the sigma without little h #The following lines are used only used for ST MF and ST bias sigma_m0 = np.array([cosmo0.sigma_m(m * cosmo0._h) for m in marr]) rho_norm0 = cosmo0.rho_bar() lnMassSigmaSpl = InterpolatedUnivariateSpline(lnmarr, sigma_m0, k=3) hzarr, BDarr, rhobarr, chiarr, dVdzdOm, rho_crit_arr = [], [], [], [], [], [] bias, bias_t, Darr = [], [], [] marr2, mf, dlnmdlnm, Deltaarr = [], [], [], [] if config.get('halomodel', 'MF') == 'Tinker' and config.get('halomodel', 'MassToIntegrate') == 'm200m': #Mass using critical density (ie. m200c) tm200c = np.logspace(np.log10(1e8), np.log10(1e17), 50) #m200m mass using mean mass density tmarr = np.exp(lnmarr).astype(np.float64) #tf = np.genfromtxt('../data/z_m_relation.dat') #tz = tf[:,0] #tmv = tf[:,1] #tm200c = tf[:,2] #tm200m = tf[:,3] for i, zi in enumerate(zarr): cosmo = CosmologyFunctions(zi, config_file, cosmo_dict) rcrit = cosmo.rho_crit() * cosmo._h * cosmo._h rbar = cosmo.rho_bar() * cosmo._h * cosmo._h bn = cosmo.BryanDelta() BDarr.append(bn) #OK rho_crit_arr.append(rcrit) #OK rhobarr.append(rbar) chiarr.append(cosmo.comoving_distance() / cosmo._h) hzarr.append(cosmo.E0(zi)) DD = bn/cosmo.omega_m() DD200 = 200./cosmo.omega_m() #Number of Msun objects/Mpc^3 (i.e. unit is 1/Mpc^3) if config.get('halomodel', 'MF') == 'Tinker': if config.get('halomodel', 'MassToIntegrate') == 'virial': if DD > 200: mFrac = marr * cosmo_h print(1) mFrac = marr * h0 #print bn, cosmo.omega_m(), bn/cosmo.omega_m() mf.append(bias_mass_func_tinker(zi, config_file, cosmo_dict, mFrac.min(), mFrac.max(), mspace, bias=False, Delta=DD, marr=mFrac, reduced=False)[1]) marr2.append(marr) dlnmdlnm.append(np.ones_like(marr)) else: mFrac = np.array([HuKravtsov(zi, mv, rcrit, bn, config.getfloat('halomodel', 'MassDef') * cosmo.omega_m(), cosmo_h, 1)[2] for mv in marr]) * cosmo_h mf.append(bias_mass_func_tinker(zi, config_file, cosmo_dict, mFrac.min(), mFrac.max(), mspace, bias=False, Delta=config.getfloat('halomodel', 'MassDef'), marr=mFrac, reduced=False)[1]) marr2.append(marr) dlnmdlnm.append([dlnMdensitydlnMcritOR200(config.getfloat('halomodel', 'MassDef') * cosmo.omega_m(), bn, mFm/cosmo_h, mv, zi, cosmo_h, 1) for mv,mFm in zip(marr, mFrac)]) #dlnmFrac/dlnMv. In the bias_mass_func_tinker() I have computed dn/dlnM where M is in the unit of Msol. I have therefore include h in that mass function. Therefore, I just need to multiply dlnmFrac/dlnMv only print(2) mFrac = np.array([HuKravtsov(zi, mv, rcrit, bn, float(config['massfunc']['MassDef'])/cosmo.omega_m(), h0, 1)[2] for mv in marr]) * h0 mf.append(bias_mass_func_tinker(zi, mFrac.min(), mFrac.max(), mspace, bias=False, Delta=float(config['massfunc']['MassDef']), marr=mFrac, reduced=False)[1]) marr2.append(marr) dlnmdlnm.append([dlnMdensitydlnMcritOR200(float(config['massfunc']['MassDef']) / cosmo.omega_m(), bn, mFm/h0, mv, zi, h0, 1) for mv,mFm in zip(marr, mFrac)]) #dlnmFrac/dlnMv. In the bias_mass_func_tinker() I have computed dn/dlnM where M is in the unit of Msol. I have therefore include h in that mass function. Therefore, I just need to multiply dlnmFrac/dlnMv only #print dlnmdlnm #print a input_mvir = 1 elif config.get('halomodel', 'MassToIntegrate') == 'm200c': #XXX #m200m = np.array([HuKravtsov(zi, mv, rcrit, 200, 200*cosmo.omega_m(), cosmo_h, 0)[2] for mv in marr]) #* cosmo_h #print m200m #XXX if DD200 > 200: mFrac = marr * cosmo_h #print 200, cosmo.omega_m(), 200/cosmo.omega_m() mf.append(bias_mass_func_tinker(zi, config_file, cosmo_dict, mFrac.min(), mFrac.max(), mspace, bias=False, Delta=DD200, marr=mFrac, reduced=False)[1]) marr2.append(marr) dlnmdlnm.append(np.ones_like(marr)) else: mFrac = np.array([HuKravtsov(zi, m2c, rcrit, 200, config.getfloat('halomodel', 'MassDef') * cosmo.omega_m(), cosmo_h, 0)[2] for m2c in marr]) * cosmo_h mf.append(bias_mass_func_tinker(zi, config_file, cosmo_dict, mFrac.min(), mFrac.max(), mspace, bias=False, Delta=config.getfloat('halomodel', 'MassDef'), marr=mFrac)[1]) marr2.append(marr) for m2,mFm in zip(marr, mFrac): dlnmdlnm.append(dlnMdensitydlnMcritOR200(config.getfloat('halomodel', 'MassDef') * cosmo.omega_m(), 200., mFm/cosmo_h, m2, zi, cosmo_h, 0)) #dlnM200m/dlnMv. In the bias_mass_func_tinker() I have computed dn/dlnM where M is in the unit of Msol. I have therefore include h in that mass function. Therefore, I just need to multiply dlnM200m/dlnMv only mFrac = np.array([HuKravtsov(zi, m2c, rcrit, 200, float(config['massfunc']['MassDef'])/cosmo.omega_m(), h0, 0)[2] for m2c in marr]) * h0 mf.append(bias_mass_func_tinker(zi, mFrac.min(), mFrac.max(), mspace, bias=False, Delta=float(config['massfunc']['MassDef']), marr=mFrac)[1]) marr2.append(marr) for m2,mFm in zip(marr, mFrac): dlnmdlnm.append(dlnMdensitydlnMcritOR200(float(config['massfunc']['MassDef']) / cosmo.omega_m(), 200., mFm/h0, m2, zi, h0, 0)) #dlnM200m/dlnMv. In the bias_mass_func_tinker() I have computed dn/dlnM where M is in the unit of Msol. I have therefore include h in that mass function. Therefore, I just need to multiply dlnM200m/dlnMv only input_mvir = 0 elif config.get('halomodel', 'MassToIntegrate') == 'm200m': #raise ValueError('Use MassToIntegrate=virial/m200c. m200m is not working') #Temporary mass array of m200m from m200c tm200m = np.array([HuKravtsov(zi, tt, rcrit, 200, 200.*cosmo.omega_m(), cosmo._h, 0)[2] for tt in tm200c]) #m200m vs m200c spline tmspl = InterpolatedUnivariateSpline(tm200m, tm200c) #Now m200c from m200m, i.e. tmarr which is the integrating #variable m200c = tmspl(tmarr) #m200m Msol/h m200m = tmarr * cosmo_h marr2.append(m200c) mf.append(bias_mass_func_tinker(zi, config_file, cosmo_dict, m200m.min(), m200m.max(), mspace, bias=False, Delta=200, marr=m200m)[1]) input_mvir = 0 elif config.get('halomodel', 'MF') == 'Bocquet': if config.get('halomodel', 'MassToIntegrate') == 'virial': m200 = np.array([HuKravtsov(zi, mv, rcrit, bn, 200, cosmo_h, 1)[2] for mv in marr]) mf.append(bias_mass_func_bocquet(zi, config_file, cosmo_dict, m200.min(), m200.max(), mspace, bias=False, marr=m200)[1]) marr2.append(marr) for mv,m2 in zip(marr, m200): dlnmdlnm.append(dlnMdensitydlnMcritOR200(200., bn, m2, mv, zi, cosmo_h, 1)) input_mvir = 1 elif config.get('halomodel', 'MassToIntegrate') == 'm200': tmf = bias_mass_func_bocquet(zi, config_file, cosmo_dict, marr.min(), marr.max(), mspace, bias=False, marr=marr)[1] mf.append(tmf) dlnmdlnm.append(np.ones(len(tmf))) input_mvir = 0 elif config.get('halomodel', 'MF') == 'ST': mf.append(bias_mass_func_st(zi, config_file, cosmo_dict, marr.min(), marr.max(), mspace, bias=False, marr=marr)[1]) marr2.append(marr) dlnmdlnm.append(np.ones_like(marr)) input_mvir = 1 #raise ValueError('MF should be Tinker or Bocquet') #Bias is calculated by assuming that the mass is virial. I need to change that #print DD #for m in marr: # print '%.2e T %.2f'%(m, halo_bias_tinker(DD, cosmo.delta_c() / cosmo._growth / lnMassSigmaSpl(np.log(m)))) # print '%.2e ST %.2f'%(m, halo_bias_st(cosmo.delta_c() * cosmo.delta_c() / cosmo._growth / cosmo._growth / lnMassSigmaSpl(np.log(m)) / lnMassSigmaSpl(np.log(m)))) #sys.exit() if config.get('halomodel', 'MF') == 'Tinker': if DD >= 200: bias.append(np.array([halo_bias_tinker(DD, cosmo.delta_c() / cosmo._growth / lnMassSigmaSpl(np.log(m))) for m in marr])) else: bias.append(np.array([halo_bias_tinker(config.getfloat('halomodel', 'MassDef') * cosmo.omega_m(), cosmo.delta_c() / cosmo._growth / lnMassSigmaSpl(np.log(m))) for m in mFrac/cosmo_h])) elif config.get('halomodel', 'MF') == 'ST' or config.get('halomodel', 'MF') == 'Bocquet': bias.append(np.array([halo_bias_st(cosmo.delta_c() * cosmo.delta_c() / cosmo._growth / cosmo._growth / lnMassSigmaSpl(np.log(m)) / lnMassSigmaSpl(np.log(m))) for m in marr])) dVdzdOm.append(cosmo.E(zi) / cosmo._h) #Mpc/h, It should have (km/s/Mpc)^-1 but in the cosmology code the speed of light is removed Darr.append(cosmo._growth) #pl.title('%.2f'%zi) #pl.scatter(np.array([halo_bias_st(cosmo.delta_c() * cosmo.delta_c() / cosmo._growth / cosmo._growth / lnMassSigmaSpl(np.log(m)) / lnMassSigmaSpl(np.log(m))) for m in marr]), np.array([halo_bias_tinker(200, cosmo.delta_c() / cosmo._growth / lnMassSigmaSpl(np.log(m))) for m in marr])) #pl.show() if config.get('halomodel', 'MF') =='Tinker' and config.get('halomodel', 'MassToIntegrate') == 'm200m': mf = np.array(mf).flatten() else: mf = np.array(mf).flatten() * np.array(dlnmdlnm).flatten() hzarr = np.array(hzarr) BDarr = np.array(BDarr) rhobarr = np.array(rhobarr) chiarr = np.array(chiarr) dVdzdOm = np.array(dVdzdOm) * chiarr * chiarr rho_crit_arr = np.array(rho_crit_arr) marr2 = np.array(marr2).flatten() zchispl = InterpolatedUnivariateSpline(zarr, chiarr, k=2) chisarr = zchispl(zsarr) bias = np.array(bias).flatten() bias_t = np.array(bias_t).flatten() Darr = np.array(Darr) #ellarr = np.linspace(1, 10001, 10) ellarr = np.logspace(np.log10(ellmin), np.log10(ellmax), ellspace) cl_arr, cl1h_arr, cl2h_arr = [], [], [] for ell in ellarr: pk = pkspl(ell/chiarr) if ky: cl1h, cl2h, cl = integrate_kyhalo(ell, lnzarr, chiarr, dVdzdOm, marr2, mf, BDarr, rhobarr, rho_crit_arr, bias, Darr, pk, zsarr, chisarr, Ns, dlnz, dlnm, omega_b0, omega_m0, cosmo_h, constk, consty, input_mvir, mspace, kRmax, kRspace, yRmax, yRspace, P01, P02, P03, xc1, xc2, xc3, beta1, beta2, beta3) if kk: cl1h, cl2h, cl = integrate_kkhalo(ell, lnzarr, chiarr, dVdzdOm, marr2, mf, BDarr, rhobarr, rho_crit_arr, bias, Darr, pk, zsarr, chisarr, Ns, dlnz, dlnm, omega_b0, omega_m0, cosmo_h, constk, consty, input_mvir, mspace, kRmax, kRspace) if yy: cl1h, cl2h, cl = integrate_yyhalo(ell, lnzarr, chiarr, dVdzdOm, marr2, mf, BDarr, rhobarr, rho_crit_arr, bias, Darr, pk, dlnz, dlnm, omega_b0, omega_m0, cosmo_h, constk, consty, input_mvir, mspace, yRmax, yRspace, P01, P02, P03, xc1, xc2, xc3, beta1, beta2, beta3) cl_arr.append(cl) cl1h_arr.append(cl1h) cl2h_arr.append(cl2h) if print_cl: print('l %.2 Cl_1h %.2e Cl_2h %.2e Cl %.2e'%(ell, cl1h, cl2h, cl)) if doPrintCl: print(ell, cl1h, cl2h, cl) convolve = np.exp(-1 * sigmasq * ellarr * ellarr)# i.e. the output is Cl by convolving by exp(-sigma^2 l^2) cl = np.array(cl_arr) * convolve cl1h = np.array(cl1h_arr) * convolve cl2h = np.array(cl2h_arr) * convolve if save_clfile: np.savetxt(os.path.join(odir, ofile), np.transpose((ellarr, cl1h, cl2h, cl)), fmt='%.2f %.3e %.3e %.3e', header='l Cl1h Cl2h Cl') return ellarr, cl1h, cl2h, cl
(1 + conc)) #Msun / Mpc^3 Rs = R / conc A = np.log(1. + conc) - 1. + 1. / (1. + conc) f = Delta * (1. / conc**3) * A p = a2 + a3 * np.log(f) + a4 * np.log(f)**2 x = (a1 * f**(2. * p) + 0.75**2.)**(-0.5) + 2. * f Mfrac = M * Delta * (1. / conc / x)**3 Rfrac = (3. * Mfrac / deltao / rho / 4. / np.pi)**(1. / 3.) return M, R, Mfrac, Rfrac, rho_s, Rs if __name__ == '__main__': z = 0.07 Mvir = 1e15 cosmo = CosmologyFunctions(z, 'wlsz.ini', 'battaglia') omega_b = cosmo._omega_b0 omega_m = cosmo._omega_m0 cosmo_h = cosmo._h BryanDelta = cosmo.BryanDelta() rho_critical = cosmo.rho_crit() * cosmo._h * cosmo._h rho_bar = cosmo.rho_bar() * cosmo._h * cosmo._h for D in np.arange(1, 100, 10): M, R, Mfrac, Rfrac, rho_s, Rs = HuKravtsov(z, Mvir, rho_critical, BryanDelta, D * cosmo.omega_m(), cosmo_h, True) print('%.2e %.2f %.2e %.2f %.2e %.2f' % (M, R, Mfrac, Rfrac, rho_s, Rs)) sys.exit() print('rho_critical = %.2e , rho_bar = %.2e' % (rho_critical, rho_bar))