def get_CCL_beta(M, z):
    a = 1. / (1 + z)
    d = 1.0001
    import pyccl as ccl
    params = ccl.Parameters(Omega_c=cos['om'] - cos['ob'],
                            Omega_b=cos['ob'],
                            h=cos['h'],
                            sigma8=cos['s8'],
                            n_s=cos['ns'])
    cosmo = ccl.Cosmology(params)
    dndM1 = ccl.massfunc(cosmo, M, a) / M
    dndM2 = ccl.massfunc(cosmo, M * d, a) / (M * d)
    return np.log(dndM2 / dndM1) / np.log(d)
Пример #2
0
    def profnorm(self, cosmo, a, squeeze=True, **kwargs):
        """Computes the overall profile normalisation for the angular cross-
        correlation calculation."""
        # Input handling
        a = np.atleast_1d(a)

        # extract parameters
        fc = kwargs["fc"]

        logMmin, logMmax = (6, 17)  # log of min and max halo mass [Msun]
        mpoints = int(64)  # number of integration points
        M = np.logspace(logMmin, logMmax, mpoints)  # masses sampled

        # CCL uses delta_matter
        Dm = self.Delta / ccl.omega_x(cosmo, a, "matter")
        mfunc = [ccl.massfunc(cosmo, M, A1, A2) for A1, A2 in zip(a, Dm)]

        Nc = self.n_cent(M, **kwargs)  # centrals
        Ns = self.n_sat(M, **kwargs)  # satellites

        if self.ns_independent:
            dng = mfunc * (Nc * fc + Ns)  # integrand
        else:
            dng = mfunc * Nc * (fc + Ns)  # integrand

        ng = simps(dng, x=np.log10(M))
        return ng.squeeze() if squeeze else ng
Пример #3
0
def test_mass_function():
    df = pd.read_csv(os.path.join(os.path.dirname(__file__),
                                  'data/model1_hmf.txt'),
                     sep=' ',
                     names=['logmass', 'sigma', 'invsigma', 'logmf'],
                     skiprows=1)

    ccl.physical_constants.T_CMB = 2.7
    with ccl.Cosmology(Omega_c=0.25,
                       Omega_b=0.05,
                       Omega_g=0,
                       Omega_k=0,
                       h=0.7,
                       sigma8=0.8,
                       n_s=0.96,
                       Neff=0,
                       m_nu=0.0,
                       w0=-1,
                       wa=0,
                       transfer_function='bbks',
                       mass_function='tinker') as c:

        rho_m = ccl.physical_constants.RHO_CRITICAL * c['Omega_m'] * c['h']**2
        for i, logmass in enumerate(df['logmass']):
            mass = 10**logmass
            sigma = ccl.sigmaM(c, mass, 1.0)
            loginvsigma = np.log10(1.0 / sigma)
            logmf = np.log10(
                ccl.massfunc(c, mass, 1, 200) * mass / rho_m / np.log(10))

            assert np.allclose(sigma, df['sigma'].values[i], rtol=3e-5)
            assert np.allclose(loginvsigma,
                               df['invsigma'].values[i],
                               rtol=1e-3)
            assert np.allclose(logmf, df['logmf'].values[i], rtol=5e-5)
Пример #4
0
def check_massfunc(cosmo):
    """
    Check that mass function and supporting functions can be run.
    """

    z = 0.
    z_arr = np.linspace(0., 2., 10)
    a = 1.
    a_arr = 1. / (1. + z_arr)
    mhalo_scl = 1e13
    mhalo_lst = [1e11, 1e12, 1e13, 1e14, 1e15, 1e16]
    mhalo_arr = np.array([1e11, 1e12, 1e13, 1e14, 1e15, 1e16])
    odelta = 200.

    # massfunc
    assert_(all_finite(ccl.massfunc(cosmo, mhalo_scl, a, odelta)))
    assert_(all_finite(ccl.massfunc(cosmo, mhalo_lst, a, odelta)))
    assert_(all_finite(ccl.massfunc(cosmo, mhalo_arr, a, odelta)))

    assert_raises(TypeError, ccl.massfunc, cosmo, mhalo_scl, a_arr, odelta)
    assert_raises(TypeError, ccl.massfunc, cosmo, mhalo_lst, a_arr, odelta)
    assert_raises(TypeError, ccl.massfunc, cosmo, mhalo_arr, a_arr, odelta)

    # Check whether odelta out of bounds
    assert_raises(CCLError, ccl.massfunc, cosmo, mhalo_scl, a, 199.)
    assert_raises(CCLError, ccl.massfunc, cosmo, mhalo_scl, a, 5000.)

    # massfunc_m2r
    assert_(all_finite(ccl.massfunc_m2r(cosmo, mhalo_scl)))
    assert_(all_finite(ccl.massfunc_m2r(cosmo, mhalo_lst)))
    assert_(all_finite(ccl.massfunc_m2r(cosmo, mhalo_arr)))

    # sigmaM
    assert_(all_finite(ccl.sigmaM(cosmo, mhalo_scl, a)))
    assert_(all_finite(ccl.sigmaM(cosmo, mhalo_lst, a)))
    assert_(all_finite(ccl.sigmaM(cosmo, mhalo_arr, a)))

    assert_raises(TypeError, ccl.sigmaM, cosmo, mhalo_scl, a_arr)
    assert_raises(TypeError, ccl.sigmaM, cosmo, mhalo_lst, a_arr)
    assert_raises(TypeError, ccl.sigmaM, cosmo, mhalo_arr, a_arr)

    # halo_bias
    assert_(all_finite(ccl.halo_bias(cosmo, mhalo_scl, a)))
    assert_(all_finite(ccl.halo_bias(cosmo, mhalo_lst, a)))
    assert_(all_finite(ccl.halo_bias(cosmo, mhalo_arr, a)))
Пример #5
0
    def nm_integ(z):
        """
        Integral to get n(>M_min).
        """
        Mh = Mh_range(z, **args)
        dndlog10m = ccl.massfunc(cosmo, Mh, 1. / (1. + z))

        # Integrate over mass range
        return integrate.simps(dndlog10m, np.log10(Mh))
Пример #6
0
def get_bpe(z, n_r, delta, nmass=256):
    a = 1./(1+z)
    lmarr = np.linspace(8.,16.,nmass)
    marr = 10.**lmarr
    Dm = delta/ccl.omega_x(cosmo, a, "matter")  # CCL uses Delta_m
    mfunc = ccl.massfunc(cosmo, marr, a, Dm)
    bh = ccl.halo_bias(cosmo, marr, a, Dm)
    et = np.array([integrated_profile(get_battaglia(m,z,delta),n_r) for m in marr])

    return itg.simps(et*bh*mfunc,x=lmarr)
Пример #7
0
    def pk(self, k, a, lmmin=6., lmmax=17., nlm=256, return_decomposed=False):
        """
        Returns power spectrum at redshift `z` sampled at all values of k in `k`.

        k : array of wavenumbers in CCL units
        a : scale factor
        lmmin, lmmax, nlm : mass edges and sampling rate for mass integral.
        return_decomposed : if True, returns 1-halo, 2-halo, bias, shot noise and total (see below for order).
        """
        z = 1. / a - 1.
        marr = np.logspace(lmmin, lmmax, nlm)
        dlm = np.log10(marr[1] / marr[0])
        u_s = self.u_sat(z, marr, k)
        hmf = ccl.massfunc(self.cosmo, marr, a)
        hbf = ccl.halo_bias(self.cosmo, marr, a)
        rhoM = ccl.rho_x(self.cosmo, a, "matter", is_comoving=True)
        n0_1h = (rhoM - np.sum(hmf * marr) * dlm) / marr[0]
        n0_2h = (rhoM - np.sum(hmf * hbf * marr) * dlm) / marr[0]

        #Number of galaxies
        fc = self.fc_f(z)
        ngm = self.n_tot(z, marr)
        ncm = self.n_cent(z, marr)
        nsm = self.n_sat(z, marr)

        #Number density
        ng = np.sum(hmf * ngm) * dlm + n0_1h * ngm[0]
        if ng <= 1E-16:  #Make sure we won't divide by 0
            return None

        #Bias
        b_hod = np.sum(
            (hmf * hbf * ncm)[None, :] * (fc + nsm[None, :] * u_s[:, :]),
            axis=1) * dlm + n0_2h * ncm[0] * (fc + nsm[0] * u_s[:, 0])
        b_hod /= ng

        #1-halo
        #p1h=np.sum((hmf*ncm**2)[None,:]*(fc+nsm[None,:]*u_s[:,:])**2,axis=1)*dlm+n0_1h*(ncm[0]*(fc+nsm[0]*u_s[:,0]))**2
        p1h = np.sum(
            (hmf * ncm)[None, :] * (2 * fc * nsm[None, :] * u_s[:, :] +
                                    (nsm[None, :] * u_s[:, :])**2),
            axis=1) * dlm + n0_1h * ncm[0] * (2 * fc * nsm[0] * u_s[:, 0] +
                                              (nsm[0] * u_s[:, 0])**2)
        p1h /= ng**2

        #2-halo
        p2h = b_hod**2 * ccl.linear_matter_power(self.cosmo, k, a)

        if return_decomposed:
            return p1h + p2h, p1h, p2h, np.ones_like(k) / ng, b_hod
        else:
            return p1h + p2h
Пример #8
0
def test_massfunc_models_smoke(mf_type):
    cosmo = ccl.Cosmology(Omega_c=0.27,
                          Omega_b=0.045,
                          h=0.67,
                          sigma8=0.8,
                          n_s=0.96,
                          transfer_function='bbks',
                          matter_power_spectrum='linear',
                          mass_function=mf_type)
    hmf_cls = ccl.halos.mass_function_from_name(MF_EQUIV[mf_type])
    hmf = hmf_cls(cosmo)
    for m in MS:
        nm_old = ccl.massfunc(cosmo, m, 1.)
        nm_new = hmf.get_mass_function(cosmo, m, 1.)
        assert np.all(np.isfinite(nm_old))
        assert np.shape(nm_old) == np.shape(m)
        assert np.all(np.array(nm_old) == np.array(nm_new))
Пример #9
0
def hm_bias(cosmo,
            a,
            profile,
            logMrange=(6, 17),
            mpoints=128,
            selection=None,
            **kwargs):
    """Computes the halo model prediction for the bias of a given
    tracer.

    Args:
        cosmo (:obj:`ccl.Cosmology`): cosmology.
        a (array): array of scale factor values
        profile (`Profile`): a profile. Only Arnaud and HOD are
            implemented.
        logMrange (tuple): limits of integration in log10(M/Msun)
        mpoints (int): number of mass samples
        selection (function): selection function in (M,z) to include
            in the calculation. Pass None if you don't want to select
            a subset of the M-z plane.
        **kwargs: parameter used internally by the profiles.
    """
    # Input handling
    a = np.atleast_1d(a)

    # Profile normalisations
    Unorm = profile.profnorm(cosmo, a, squeeze=False, **kwargs)
    Unorm = Unorm[..., None]

    # Set up integration boundaries
    logMmin, logMmax = logMrange  # log of min and max halo mass [Msun]
    mpoints = int(mpoints)  # number of integration points
    M = np.logspace(logMmin, logMmax, mpoints)  # masses sampled

    # Out-of-loop optimisations
    Dm = profile.Delta / ccl.omega_x(cosmo, a, "matter")  # CCL uses Delta_m
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        mfunc = np.array(
            [ccl.massfunc(cosmo, M, A1, A2) for A1, A2 in zip(a, Dm)])
        bh = np.array(
            [ccl.halo_bias(cosmo, M, A1, A2) for A1, A2 in zip(a, Dm)])
    # shape transformations
    mfunc, bh = mfunc.T[..., None], bh.T[..., None]
    if selection is not None:
        select = np.array([selection(M, 1. / aa - 1) for aa in a])
        select = select.T[..., None]
    else:
        select = 1

    U, _ = profile.fourier_profiles(cosmo,
                                    np.array([0.001]),
                                    M,
                                    a,
                                    squeeze=False,
                                    **kwargs)

    # Tinker mass function is given in dn/dlog10M, so integrate over d(log10M)
    b2h = simps(bh * mfunc * select * U, x=np.log10(M), axis=0).squeeze()

    # Contribution from small masses (added in the beginning)
    rhoM = ccl.rho_x(cosmo, a, "matter", is_comoving=True)
    dlM = (logMmax - logMmin) / (mpoints - 1)
    mfunc, bh = mfunc.squeeze(), bh.squeeze()  # squeeze extra dimensions

    n0_2h = np.array((rhoM - np.dot(M, mfunc * bh) * dlM) / M[0])[None, ...,
                                                                  None]

    b2h += (n0_2h * U[0]).squeeze()
    b2h /= Unorm.squeeze()

    return b2h.squeeze()
Пример #10
0
def hm_power_spectrum(cosmo,
                      k,
                      a,
                      profiles,
                      logMrange=(6, 17),
                      mpoints=128,
                      include_1h=True,
                      include_2h=True,
                      squeeze=True,
                      hm_correction=None,
                      selection=None,
                      **kwargs):
    """Computes the halo model prediction for the 3D cross-power
    spectrum of two quantities.

    Args:
        cosmo (:obj:`ccl.Cosmology`): cosmology.
        k (array): array of wavenumbers in units of Mpc^-1
        a (array): array of scale factor values
        profiles (tuple): tuple of two profile objects (currently
            only Arnaud and HOD are implemented) corresponding to
            the two quantities being correlated.
        logMrange (tuple): limits of integration in log10(M/Msun)
        mpoints (int): number of mass samples
        include_1h (bool): whether to include the 1-halo term.
        include_2h (bool): whether to include the 2-halo term.
        hm_correction (:obj:`HalomodCorrection` or None):
            Correction to the halo model in the transition regime.
            If `None`, no correction is applied.
        selection (function): selection function in (M,z) to include
            in the calculation. Pass None if you don't want to select
            a subset of the M-z plane.
        **kwargs: parameter used internally by the profiles.
    """
    # Input handling
    a, k = np.atleast_1d(a), np.atleast_2d(k)

    # Profile normalisations
    p1, p2 = profiles
    Unorm = p1.profnorm(cosmo, a, squeeze=False, **kwargs)
    if p1.name == p2.name:
        Vnorm = Unorm
    else:
        Vnorm = p2.profnorm(cosmo, a, squeeze=False, **kwargs)
    if (Vnorm < 1e-16).any() or (Unorm < 1e-16).any():
        return None  # zero division
    Unorm, Vnorm = Unorm[..., None], Vnorm[..., None]  # transform axes

    # Set up integration boundaries
    logMmin, logMmax = logMrange  # log of min and max halo mass [Msun]
    mpoints = int(mpoints)  # number of integration points
    M = np.logspace(logMmin, logMmax, mpoints)  # masses sampled

    # Out-of-loop optimisations
    Pl = np.array(
        [ccl.linear_matter_power(cosmo, k[i], a) for i, a in enumerate(a)])
    Dm = p1.Delta / ccl.omega_x(cosmo, a, "matter")  # CCL uses Delta_m
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        mfunc = np.array(
            [ccl.massfunc(cosmo, M, A1, A2) for A1, A2 in zip(a, Dm)])

    if selection is not None:
        select = np.array([selection(M, 1. / aa - 1) for aa in a])
        mfunc *= select

    # tinker10 halo bias
    csm = ccl.Cosmology(Omega_c=cosmo["Omega_c"],
                        Omega_b=cosmo["Omega_b"],
                        h=cosmo["h"],
                        sigma8=cosmo["sigma8"],
                        n_s=cosmo["n_s"],
                        mass_function="tinker10")

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        bh = np.array([ccl.halo_bias(csm, M, A1, A2) for A1, A2 in zip(a, Dm)])

    # shape transformations
    mfunc, bh = mfunc.T[..., None], bh.T[..., None]
    if selection is not None:
        select = np.array([selection(M, 1. / aa - 1) for aa in a])
        select = select.T[..., None]
    else:
        select = 1

    U, UU = p1.fourier_profiles(cosmo, k, M, a, squeeze=False, **kwargs)
    # optimise for autocorrelation (no need to recompute)
    if p1.name == p2.name:
        V = U
        UV = UU
    else:
        V, VV = p2.fourier_profiles(cosmo, k, M, a, squeeze=False, **kwargs)
        r = kwargs["r_corr"] if "r_corr" in kwargs else 0
        UV = U * V * (1 + r)

    # Tinker mass function is given in dn/dlog10M, so integrate over d(log10M)
    P1h = simps(mfunc * select * UV, x=np.log10(M), axis=0)
    b2h_1 = simps(bh * mfunc * select * U, x=np.log10(M), axis=0)
    b2h_2 = simps(bh * mfunc * select * V, x=np.log10(M), axis=0)

    # Contribution from small masses (added in the beginning)
    rhoM = ccl.rho_x(cosmo, a, "matter", is_comoving=True)
    dlM = (logMmax - logMmin) / (mpoints - 1)
    mfunc, bh = mfunc.squeeze(), bh.squeeze()  # squeeze extra dimensions

    n0_1h = np.array((rhoM - np.dot(M, mfunc) * dlM) / M[0])[None, ..., None]
    n0_2h = np.array((rhoM - np.dot(M, mfunc * bh) * dlM) / M[0])[None, ...,
                                                                  None]

    P1h += (n0_1h * U[0] * V[0]).squeeze()
    b2h_1 += (n0_2h * U[0]).squeeze()
    b2h_2 += (n0_2h * V[0]).squeeze()

    F = (include_1h * P1h + include_2h *
         (Pl * b2h_1 * b2h_2)) / (Unorm * Vnorm)
    if hm_correction is not None:
        for ia, (aa, kk) in enumerate(zip(a, k)):
            R = hm_correction.rk_interp(kk, aa)
            F[ia, :] *= R

    return F.squeeze() if squeeze else F
Пример #11
0
cosmo = [
    ccl.Cosmology(Omega_c=0.26066676,
                  Omega_b=0.048974682,
                  h=0.6766,
                  sigma8=0.8102,
                  n_s=0.9665,
                  mass_function=mf) for mf in ["tinker", "tinker10"]
]

M = np.logspace(10, 15, 100)

mfr = [[]] * len(a)
for i, sf in enumerate(a):
    rho = [500 / ccl.omega_x(c, sf, "matter") for c in cosmo]
    mf = [ccl.massfunc(c, M, sf, overdensity=r) for c, r in zip(cosmo, rho)]
    mfr[i] = mf[0] / mf[1]

mfr = np.array(mfr)

cmap = truncate_colormap(cm.Reds, 0.2, 1.0)
col = [cmap(i) for i in np.linspace(0, 1, len(a))]

fig, ax = plt.subplots()
ax.set_xlim(M.min(), M.max())
ax.axhline(y=1, ls="--", color="k")
[ax.loglog(M, R, c=c, label="%s" % red) for R, c, red in zip(mfr, col, z)]

ax.yaxis.set_major_formatter(FormatStrFormatter("$%.1f$"))
ax.yaxis.set_minor_formatter(FormatStrFormatter("$%.1f$"))
Пример #12
0
    def x(self):
        pass


# Specify cosmology
cosmo = ccl.Cosmology(h=0.67,
                      Omega_c=0.25,
                      Omega_b=0.045,
                      n_s=0.965,
                      sigma8=0.834)

z = 0.

# Halo mass function
Mh = np.logspace(np.log10(MH_MIN), np.log10(MH_MAX), MH_BINS)
dndlog10m = ccl.massfunc(cosmo, Mh, 1. / (1. + z))
bh = ccl.halo_bias(cosmo, Mh, a)

# Cumulative integral of halo mass function
nm = integrate.cumtrapz(dndlog10m[::-1], -np.log10(Mh)[::-1], initial=0.)[::-1]

# Rescale nm to get cdf
cdf = nm / np.max(nm)

# Build interpolator
Mh_interp = interpolate.interp1d(cdf, np.log10(Mh), kind='linear')

np.random.seed(10)
u = np.random.uniform(size=int(1e6))

# Realise halo mass distribution
Пример #13
0
def test_massfunc_smoke(m):
    a = 0.8
    mf = ccl.massfunc(COSMO, m, a)
    assert np.all(np.isfinite(mf))
    assert np.shape(mf) == np.shape(m)
Пример #14
0
    def pk_gm(self,
              k,
              a,
              lmmin=6.,
              lmmax=17.,
              nlm=256,
              return_decomposed=False):
        """
        Returns galaxy-matter power spectrum at a single scale-factor a for array of wave vectors k.
        :param k: wave vector array
        :param a: single scale factor value
        :param lmmin: Mmin for HOD integrals
        :param lmmax: Mmax for HOD integrals
        :param nlm: sampling rate for mass integral
        :param return_decomposed: boolean tag, if True return 1h, 2h power spectrum separately
        :return:
        """

        z = 1. / a - 1.
        marr = np.logspace(lmmin, lmmax, nlm)
        dlm = np.log10(marr[1] / marr[0])
        u_nfw = self.u_sat(z, marr, k)
        hmf = ccl.massfunc(self.cosmo, marr, a)
        hbf = ccl.halo_bias(self.cosmo, marr, a)
        rhoM = ccl.rho_x(self.cosmo, a, "matter", is_comoving=True)
        n0_1h = (rhoM - np.sum(hmf * marr) * dlm) / marr[0]
        n0_2h = (rhoM - np.sum(hmf * hbf * marr) * dlm) / marr[0]
        # n0_2h = (rhoM - np.sum(hmf*hbf*marr)*dlm)

        #Number of galaxies
        fc = self.fc_f(z)
        ngm = self.n_tot(z, marr)
        ncm = self.n_cent(z, marr)
        nsm = self.n_sat(z, marr)

        #Number density
        ng = np.sum(hmf * ngm) * dlm + n0_1h * ngm[0]
        if ng <= 1E-16:  #Make sure we won't divide by 0
            return None

        #Bias
        b_hod=np.sum((hmf*hbf*ncm)[None,:]*(fc+nsm[None,:]*u_nfw[:,:]),axis=1)*dlm \
              + n0_2h*ncm[0]*(fc+nsm[0]*u_nfw[:,0])
        b_m = np.sum((hmf * hbf)[None, :] * marr[None, :] * u_nfw[:, :],
                     axis=1) * dlm + n0_2h * u_nfw[:, 0]

        b_hod /= ng
        b_m /= rhoM

        #1-halo
        #p1h=np.sum((hmf*ncm**2)[None,:]*(fc+nsm[None,:]*u_s[:,:])**2,axis=1)*dlm+n0_1h*(ncm[0]*(fc+nsm[0]*u_s[:,0]))**2
        p1h=np.sum((hmf*ncm)[None,:]*(fc+nsm[None,:]*u_nfw[:,:])*marr*u_nfw[:,:],axis=1)*dlm \
            + n0_1h*ncm[0]*(fc + nsm[0]*u_nfw[:,0])*u_nfw[:,0]
        p1h /= ng * rhoM

        #2-halo
        p2h = b_hod * b_m * ccl.linear_matter_power(self.cosmo, k, a)

        if return_decomposed:
            return p1h + p2h, p1h, p2h, np.ones_like(k) / ng, b_hod
        else:
            return p1h + p2h
Пример #15
0
 def __init__(self):
     """
     Initialise.
     """
     Mh = Mh_range(z, **args)
     dndlog10m = ccl.massfunc(cosmo, Mh, 1. / (1. + z))
Пример #16
0
           aspect='auto',
           extent=[0, 1, 13.5, 15.5])
plt.scatter(data['REDSHIFT'], np.log10(data['MSZ'] * 1E14), c='r', s=1)
plt.plot(zs, np.log10(selection_planck_mthr(zs)), 'k-', lw=2)
plt.xlim([0, 0.6])
plt.ylim([13.7, 15.2])
plt.xlabel('$z$', fontsize=16)
plt.ylabel('$\\log_{10}(M/M_\\odot)$', fontsize=16)

zranges = [[0, 0.07], [0.07, 0.17], [0.17, 0.3], [0.3, 0.5], [0.5, 1.]]
for z0, zf in zranges:
    mask = (data['REDSHIFT'] < zf) & (data['REDSHIFT'] >= z0)
    zmean = np.mean(data['REDSHIFT'][mask])
    ms = 10.**np.linspace(13.7, 15.5, 20)
    Delta = 500. / ccl.omega_x(cosmo, 1. / (1 + zmean), "matter")
    hmf = ccl.massfunc(cosmo, ms, 1. / (1 + zmean), Delta)
    pd = np.histogram(np.log10(data['MSZ'][mask] * 1E14),
                      range=[13.7, 15.5],
                      bins=20)[0] + 0.
    pd /= np.sum(pd)
    pt = selection_planck_erf(ms, zmean, complementary=False)
    pt = pt * hmf / np.sum(pt * hmf)

    plt.figure()
    plt.plot(ms, pt, 'k-')
    plt.plot(ms, pd, 'r-')
    plt.xscale('log')
plt.show()

#Compute their angular extent
r500 = rDelta(data['MSZ'] * HH * 1E14, data['REDSHIFT'], 500)
Пример #17
0
def hm_1h_trispectrum(cosmo,
                      k,
                      a,
                      profiles,
                      logMrange=(8, 16),
                      mpoints=128,
                      selection=None,
                      **kwargs):
    """Computes the halo model prediction for the 1-halo 3D
    trispectrum of four quantities.

    Args:
        cosmo (:obj:`ccl.Cosmology`): cosmology.
        k (array): array of wavenumbers in units of Mpc^-1
        a (array): array of scale factor values
        profiles (tuple): tuple of four profile objects (currently
            only Arnaud and HOD are implemented) corresponding to
            the four quantities being correlated.
        logMrange (tuple): limits of integration in log10(M/Msun)
        mpoints (int): number of mass samples
        selection (function): selection function in (M,z) to include
            in the calculation. Pass None if you don't want to select
            a subset of the M-z plane.
        **kwargs: parameter used internally by the profiles.
    """
    k = np.atleast_1d(k)
    a = np.atleast_1d(a)
    pau, pav, pbu, pbv = profiles

    aUnorm = pau.profnorm(cosmo, a, squeeze=False, **kwargs)
    aVnorm = pav.profnorm(cosmo, a, squeeze=False, **kwargs)
    bUnorm = pbu.profnorm(cosmo, a, squeeze=False, **kwargs)
    bVnorm = pbv.profnorm(cosmo, a, squeeze=False, **kwargs)

    logMmin, logMmax = logMrange
    mpoints = int(mpoints)
    M = np.logspace(logMmin, logMmax, mpoints)

    Dm = pau.Delta / ccl.omega_x(cosmo, a, 'matter')
    mfunc = np.array(
        [ccl.massfunc(cosmo, M, aa, Dmm) for aa, Dmm in zip(a, Dm)]).T
    if selection is not None:
        select = np.array([selection(M, 1. / aa - 1) for aa in a]).T
    else:
        select = 1

    aU, aUU = pau.fourier_profiles(cosmo, k, M, a, squeeze=False, **kwargs)
    if pau.name == pav.name:
        aUV = aUU
    else:
        aV, aVV = pav.fourier_profiles(cosmo, k, M, a, squeeze=False, **kwargs)
        if 'r_corr' in kwargs:
            r = kwargs['r_corr']
        else:
            r = 0

        # aUV = np.sqrt(aUU*aVV)*(1+r)
        aUV = aU * aV * (1 + r)

    bU, bUU = pbu.fourier_profiles(cosmo, k, M, a, squeeze=False, **kwargs)
    if pbu.name == pbv.name:
        bUV = bUU
    else:
        bV, bVV = pbv.fourier_profiles(cosmo, k, M, a, squeeze=False, **kwargs)
        if 'r_corr' in kwargs:
            r = kwargs['r_corr']
        else:
            r = 0

        # bUV = np.sqrt(bUU*bVV)*(1+r)
        bUV = bU * bV * (1 + r)

    t1h = simps((select * mfunc)[:, :, None, None] * aUV[:, :, :, None] *
                bUV[:, :, None, :],
                x=np.log10(M),
                axis=0)

    rhoM = ccl.rho_x(cosmo, a, "matter", is_comoving=True)
    dlM = (logMmax - logMmin) / (mpoints - 1)
    n0_1h = (rhoM - np.dot(M, mfunc) * dlM) / M[0]
    t1h += (n0_1h[:, None, None] * aUV[0, :, :, None] * bUV[0, :, None, :])
    t1h /= (aUnorm * aVnorm * bUnorm * bVnorm)[:, None, None]

    return t1h