def get_args(i): Ms = np.array([]) bs = np.array([]) tbs = np.array([]) pd = np.array([]) pde = np.array([]) bes = np.array([]) icovs = np.array([]) boxes = np.array([]) snaps = np.array([]) cosmo, h, Omega_m = get_cosmo(i) hmf = mf_obj(i) k = np.logspace(-5, 1, num=1000) #Mpc^-1 kh = k/h nus = [] #sigma^2 for j in range(0,10): #snap z = zs[j] M, Mlo, Mhigh, b, be = np.loadtxt("/Users/tmcclintock/Data/linear_bias_test/TestBox%03d-combined_Z%d_DS50_linearbias.txt"%(i,j)).T M = np.ascontiguousarray(M) Mlo = np.ascontiguousarray(Mlo) Mhigh = np.ascontiguousarray(Mhigh) inds = Mhigh > 1e99 Mhigh[inds] = 1e16 p = np.array([cosmo.pk_lin(ki, z) for ki in k])*h**3 nu = ph.nu_at_M(M, kh, p, Omega_m) #Replace this part with the average bias Mbins = np.array([Mlo, Mhigh]).T n_bins = hmf.n_in_bins(Mbins, z) #Denominator Marr = np.logspace(np.log10(M[0]*0.98), 16, 1000) lMarr = np.log(Marr) nuarr = ph.nu_at_M(Marr, kh, p, Omega_m) dndlm = hmf.dndlM(Marr, z) b_n = dndlm * ct.bias.bias_at_nu(nuarr) b_n_spl = IUS(lMarr, b_n) lMbins = np.log(Mbins) tb = np.zeros_like(nu) for ind in range(len(tb)): tbi = quad(b_n_spl, lMbins[ind,0], lMbins[ind,1]) tbi2 = b_n_spl.integral(lMbins[ind,0], lMbins[ind,1]) #print tbi[0]/n_bins[ind], tbi2/n_bins[ind] tb[ind] = tbi[0] / n_bins[ind] #print b #exit() #print tb #print ct.bias.bias_at_nu(nu) #instantaneous tinker bias #tb = ct.bias.bias_at_nu(nu) #instantaneous tinker bias tbs = np.concatenate((tbs, tb)) Ms=np.concatenate((Ms, M)) bs=np.concatenate((bs, b)) bes=np.concatenate((bes, be)) nus = np.concatenate((nus, nu)) pd = np.concatenate((pd, (b-tb)/tb)) pde = np.concatenate((pde, be/tb)) boxes = np.concatenate((boxes, np.ones_like(M)*i)) snaps = np.concatenate((snaps, np.ones_like(M)*j)) return nus, bs, bes, Ms, tbs, pd, pde, boxes, snaps
def test_s2_and_nu_functions(): #Test the mass calls s2 = peaks.sigma2_at_M(Mass, klin, plin, Omega_m) nu = peaks.nu_at_M(Mass, klin, plin, Omega_m) npt.assert_equal(1.686 / np.sqrt(s2), nu) s2 = peaks.sigma2_at_M(Ma, klin, plin, Omega_m) nu = peaks.nu_at_M(Ma, klin, plin, Omega_m) npt.assert_array_equal(1.686 / np.sqrt(s2), nu) #Now test the R calls R = 1.0 #Mpc/h; arbitrary s2 = peaks.sigma2_at_R(R, klin, plin) nu = peaks.nu_at_R(R, klin, plin) npt.assert_equal(1.686 / np.sqrt(s2), nu)
def test_mass_dependence(): masses = np.logspace(13, 15, num=100) arrout = bias.bias_at_M(masses, klin, plin, Omega_m) for i in range(len(masses)-1): assert arrout[i] < arrout[i+1] Rs = (masses/(4./3.*np.pi*Omega_m*rhomconst))**(1./3.) arrout = bias.bias_at_R(Rs, klin, plin) for i in range(len(masses)-1): assert arrout[i] < arrout[i+1] nus = peaks.nu_at_M(masses, klin, plin, Omega_m) arrout = bias.bias_at_nu(nus) for i in range(len(masses)-1): assert arrout[i] < arrout[i+1]
def calc_peak_height(cosmos, zs, k, p): Nc = len(cosmos) Nz = len(zs) nus = np.zeros((Nc, Nz, len(M))) for i in range(Nc): obh2, och2, w, ns, ln10As, H0, Neff, s8 = cosmos[i] h = H0 / 100. Om = (obh2 + och2) / h**2 kh = k / h #now h/Mpc for j in range(Nz): ph3 = p[i, j] * h**3 #now (Mpc/h)^3 nus[i, j] = ctph.nu_at_M(M, kh, ph3, Om) continue print("Finished peak height box %d" % i) continue return nus