Ejemplo n.º 1
0
def get_masses(nu, box=0):
    hmf = aemHMF.Aemulus_HMF()
    #nu has locations of the ticks in the x axis
    #Pick some cosmology, box=16
    Ombh2, Omch2, w, ns, ln10As, H0, Neff, sig8 = np.genfromtxt(
        AD.path_to_test_box_cosmologies())[int(box)]
    h = H0 / 100.
    Ob = Ombh2 / h**2
    Oc = Omch2 / h**2
    Om = Ob + Oc
    cosmo = {
        "om": Om,
        "ob": Ob,
        "ol": 1 - Om,
        "h": h,
        "s8": sig8,
        "ns": ns,
        "w0": w,
        "Neff": Neff,
        "wa": 0
    }
    hmf.set_cosmology(cosmo)
    Ms = np.logspace(11, 17, num=100)  #Msun/h
    a = 1.0
    nus = np.array([aemHMF.peak_height(Mi, a) for Mi in Ms])
    from scipy.interpolate import interp1d
    spl = interp1d(nus, Ms)
    return spl(nu)  #np.log10(spl(nu))
Ejemplo n.º 2
0
def calc_hmf(cosmos, zs):
    import aemHMF
    hmf = aemHMF.Aemulus_HMF()

    Nc = len(cosmos)
    Nz = len(zs)
    dndlMs = np.zeros((Nc, Nz, len(M)))
    for i in range(Nc):
        Ombh2, Omch2, w, ns, ln10As, H0, Neff, sig8 = cosmos[i]
        cosmo = {
            'Obh2': Ombh2,
            'Och2': Omch2,
            'w0': w,
            'n_s': ns,
            'ln10^{10}A_s': ln10As,
            'N_eff': Neff,
            'H0': H0
        }
        hmf.set_cosmology(cosmo)
        for j in range(Nz):
            z = zs[j]
            dndlMs[i, j] = hmf.dndlM(M, z)
            continue
        print("Finished with dndlM in box%d" % i)
        continue
    return dndlMs
def get_aemulus_beta(M, z):
    import aemHMF
    hmf = aemHMF.Aemulus_HMF()
    hmf.set_cosmology()
    d = 1.0001
    dndM1 = hmf.dndlM(M, z) / M
    dndM2 = hmf.dndlM(M * d, z) / (M * d)
    return np.log(dndM2 / dndM1) / np.log(d)
Ejemplo n.º 4
0
def mf_obj(i):
    Ombh2, Omch2, w, ns, ln10As, H0, Neff, sig8 = AD.building_box_cosmologies(
    )[i]
    cosmo = {
        'Obh2': Ombh2,
        'Och2': Omch2,
        'w0': w,
        'n_s': ns,
        'ln10^{10}A_s': ln10As,
        'N_eff': Neff,
        'H0': H0
    }
    hmf = aemHMF.Aemulus_HMF()
    hmf.set_cosmology(cosmo)
    return hmf
Ejemplo n.º 5
0
def get_cosmo(i):
    obh2, och2, w, ns, ln10As, H0, Neff, s8 = AD.building_box_cosmologies()[i]
    aemcosmo={'Obh2':obh2, 'Och2':och2, 'w0':w, 'n_s':ns, 'ln10^{10}A_s':ln10As, 'N_eff':Neff, 'H0':H0}
    import aemHMF
    hmf = aemHMF.Aemulus_HMF()
    hmf.set_cosmology(aemcosmo)

    h = H0/100.
    Omega_b = obh2/h**2
    Omega_c = och2/h**2
    Omega_m = Omega_b+Omega_c
    params = {'output': 'mPk', 'h': h, 'ln10^{10}A_s': ln10As, 'n_s': ns, 'w0_fld': w, 'wa_fld': 0.0, 'Omega_b': Omega_b, 'Omega_cdm': Omega_c, 'Omega_Lambda': 1.- Omega_m, 'N_eff': Neff, 'P_k_max_1/Mpc':10., 'z_max_pk':10. }
    cosmo = Class()
    cosmo.set(params)
    cosmo.compute()
    return cosmo, h, Omega_m, hmf
Ejemplo n.º 6
0
def function_of_z(ax):
    cosmo = default_cosmo.copy()
    hmf = aemHMF.Aemulus_HMF()
    hmf.set_cosmology(cosmo)
    
    sigma = np.linspace(1, 6, num=30)
    nu = deltac/sigma
    Gz0 = hmf.multiplicity_sigma(sigma, 0.5)
    for a in [1.0, 2./3., 0.5, 1./3., 0.25]:
        z = 1./a - 1
        G = hmf.multiplicity_sigma(sigma, a)
        Y = (G-Gz0)/Gz0
        ax.plot(nu, Y, label=r"$z=%.1f$"%z)
        print "z = %f done"%z
    #plt.title(r"$M_{low}$=%.1e  $M_{high}$=%.1e"%(min(M), max(M)))
    #plt.ylabel(r"$\frac{G(\sigma) - G(\sigma)_{fid}}{G(\sigma)_{fid}}$")
    ax.set_xlabel(r"$\nu$")
    ax.legend(loc="upper left", frameon=False, fontsize=12)
Ejemplo n.º 7
0
def function_of_sigma8(ax):
    hmf = aemHMF.Aemulus_HMF()
    a = 0.5
    z = 1./a - 1
    cosmo = default_cosmo.copy()
    cosmo['s8'] = 0.8
    hmf.set_cosmology(cosmo)
    nu = np.linspace(1, 6, num=30)
    sigma = deltac/nu
    Gom0 = hmf.multiplicity_sigma(sigma, a)

    for sig8 in [0.7, .75, 0.8, 0.85, .9]:
        cosmo["s8"] = sig8
        hmf.set_cosmology(cosmo)
        G = hmf.multiplicity_sigma(sigma, a)
        Y = (G - Gom0)/Gom0
        ax.plot(nu, Y, label=r"$\sigma_8=%.2f$"%sig8)
        print "z = %f done"%z
    #ax.set_ylabel(r"$\frac{G(\sigma)-G(\sigma)_{fid}}{G(\sigma)_{fid}}$")
    ax.set_xlabel(r"$\nu$")
    ax.legend(loc="upper left", frameon=False, fontsize=12)
Ejemplo n.º 8
0
def function_of_Omegam(ax):
    hmf = aemHMF.Aemulus_HMF()
    a = 0.5
    z = 1./a - 1
    cosmo = default_cosmo.copy()
    Om = 0.3
    cosmo['om'] = Om
    cosmo['ol'] = 1. - Om
    hmf.set_cosmology(cosmo)
    nu = np.linspace(1, 6, num=30)
    sigma = deltac/nu
    Gom0 = hmf.multiplicity_sigma(sigma, a)

    for Om in [0.26, 0.28, 0.3, 0.32, 0.34]:
        cosmo['om'] = Om
        cosmo['ol'] = 1. - Om
        hmf.set_cosmology(cosmo)
        G = hmf.multiplicity_sigma(sigma, a)
        Y = (G - Gom0)/Gom0
        ax.plot(nu, Y, label=r"$\Omega_m=%.2f$"%Om)
        print "z = %f done"%z
    ax.set_ylabel(r"$\frac{G(\sigma) - G(\sigma)_{fid}}{G(\sigma)_{fid}}$")
    ax.set_xlabel(r"$\nu$")
    ax.legend(loc=0, frameon=False, fontsize=12)
Ejemplo n.º 9
0
def peakheight_test(M, box=0):
    hmf = aemHMF.Aemulus_HMF()
    #nu has locations of the ticks in the x axis
    #Pick some cosmology, box=16
    Ombh2, Omch2, w, ns, ln10As, H0, Neff, sig8 = np.genfromtxt(
        AD.path_to_test_box_cosmologies())[int(box)]
    h = H0 / 100.
    Ob = Ombh2 / h**2
    Oc = Omch2 / h**2
    Om = Ob + Oc
    cosmo = {
        "om": Om,
        "ob": Ob,
        "ol": 1 - Om,
        "h": h,
        "s8": sig8,
        "ns": ns,
        "w0": w,
        "Neff": Neff,
        "wa": 0
    }
    hmf.set_cosmology(cosmo)
    a = 0.25
    return np.array([aemHMF.peak_height(Mi, a) for Mi in M])
Ejemplo n.º 10
0
        AD.path_to_test_box_cosmologies())[box]
    h = H0 / 100.
    Ob = Ombh2 / h**2
    Oc = Omch2 / h**2
    Om = Ob + Oc

    cosmo = {
        "om": Om,
        "ob": Ob,
        "ol": 1 - Om,
        "h": h,
        "s8": sig8,
        "ns": ns,
        "w0": w,
        "Neff": Neff
    }

    hmf = aemHMF.Aemulus_HMF()
    hmf.set_cosmology(cosmo)
    N_aem = hmf.n_bins(M_bins, a) * Volume
    pdiff = (N - N_aem) / N_aem

    f, axarr = plt.subplots(2, sharex=True)
    axarr[0].loglog(M, N, ls='', marker='.', c='k')
    axarr[0].loglog(M, N_aem, ls='-', c='b')
    axarr[0].set_yscale('log')

    axarr[1].plot(M, pdiff, c='b', ls='-')
    axarr[1].axhline(0, c='k', ls='--')
    plt.show()
Ejemplo n.º 11
0
def get_all_residuals(building_box=True, bf=False):
    if building_box:
        N_boxes = 40
        cospath = AD.path_to_building_box_cosmologies()
        outpath = "BB_residuals.txt"
        if with_f: outpath = "BB_residuals_f.txt"
    else:
        N_boxes = 7
        cospath = AD.path_to_test_box_cosmologies()
        outpath = "test_residuals.txt"
        if with_f: outpath = "test_residuals_f.txt"
    if bf:
        print "Working with best fits"
        N_boxes = 40
        cospath = AD.path_to_building_box_cosmologies()
        outpath = "bestfit_residuals.txt"
    N_snaps = 10
    hmf = aemHMF.Aemulus_HMF()
    z_arr = np.array([])
    lM_arr = np.array([])
    nu_arr = np.array([])
    Residuals = np.array([])
    Resid_err = np.array([])
    N_arr = np.array([])
    err_arr = np.array([])
    Nt08_arr = np.array([])
    boxnum_arr = np.array([])
    snapnum_arr = np.array([])
    for i in range(N_boxes):
        Ombh2, Omch2, w, ns, ln10As, H0, Neff, sig8 = np.genfromtxt(cospath)[i]
        h = H0 / 100.
        Ob = Ombh2 / h**2
        Oc = Omch2 / h**2
        Om = Ob + Oc
        cosmo = {
            "om": Om,
            "ob": Ob,
            "ol": 1 - Om,
            "h": h,
            "s8": sig8,
            "ns": ns,
            "w0": w,
            "Neff": Neff
        }
        hmf.set_cosmology(cosmo)
        for j in range(N_snaps):
            z, lM, nu, R, eR, N, err, Nt08, box, snap = get_residuals(
                i, j, hmf, building_box, bf)
            z_arr = np.concatenate([z_arr, z])
            lM_arr = np.concatenate([lM_arr, lM])
            nu_arr = np.concatenate([nu_arr, nu])
            Residuals = np.concatenate([Residuals, R])
            Resid_err = np.concatenate([Resid_err, eR])
            N_arr = np.concatenate([N_arr, N])
            err_arr = np.concatenate([err_arr, err])
            Nt08_arr = np.concatenate([Nt08_arr, Nt08])
            boxnum_arr = np.concatenate([boxnum_arr, box])
            snapnum_arr = np.concatenate([snapnum_arr, snap])
            print "Residuals made for the box at ", i, j
    out = np.array([
        z_arr, lM_arr, nu_arr, Residuals, Resid_err, N_arr, err_arr, Nt08_arr,
        boxnum_arr, snapnum_arr
    ]).T
    np.savetxt(outpath, out)
    print "done, with_f = ", with_f, " building_box = ", building_box, " bestfits = ", bf
Ejemplo n.º 12
0
    0.25, 0.333333, 0.5, 0.540541, 0.588235, 0.645161, 0.714286, 0.8, 0.909091,
    1.0
])
z = 1. / scale_factors - 1.0

if __name__ == "__main__":

    colors = get_colors()

    use_nu = True
    zs, lMs, nus, R, Re, N, err, Nt08, box, snap = np.genfromtxt(
        "BB_residuals.txt", unpack=True)
    if use_nu: x = nus
    else: x = lMs

    fgp = aemHMF.Aemulus_HMF().f
    nugp = np.linspace(min(x) - .1, max(x) + .1, 100)
    fig, axarr = plt.subplots(1, 2, sharey=True)
    #First do the points
    ax = 0
    for i in range(len(z)):
        if i not in [1, 9]: continue
        inds = (z[i] == zs)
        #print lMs[inds]
        #print np.log10(get_masses(nus[inds], z[i]))
        axarr[ax].plot(x[inds],
                       R[inds],
                       marker='.',
                       ls='',
                       markersize=1,
                       c=colors[i],