Ejemplo n.º 1
0
def test_tkk1h_errors():
    from pyccl.pyutils import assert_warns

    hmc = ccl.halos.HMCalculator(COSMO, HMF, HBF, mass_def=M200)
    k_arr = KK
    a_arr = np.array([0.1, 0.4, 0.7, 1.0])

    # Wrong first profile
    with pytest.raises(TypeError):
        ccl.halos.halomod_trispectrum_1h(COSMO, hmc, k_arr, a_arr, None)
    # Wrong other profiles
    with pytest.raises(TypeError):
        ccl.halos.halomod_trispectrum_1h(COSMO,
                                         hmc,
                                         k_arr,
                                         a_arr,
                                         P1,
                                         prof2=PKC)
    with pytest.raises(TypeError):
        ccl.halos.halomod_trispectrum_1h(COSMO,
                                         hmc,
                                         k_arr,
                                         a_arr,
                                         P1,
                                         prof3=PKC)
    with pytest.raises(TypeError):
        ccl.halos.halomod_trispectrum_1h(COSMO,
                                         hmc,
                                         k_arr,
                                         a_arr,
                                         P1,
                                         prof4=PKC)
    # Wrong 2pts
    with pytest.raises(TypeError):
        ccl.halos.halomod_trispectrum_1h(COSMO,
                                         hmc,
                                         k_arr,
                                         a_arr,
                                         P1,
                                         prof12_2pt=P2)
    with pytest.raises(TypeError):
        ccl.halos.halomod_trispectrum_1h(COSMO,
                                         hmc,
                                         k_arr,
                                         a_arr,
                                         P1,
                                         prof34_2pt=P2)

    # Negative profile in logspace
    assert_warns(ccl.CCLWarning,
                 ccl.halos.halomod_Tk3D_1h,
                 COSMO,
                 hmc,
                 P3,
                 prof2=Pneg,
                 lk_arr=np.log(k_arr),
                 a_arr=a_arr,
                 use_log=True)
Ejemplo n.º 2
0
def test_halomodel_power_consistent():
    from pyccl.pyutils import assert_warns
    a = 0.8
    k = np.logspace(-1, 1, 10)
    # These are all deprecated.
    tot = assert_warns(ccl.CCLWarning, ccl.halomodel_matter_power, COSMO, k, a)
    one = assert_warns(ccl.CCLWarning, ccl.onehalo_matter_power, COSMO, k, a)
    two = assert_warns(ccl.CCLWarning, ccl.twohalo_matter_power, COSMO, k, a)

    assert np.allclose(one + two, tot)
Ejemplo n.º 3
0
def test_mu_sigma_matter_power_err(mp):
    from pyccl.pyutils import assert_warns
    with pytest.raises(ccl.CCLError):
        cosmo = ccl.Cosmology(Omega_c=0.25,
                              Omega_b=0.05,
                              h=0.7,
                              A_s=2.1e-9,
                              n_s=0.96,
                              mu_0=0.1,
                              sigma_0=0.2,
                              transfer_function=None,
                              matter_power_spectrum=mp)
        # Also raises a warning, so catch that.
        assert_warns(ccl.CCLWarning, ccl.nonlin_matter_power, cosmo, 1, 1)
Ejemplo n.º 4
0
def test_halomodel_choices_raises():
    from pyccl.pyutils import assert_warns
    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='tinker')
    a = 0.8
    k = np.geomspace(1E-2, 1, 10)

    with pytest.raises(ValueError):
        assert_warns(ccl.CCLWarning, ccl.twohalo_matter_power, cosmo, k, a)
Ejemplo n.º 5
0
def test_halomod_f2d_copy():
    from pyccl.pyutils import assert_warns
    mdef = ccl.halos.MassDef('vir', 'matter')
    hmf = ccl.halos.MassFuncSheth99(COSMO_HM,
                                    mdef,
                                    mass_def_strict=False,
                                    use_delta_c_fit=True)
    hbf = ccl.halos.HaloBiasSheth99(COSMO_HM,
                                    mass_def=mdef,
                                    mass_def_strict=False)
    cc = ccl.halos.ConcentrationDuffy08(mdef)
    prf = ccl.halos.HaloProfileNFW(cc)
    hmc = ccl.halos.HMCalculator(COSMO_HM, hmf, hbf, mdef)
    pk2d = ccl.halos.halomod_Pk2D(COSMO_HM, hmc, prf, normprof1=True)
    psp_new = pk2d.psp
    # This just triggers the internal calculation
    pk_old = assert_warns(ccl.CCLWarning, ccl.nonlin_matter_power, COSMO_HM,
                          1., 0.8)
    pk_new = pk2d.eval(1., 0.8, COSMO_HM)
    psp_old = COSMO_HM.get_nonlin_power().psp
    assert psp_new.lkmin == psp_old.lkmin
    assert psp_new.lkmax == psp_old.lkmax
    assert psp_new.amin == psp_old.amin
    assert psp_new.amax == psp_old.amax
    assert psp_new.is_factorizable == psp_old.is_factorizable
    assert psp_new.is_k_constant == psp_old.is_k_constant
    assert psp_new.is_a_constant == psp_old.is_a_constant
    assert psp_new.is_log == psp_old.is_log
    assert psp_new.growth_factor_0 == psp_old.growth_factor_0
    assert psp_new.growth_exponent == psp_old.growth_exponent
    assert psp_new.extrap_order_lok == psp_old.extrap_order_lok
    assert psp_new.extrap_order_hik == psp_old.extrap_order_hik
    assert pk_old == pk_new
Ejemplo n.º 6
0
def test_halo_concentration(m):
    from pyccl.pyutils import assert_warns
    a = 0.8
    # Deprecated.
    c = assert_warns(ccl.CCLWarning, ccl.halo_concentration, COSMO, m, a)
    assert np.all(np.isfinite(c))
    assert np.shape(c) == np.shape(m)
Ejemplo n.º 7
0
def test_massfunc_m2r_smoke(m):
    from pyccl.pyutils import assert_warns
    # Deprecated
    # TODO: switch to mass2radius_lagrangian
    r = assert_warns(ccl.CCLWarning, ccl.massfunc_m2r, COSMO, m)
    assert np.all(np.isfinite(r))
    assert np.shape(r) == np.shape(m)
Ejemplo n.º 8
0
def test_halo_bias_smoke(m):
    from pyccl.pyutils import assert_warns
    a = 0.8
    # Deprecated
    # TODO: switch to HaloBias
    b = assert_warns(ccl.CCLWarning, ccl.halo_bias, COSMO, m, a)
    assert np.all(np.isfinite(b))
    assert np.shape(b) == np.shape(m)
Ejemplo n.º 9
0
def test_tkkssc_linear_bias_smoke_and_errors():
    hmc = ccl.halos.HMCalculator(COSMO, HMF, HBF, mass_def=M200, nlog10M=2)
    k_arr = KK
    a_arr = np.array([0.3, 0.5, 0.7, 1.0])

    # Tk's exact version
    prof = ccl.halos.HaloProfileNFW(ccl.halos.ConcentrationDuffy08(M200),
                                    fourier_analytic=True)

    ccl.halos.halomod_Tk3D_SSC_linear_bias(COSMO,
                                           hmc,
                                           prof=prof,
                                           p_of_k_a='linear')

    ccl.halos.halomod_Tk3D_SSC_linear_bias(COSMO,
                                           hmc,
                                           prof=prof,
                                           p_of_k_a='nonlinear')

    pk = COSMO.get_nonlin_power()
    ccl.halos.halomod_Tk3D_SSC_linear_bias(COSMO, hmc, prof=prof, p_of_k_a=pk)

    # Error when prof is not NFW
    with pytest.raises(TypeError):
        ccl.halos.halomod_Tk3D_SSC_linear_bias(COSMO, hmc, prof=P2)

    # Error when p_of_k_a is wrong
    with pytest.raises(TypeError):
        ccl.halos.halomod_Tk3D_SSC_linear_bias(COSMO,
                                               hmc,
                                               prof=prof,
                                               p_of_k_a=P1)

    # Negative profile in logspace
    assert_warns(ccl.CCLWarning,
                 ccl.halos.halomod_Tk3D_SSC_linear_bias,
                 COSMO,
                 hmc,
                 prof,
                 bias1=-1,
                 lk_arr=np.log(k_arr),
                 a_arr=a_arr,
                 use_log=True)
Ejemplo n.º 10
0
def test_tkkssc_errors():

    hmc = ccl.halos.HMCalculator(COSMO, HMF, HBF, mass_def=M200)
    k_arr = KK
    a_arr = np.array([0.3, 0.5, 0.7, 1.0])

    # Wrong first profile
    with pytest.raises(TypeError):
        ccl.halos.halomod_Tk3D_SSC(COSMO, hmc, None)
    # Wrong other profiles
    for i in range(2, 4):
        kw = {'prof%d' % i: PKC}
        with pytest.raises(TypeError):
            ccl.halos.halomod_Tk3D_SSC(COSMO, hmc, P1, **kw)
    # Wrong 2pts
    with pytest.raises(TypeError):
        ccl.halos.halomod_Tk3D_SSC(COSMO, hmc, P1, prof12_2pt=P2)
    with pytest.raises(TypeError):
        ccl.halos.halomod_Tk3D_SSC(COSMO, hmc, P1, prof34_2pt=P2)

    # No normalization for number counts profile
    with pytest.raises(ValueError):
        ccl.halos.halomod_Tk3D_SSC(COSMO, hmc, P2, normprof1=False)
    with pytest.raises(ValueError):
        ccl.halos.halomod_Tk3D_SSC(COSMO, hmc, P1, prof2=P2, normprof2=False)
    with pytest.raises(ValueError):
        ccl.halos.halomod_Tk3D_SSC(COSMO, hmc, P1, prof3=P2, normprof3=False)
    with pytest.raises(ValueError):
        ccl.halos.halomod_Tk3D_SSC(COSMO, hmc, P1, prof4=P2, normprof4=False)

    # Negative profile in logspace
    assert_warns(ccl.CCLWarning,
                 ccl.halos.halomod_Tk3D_1h,
                 COSMO,
                 hmc,
                 P3,
                 prof2=Pneg,
                 lk_arr=np.log(k_arr),
                 a_arr=a_arr,
                 use_log=True)
Ejemplo n.º 11
0
def test_halomodel_power(k, kind):
    from pyccl.pyutils import assert_warns
    a = 0.8

    if kind == 'one':
        func = ccl.onehalo_matter_power
    elif kind == 'two':
        func = ccl.twohalo_matter_power
    else:
        func = ccl.halomodel_matter_power

    pk = assert_warns(ccl.CCLWarning, func, COSMO, k, a)
    assert np.all(np.isfinite(pk))
    assert np.shape(k) == np.shape(pk)
Ejemplo n.º 12
0
def test_haloprofile_smoke(func, r):
    from pyccl.pyutils import assert_warns
    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')
    a = 1
    c = 5
    mass = 1e14
    odelta = 200
    # These are all deprecated
    prof = assert_warns(
            ccl.CCLWarning,
            getattr(ccl, func), cosmo, c, mass, odelta, a, r)
    assert np.all(np.isfinite(prof))
    assert np.shape(prof) == np.shape(r)
Ejemplo n.º 13
0
def test_halo_bias_models_smoke(mf_type):
    from pyccl.pyutils import assert_warns
    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)
    hbf_cls = ccl.halos.halo_bias_from_name(MF_EQUIV[mf_type])
    hbf = hbf_cls(cosmo)
    for m in MS:
        # Deprecated
        bm_old = assert_warns(ccl.CCLWarning, ccl.halo_bias, cosmo, m, 1.)
        bm_new = hbf.get_halo_bias(cosmo, m, 1.)
        assert np.all(np.isfinite(bm_old))
        assert np.shape(bm_old) == np.shape(m)
        assert np.all(np.array(bm_old) == np.array(bm_new))
Ejemplo n.º 14
0
def test_correlation_newtypes(typs):
    from pyccl.pyutils import assert_warns
    z = np.linspace(0., 1., 200)
    n = np.ones(z.shape)
    lens = ccl.WeakLensingTracer(COSMO, dndz=(z, n))

    ell = np.logspace(1, 3, 5)
    cl = ccl.angular_cl(COSMO, lens, lens, ell)

    theta = np.logspace(-2., np.log10(5.), 5)
    corr_old = assert_warns(ccl.CCLWarning,
                            ccl.correlation,
                            COSMO,
                            ell,
                            cl,
                            theta,
                            corr_type=typs[0])
    corr_new = ccl.correlation(COSMO, ell, cl, theta, type=typs[1])
    assert np.all(corr_new == corr_old)
Ejemplo n.º 15
0
def test_halomodel_choices_smoke(mf_c):
    from pyccl.pyutils import assert_warns
    mf, c = mf_c
    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,
                          halo_concentration=c)
    a = 0.8
    k = np.geomspace(1E-2, 1, 10)
    # Deprecated
    # TODO: Convert this and other places to using the non-deprecated syntax
    # Or, since this wasn't already done, maybe this is a useful convenience
    # function?
    p = assert_warns(ccl.CCLWarning, ccl.twohalo_matter_power, cosmo, k, a)
    pb = get_pk_new(mf, c, cosmo, a, k, False, True)

    assert np.all(np.isfinite(p))
    assert np.allclose(p, pb)