コード例 #1
0
ファイル: test_hmfunc.py プロジェクト: wwk5c5gh3/CCL
def test_nM_tinker_crit(mf):
    a = 0.5
    om = ccl.omega_x(COSMO, a, 'matter')
    oc = ccl.omega_x(COSMO, a, 'critical')
    delta_c = 500.
    delta_m = delta_c * oc / om
    mdef_c = ccl.halos.MassDef(delta_c, 'critical')
    mdef_m = ccl.halos.MassDef(delta_m, 'matter')
    nM_c = mf(COSMO, mdef_c)
    nM_m = mf(COSMO, mdef_m)
    assert np.allclose(nM_c.get_mass_function(COSMO, 1E13, a),
                       nM_m.get_mass_function(COSMO, 1E13, a))
コード例 #2
0
def check_background_nu(cosmo):
    """
    Check that background functions can be run and that the growth functions
    exit gracefully in functions with massive neutrinos (not implemented yet).
    """
    # Types of scale factor input (scalar, list, array)
    a_scl = 0.5
    a_lst = [0.2, 0.4, 0.6, 0.8, 1.]
    a_arr = np.linspace(0.2, 1., 5)

    # growth_factor
    assert_raises(CCLError, ccl.growth_factor, cosmo, a_scl)
    assert_raises(CCLError, ccl.growth_factor, cosmo, a_lst)
    assert_raises(CCLError, ccl.growth_factor, cosmo, a_arr)

    # growth_factor_unnorm
    assert_raises(CCLError, ccl.growth_factor_unnorm, cosmo, a_scl)
    assert_raises(CCLError, ccl.growth_factor_unnorm, cosmo, a_lst)
    assert_raises(CCLError, ccl.growth_factor_unnorm, cosmo, a_arr)

    # growth_rate
    assert_raises(CCLError, ccl.growth_rate, cosmo, a_scl)
    assert_raises(CCLError, ccl.growth_rate, cosmo, a_lst)
    assert_raises(CCLError, ccl.growth_rate, cosmo, a_arr)

    # comoving_radial_distance
    assert_(all_finite(ccl.comoving_radial_distance(cosmo, a_scl)))
    assert_(all_finite(ccl.comoving_radial_distance(cosmo, a_lst)))
    assert_(all_finite(ccl.comoving_radial_distance(cosmo, a_arr)))

    # h_over_h0
    assert_(all_finite(ccl.h_over_h0(cosmo, a_scl)))
    assert_(all_finite(ccl.h_over_h0(cosmo, a_lst)))
    assert_(all_finite(ccl.h_over_h0(cosmo, a_arr)))

    # luminosity_distance
    assert_(all_finite(ccl.luminosity_distance(cosmo, a_scl)))
    assert_(all_finite(ccl.luminosity_distance(cosmo, a_lst)))
    assert_(all_finite(ccl.luminosity_distance(cosmo, a_arr)))

    # scale_factor_of_chi
    assert_(all_finite(ccl.scale_factor_of_chi(cosmo, a_scl)))
    assert_(all_finite(ccl.scale_factor_of_chi(cosmo, a_lst)))
    assert_(all_finite(ccl.scale_factor_of_chi(cosmo, a_arr)))

    # omega_m_a
    assert_(all_finite(ccl.omega_x(cosmo, a_scl, 'matter')))
    assert_(all_finite(ccl.omega_x(cosmo, a_lst, 'matter')))
    assert_(all_finite(ccl.omega_x(cosmo, a_arr, 'matter')))
コード例 #3
0
def check_background(cosmo):
    """
    Check that background and growth functions can be run.
    """
    # Types of scale factor input (scalar, list, array)
    a_scl = 0.5
    a_lst = [0.2, 0.4, 0.6, 0.8, 1.]
    a_arr = np.linspace(0.2, 1., 5)
    
    # growth_factor
    assert_( all_finite(ccl.growth_factor(cosmo, a_scl)) )
    assert_( all_finite(ccl.growth_factor(cosmo, a_lst)) )
    assert_( all_finite(ccl.growth_factor(cosmo, a_arr)) )
    
    # growth_factor_unnorm
    assert_( all_finite(ccl.growth_factor_unnorm(cosmo, a_scl)) )
    assert_( all_finite(ccl.growth_factor_unnorm(cosmo, a_lst)) )
    assert_( all_finite(ccl.growth_factor_unnorm(cosmo, a_arr)) )
    
    # growth_rate
    assert_( all_finite(ccl.growth_rate(cosmo, a_scl)) )
    assert_( all_finite(ccl.growth_rate(cosmo, a_lst)) )
    assert_( all_finite(ccl.growth_rate(cosmo, a_arr)) )
    
    # comoving_radial_distance
    assert_( all_finite(ccl.comoving_radial_distance(cosmo, a_scl)) )
    assert_( all_finite(ccl.comoving_radial_distance(cosmo, a_lst)) )
    assert_( all_finite(ccl.comoving_radial_distance(cosmo, a_arr)) )
    
    # h_over_h0
    assert_( all_finite(ccl.h_over_h0(cosmo, a_scl)) )
    assert_( all_finite(ccl.h_over_h0(cosmo, a_lst)) )
    assert_( all_finite(ccl.h_over_h0(cosmo, a_arr)) )
    
    # luminosity_distance
    assert_( all_finite(ccl.luminosity_distance(cosmo, a_scl)) )
    assert_( all_finite(ccl.luminosity_distance(cosmo, a_lst)) )
    assert_( all_finite(ccl.luminosity_distance(cosmo, a_arr)) )
    
    # scale_factor_of_chi
    assert_( all_finite(ccl.scale_factor_of_chi(cosmo, a_scl)) )
    assert_( all_finite(ccl.scale_factor_of_chi(cosmo, a_lst)) )
    assert_( all_finite(ccl.scale_factor_of_chi(cosmo, a_arr)) )
    
    # omega_m_a
    assert_( all_finite(ccl.omega_x(cosmo, a_scl, 'matter')) )
    assert_( all_finite(ccl.omega_x(cosmo, a_lst, 'matter')) )
    assert_( all_finite(ccl.omega_x(cosmo, a_arr, 'matter')) )
コード例 #4
0
def r_Delta(cosmo, halo_mass, a, Delta=200, is_matter=False):
    """
    Calculate the reference radius of a halo.

    .. note:: this is R=(3M/(4*pi*rho_c(a)*Delta))^(1/3), where rho_c is the critical
              matter density

    Arguments
    ---------
    cosmo : ``pyccl.Cosmology`` object
        Cosmological parameters.
    halo_mass : float or array_like
        Halo mass [Msun].
    a : float
        Scale factor
    Delta : float
        Overdensity parameter.

    Returns
    -------
    float or array_like : The halo reference radius in `Mpc`.
    """
    omega_factor = 1.
    if is_matter:
        omega_factor = ccl.omega_x(cosmo, a, 'matter')
    prefac = Delta * omega_factor * 1.16217766E12 * (
        cosmo['h'] * ccl.h_over_h0(cosmo, a))**2
    return (halo_mass / prefac)**(1. / 3.)
コード例 #5
0
ファイル: profile2D.py プロジェクト: nikfilippas/yxg
    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
コード例 #6
0
ファイル: plot_by.py プロジェクト: nikfilippas/yxg
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 _get_param(self, key):
     if key == "Omega_m0":
         return ccl.omega_x(self.be_cosmo, 1.0, "matter")
     elif key == "Omega_b0":
         return self.be_cosmo['Omega_b']
     elif key == "Omega_dm0":
         return self.be_cosmo['Omega_c']
     elif key == "Omega_k0":
         return self.be_cosmo['Omega_k']
     elif key == 'h':
         return self.be_cosmo['h']
     elif key == 'H0':
         return self.be_cosmo['h']*100.0
     else:
         raise ValueError(f"Unsupported parameter {key}")
コード例 #8
0
def R_Delta(cosmo, M, a, Delta=500, is_matter=False, squeeze=True, **kwargs):
    """
    Calculate the reference radius of a halo.

    .. note:: This is ``R = (3M/(4*pi*rho_c(a)*Delta))^(1/3)``, where rho_c is
              the critical matter density at scale factor ``a``.

    Arguments
    ---------
    cosmo: ~pyccl.core.Cosmology
        Cosmology object.
    M : float or array_like
        Halo mass [Msun].
    a : float or array_like
        Scale factor
    Delta : float
        Overdensity parameter.
    is_matter : bool
        True when R_Delta is calculated using the average matter density.
        False when R_Delta is calculated using the critical density.
    squeeze : bool
        Whether to squeeze extra dimensions.
    **kwargs : dict
        Parametrisation of the profiles and cosmology.

    Returns
    -------
    float or array_like : The halo reference radius in `Mpc`.
    """
    # Input handling
    M, a = np.atleast_1d(M, a)

    if is_matter:
        omega_factor = ccl.omega_x(cosmo, a, "matter")
    else:
        omega_factor = 1

    c1 = (cosmo["h"] * ccl.h_over_h0(cosmo, a))**2
    prefac = 1.16217766e12 * Delta * omega_factor * c1

    R = (M[..., None] / prefac)**(1 / 3)
    return R.squeeze() if squeeze else R
コード例 #9
0
ファイル: test_background.py プロジェクト: AntonVopilov/CCL
def test_background_omega_x(a, kind):
    val = ccl.omega_x(COSMO_NU, a, kind)
    assert np.all(np.isfinite(val))
    assert np.shape(val) == np.shape(a)

    if np.all(a == 1):
        if kind == 'matter':
            val_z0 = (COSMO_NU['Omega_b'] + COSMO_NU['Omega_c'] +
                      COSMO_NU['Omega_nu_mass'])
        elif kind == 'dark_energy':
            val_z0 = COSMO_NU['Omega_l']
        elif kind == 'radiation':
            val_z0 = COSMO_NU['Omega_g']
        elif kind == 'curvature':
            val_z0 = COSMO_NU['Omega_k']
        elif kind == 'neutrinos_rel':
            val_z0 = COSMO_NU['Omega_nu_rel']
        elif kind == 'neutrinos_massive':
            val_z0 = COSMO_NU['Omega_nu_mass']

        assert np.allclose(val, val_z0)
コード例 #10
0
def check_background(cosmo):
    """
    Check that background and growth functions can be run.
    """

    # Types of scale factor input (scalar, list, array)
    a_scl = 0.5
    is_comoving = 0
    a_lst = [0.2, 0.4, 0.6, 0.8, 1.]
    a_arr = np.linspace(0.2, 1., 5)

    # growth_factor
    assert_(all_finite(ccl.growth_factor(cosmo, a_scl)))
    assert_(all_finite(ccl.growth_factor(cosmo, a_lst)))
    assert_(all_finite(ccl.growth_factor(cosmo, a_arr)))

    # growth_factor_unnorm
    assert_(all_finite(ccl.growth_factor_unnorm(cosmo, a_scl)))
    assert_(all_finite(ccl.growth_factor_unnorm(cosmo, a_lst)))
    assert_(all_finite(ccl.growth_factor_unnorm(cosmo, a_arr)))

    # growth_rate
    assert_(all_finite(ccl.growth_rate(cosmo, a_scl)))
    assert_(all_finite(ccl.growth_rate(cosmo, a_lst)))
    assert_(all_finite(ccl.growth_rate(cosmo, a_arr)))

    # comoving_radial_distance
    assert_(all_finite(ccl.comoving_radial_distance(cosmo, a_scl)))
    assert_(all_finite(ccl.comoving_radial_distance(cosmo, a_lst)))
    assert_(all_finite(ccl.comoving_radial_distance(cosmo, a_arr)))

    # comoving_angular_distance
    assert_(all_finite(ccl.comoving_angular_distance(cosmo, a_scl)))
    assert_(all_finite(ccl.comoving_angular_distance(cosmo, a_lst)))
    assert_(all_finite(ccl.comoving_angular_distance(cosmo, a_arr)))

    # h_over_h0
    assert_(all_finite(ccl.h_over_h0(cosmo, a_scl)))
    assert_(all_finite(ccl.h_over_h0(cosmo, a_lst)))
    assert_(all_finite(ccl.h_over_h0(cosmo, a_arr)))

    # luminosity_distance
    assert_(all_finite(ccl.luminosity_distance(cosmo, a_scl)))
    assert_(all_finite(ccl.luminosity_distance(cosmo, a_lst)))
    assert_(all_finite(ccl.luminosity_distance(cosmo, a_arr)))

    # scale_factor_of_chi
    assert_(all_finite(ccl.scale_factor_of_chi(cosmo, a_scl)))
    assert_(all_finite(ccl.scale_factor_of_chi(cosmo, a_lst)))
    assert_(all_finite(ccl.scale_factor_of_chi(cosmo, a_arr)))

    # omega_m_a
    assert_(all_finite(ccl.omega_x(cosmo, a_scl, 'matter')))
    assert_(all_finite(ccl.omega_x(cosmo, a_lst, 'matter')))
    assert_(all_finite(ccl.omega_x(cosmo, a_arr, 'matter')))

    # Fractional density of different types of fluid
    assert_(all_finite(ccl.omega_x(cosmo, a_arr, 'dark_energy')))
    assert_(all_finite(ccl.omega_x(cosmo, a_arr, 'radiation')))
    assert_(all_finite(ccl.omega_x(cosmo, a_arr, 'curvature')))
    assert_(all_finite(ccl.omega_x(cosmo, a_arr, 'neutrinos_rel')))
    assert_(all_finite(ccl.omega_x(cosmo, a_arr, 'neutrinos_massive')))

    # Check that omega_x fails if invalid component type is passed
    assert_raises(ValueError, ccl.omega_x, cosmo, a_scl, 'xyz')

    # rho_crit_a
    assert_(all_finite(ccl.rho_x(cosmo, a_scl, 'critical', is_comoving)))
    assert_(all_finite(ccl.rho_x(cosmo, a_lst, 'critical', is_comoving)))
    assert_(all_finite(ccl.rho_x(cosmo, a_arr, 'critical', is_comoving)))

    # rho_m_a
    assert_(all_finite(ccl.rho_x(cosmo, a_scl, 'matter', is_comoving)))
    assert_(all_finite(ccl.rho_x(cosmo, a_lst, 'matter', is_comoving)))
    assert_(all_finite(ccl.rho_x(cosmo, a_arr, 'matter', is_comoving)))
コード例 #11
0
ファイル: test_background.py プロジェクト: AntonVopilov/CCL
def test_background_omega_x_raises():
    with pytest.raises(ValueError):
        ccl.omega_x(COSMO, 1, 'blah')
コード例 #12
0
 def get_Omega_m(self, z):
     return ccl.omega_x(self.be_cosmo, 1.0/(1.0+z), "matter")
コード例 #13
0
# plt.show()
plt.close()

# The ratio of the Hubble parameter at scale factor a to H0:
H_over_H0 = ccl.h_over_h0(cosmo, a)
plt.figure()
plt.plot(z, H_over_H0, 'k', linewidth=2)
plt.xlabel('$z$', fontsize=20)
plt.ylabel('$H / H_0$', fontsize=15)
plt.tick_params(labelsize=13)
# plt.show()
plt.close()

# For each component of the matter / energy budget, 
# we can get $\Omega_{\rm x}(z)$, the fractional energy density at $z \ne 0$.
OmM_z = ccl.omega_x(cosmo, a, 'matter')
OmL_z = ccl.omega_x(cosmo, a, 'dark_energy')
OmR_z = ccl.omega_x(cosmo, a, 'radiation')
OmK_z = ccl.omega_x(cosmo, a, 'curvature')
OmNuRel_z = ccl.omega_x(cosmo, a, 'neutrinos_rel')
OmNuMass_z = ccl.omega_x(cosmo, a, 'neutrinos_massive')

plt.figure()
plt.plot(z, OmM_z, 'k', linewidth=2, label='$\Omega_{\\rm M}(z)$')
plt.plot(z, OmL_z, 'g', linewidth=2, label='$\Omega_{\Lambda}(z)$')
plt.plot(z, OmR_z, 'b', linewidth=2, label='$\Omega_{\\rm R}(z)$')
plt.plot(z, OmNuRel_z, 'm', linewidth=2, label='$\Omega_{\\nu}^{\\rm rel}(z)$')
plt.xlabel('$z$',fontsize=20)
plt.ylabel('$\Omega_{\\rm x}(z)$', fontsize= 20)
plt.tick_params(labelsize=13)
plt.legend(loc='upper right')
コード例 #14
0
ファイル: plot_mf.py プロジェクト: nikfilippas/yxgxk
a = 1 / (1 + z)

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$"))
コード例 #15
0
ファイル: mk_mask_y.py プロジェクト: nikfilippas/yxgxk
           origin='lower',
           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
コード例 #16
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
コード例 #17
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()
コード例 #18
0
 def get_E2Omega_m(self, z):
     a = 1.0/(1.0+z)
     return ccl.omega_x(self.be_cosmo, a, "matter")*(ccl.h_over_h0(self.be_cosmo, a))**2
コード例 #19
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