Ejemplo n.º 1
0
def get_cl(dtype):
    config = get_config(dtype)
    cosmo_pars = config['cosmo']
    cosmo = ccl.Cosmology(**cosmo_pars)

    if config['dtype'] == 'generic':
        return np.ones(3 * config['nside'])

    if config['dtype'] == 'galaxy_density':
        z, nz = np.loadtxt('xcell/tests/data/DESY1gc_dndz_bin0.txt',
                           usecols=(1, 3),
                           unpack=True)
        b = np.ones_like(z)
        tracer = ccl.NumberCountsTracer(cosmo,
                                        dndz=(z, nz),
                                        bias=(z, b),
                                        has_rsd=None)
    elif config['dtype'] == 'galaxy_shear':
        z, nz = np.loadtxt('xcell/tests/data/Nz_DIR_z0.1t0.3.asc',
                           usecols=(0, 1),
                           unpack=True)
        tracer = ccl.WeakLensingTracer(cosmo, dndz=(z, nz))
    elif config['dtype'] == 'cmb_convergence':
        tracer = ccl.CMBLensingTracer(cosmo, z_source=1100)
    elif config['dtype'] == 'cmb_tSZ':
        tracer = ccl.tSZTracer(cosmo, z_max=3.)

    cl = ccl.angular_cl(cosmo, tracer, tracer, np.arange(3 * config['nside']))
    return cl
Ejemplo n.º 2
0
def test_clfid_halomod(tr1, tr2):
    data = get_config(dtype0=tr1, dtype1=tr2, inc_hm=True)

    cosmo = ccl.Cosmology(**data['cov']['fiducial']['cosmo'])
    md = ccl.halos.MassDef200m()
    mf = ccl.halos.MassFuncTinker10(cosmo, mass_def=md)
    hb = ccl.halos.HaloBiasTinker10(cosmo, mass_def=md)
    cm = ccl.halos.ConcentrationDuffy08(mdef=md)
    hmc = ccl.halos.HMCalculator(cosmo, mf, hb, md)
    pNFW = ccl.halos.HaloProfileNFW(cm)
    profs = {}
    ccltr = {}
    normed = {}
    for tr, lab in [(tr1, 'Dummy__0'), (tr2, 'Dummy__1')]:
        if tr == 'galaxy_density':
            data['tracers'][lab]['hod_params'] = {'lMmin_0': 12.1,
                                                  'lM1_p': 0.1,
                                                  'bg_0': 1.2}
            profs[tr] = ccl.halos.HaloProfileHOD(cm, lMmin_0=12.1,
                                                 lM1_p=0.1, bg_0=1.2)
            z, nz = np.loadtxt('xcell/tests/data/DESY1gc_dndz_bin0.txt',
                               usecols=(1, 3), unpack=True)
            ccltr[tr] = ccl.NumberCountsTracer(cosmo, False, dndz=(z, nz),
                                               bias=(z, np.ones_like(z)))
            normed[tr] = True
        elif tr == 'cmb_tSZ':
            data['tracers'][lab]['gnfw_params'] = {'mass_bias': 0.9}
            profs[tr] = ccl.halos.HaloProfilePressureGNFW(mass_bias=0.9)
            ccltr[tr] = ccl.tSZTracer(cosmo, z_max=3.)
            normed[tr] = False
        elif tr == 'galaxy_shear':
            profs[tr] = pNFW
            z, nz = np.loadtxt('xcell/tests/data/Nz_DIR_z0.1t0.3.asc',
                               usecols=(0, 1), unpack=True)
            ccltr[tr] = ccl.WeakLensingTracer(cosmo, dndz=(z, nz))
            normed[tr] = True
        elif tr == 'cmb_convergence':
            profs[tr] = pNFW
            ccltr[tr] = ccl.CMBLensingTracer(cosmo, z_source=1100.)
            normed[tr] = True

    clf = ClFid(data, 'Dummy__0', 'Dummy__1')
    d = clf.get_cl_file()
    shutil.rmtree(tmpdir1)

    k_arr = np.geomspace(1E-4, 1E2, 512)
    a_arr = 1./(1+np.linspace(0, 3, 15)[::-1])
    pk = ccl.halos.halomod_Pk2D(cosmo, hmc, profs[tr1],
                                prof2=profs[tr2],
                                normprof1=normed[tr1],
                                normprof2=normed[tr2],
                                lk_arr=np.log(k_arr),
                                a_arr=a_arr)
    # Commented out until these features are pushed to the pip release of CCL
    # smooth_transition=(lambda a: 0.7),
    # supress_1h=(lambda a: 0.01))
    clb = ccl.angular_cl(cosmo, ccltr[tr1], ccltr[tr2], d['ell'], p_of_k_a=pk)

    assert np.all(np.fabs(clb[2:]/d['cl'][0][2:]-1) < 1E-4)
Ejemplo n.º 3
0
 def update_tracer(self, cosmo, **kwargs):
     if self.type == 'g':
         nz_new = self.nzf(self.z_avg +
                           (self.z - self.z_avg) / kwargs['width'])
         nz_new /= simps(nz_new, x=self.z)
         self.tracer = ccl.NumberCountsTracer(cosmo,
                                              has_rsd=False,
                                              dndz=(self.z, nz_new),
                                              bias=(self.z, self.bz))
     elif self.type == 'y':
         self.tracer = ccl.tSZTracer(cosmo)
     elif self.type == 'k':
         self.tracer = ccl.CMBLensingTracer(cosmo, z_source=1100.)
Ejemplo n.º 4
0
    def _get_cl_ccl(self, dtype):
        ls = np.arange(3 * self.nside)
        if dtype == 'galaxy_density':
            z, nz = self.get_nz()
            b = np.ones_like(z)
            tracer = ccl.NumberCountsTracer(self.cosmo, has_rsd=False,
                                            dndz=(z, nz), bias=(z, b))
        elif dtype == 'galaxy_shear':
            z, nz = self.get_nz()
            tracer = ccl.WeakLensingTracer(self.cosmo, dndz=(z, nz))
        elif dtype == 'cmb_convergence':
            tracer = ccl.CMBLensingTracer(self.cosmo, z_source=1100)
        elif dtype == 'cmb_tSZ':
            # Note that the tSZ power spectrum implemented here is wrong
            # But it's not worth for now adding all the halo model stuff.
            tracer = ccl.tSZTracer(self.cosmo, z_max=3.)

        return ccl.angular_cl(self.cosmo, tracer, tracer, ls)
Ejemplo n.º 5
0
def test_szcl():
    fsky = 1.
    COSMO = ccl.Cosmology(Omega_b=0.05,
                          Omega_c=0.25,
                          h=0.7,
                          n_s=0.9645,
                          A_s=2.02E-9,
                          Neff=3.046,
                          transfer_function='boltzmann_class')
    bm = np.loadtxt("benchmarks/data/sz_cl_P13_szpowerspectrum.txt",
                    unpack=True)
    l_bm = bm[0]
    cl_bm = bm[1]
    tll_bm = np.loadtxt("benchmarks/data/tSZ_trispectrum_ref_for_cobaya.txt")
    fac = 2 * np.pi / (l_bm * (l_bm + 1) * 1E12)

    cl_bm *= fac
    tll_bm *= fac[:, None] * fac[None, :] / (4 * np.pi * fsky)
    mass_def = ccl.halos.MassDef(500, 'critical')
    hmf = ccl.halos.MassFuncTinker08(COSMO, mass_def=mass_def)
    hbf = ccl.halos.HaloBiasTinker10(COSMO, mass_def=mass_def)
    hmc = ccl.halos.HMCalculator(COSMO, hmf, hbf, mass_def)
    prf = ccl.halos.HaloProfilePressureGNFW()
    prf.update_parameters(mass_bias=1. / 1.41, x_out=6.)
    tr = ccl.tSZTracer(COSMO, z_max=3.)

    # Power spectrum
    pk = ccl.halos.halomod_Pk2D(COSMO, hmc, prf, get_2h=False)
    cl = ccl.angular_cl(COSMO, tr, tr, l_bm, p_of_k_a=pk)

    # Covariance
    lk_arr = np.log(np.geomspace(1E-4, 1E2, 256))
    a_arr = 1. / (1 + np.linspace(0, 3., 20))[::-1]
    tkk = ccl.halos.halomod_Tk3D_1h(COSMO,
                                    hmc,
                                    prf,
                                    lk_arr=lk_arr,
                                    a_arr=a_arr,
                                    use_log=True)
    tll = ccl.angular_cl_cov_cNG(COSMO, tr, tr, l_bm, tkk, fsky=fsky)

    assert np.all(np.fabs(cl / cl_bm - 1) < 2E-2)
    assert np.all(np.fabs(tll / tll_bm - 1) < 5E-2)
Ejemplo n.º 6
0
def test_szcl():
    COSMO = ccl.Cosmology(Omega_b=0.05,
                          Omega_c=0.25,
                          h=0.67,
                          n_s=0.9645,
                          A_s=2.02E-9,
                          Neff=3.046)
    bm = np.loadtxt("benchmarks/data/sz_cl_P13_szpowerspectrum.txt",
                    unpack=True)
    l_bm = bm[0]
    cl_bm = bm[1]
    cl_bm *= (2 * np.pi) / (1E12 * l_bm * (l_bm + 1))
    mass_def = ccl.halos.MassDef(500, 'critical')
    hmf = ccl.halos.MassFuncTinker08(COSMO, mass_def=mass_def)
    hbf = ccl.halos.HaloBiasTinker10(COSMO, mass_def=mass_def)
    hmc = ccl.halos.HMCalculator(COSMO, hmf, hbf, mass_def)
    prf = ccl.halos.HaloProfilePressureGNFW(mass_bias=1. / 1.41)
    pk = ccl.halos.halomod_Pk2D(COSMO, hmc, prf, get_2h=False)
    tr = ccl.tSZTracer(COSMO, z_max=4.)
    cl = ccl.angular_cl(COSMO, tr, tr, l_bm, p_of_k_a=pk)

    assert np.all(np.fabs(cl / cl_bm - 1) < 2E-2)
Ejemplo n.º 7
0
def test_clfid_halomod_M500c():
    tr1 = 'cmb_tSZ'
    tr2 = 'cmb_convergence'
    data = get_config(dtype0=tr1, dtype1=tr2, inc_hm=True)
    data['cov']['fiducial']['halo_model'] = {'mass_def': '500c',
                                             'concentration': 'Duffy08M500c'}
    data['tracers']['Dummy__0']['gnfw_params'] = {'mass_bias': 0.9}

    cosmo = ccl.Cosmology(**data['cov']['fiducial']['cosmo'])
    md = ccl.halos.MassDef(500, 'critical')
    mf = ccl.halos.MassFuncTinker10(cosmo, mass_def=md)
    hb = ccl.halos.HaloBiasTinker10(cosmo, mass_def=md)
    cm = ConcentrationDuffy08M500c(mdef=md)
    hmc = ccl.halos.HMCalculator(cosmo, mf, hb, md)
    prof1 = ccl.halos.HaloProfilePressureGNFW(mass_bias=0.9)
    ccltr1 = ccl.tSZTracer(cosmo, z_max=3.)
    prof2 = ccl.halos.HaloProfileNFW(cm)
    ccltr2 = ccl.CMBLensingTracer(cosmo, z_source=1100.)

    clf = ClFid(data, 'Dummy__0', 'Dummy__1')
    d = clf.get_cl_file()
    shutil.rmtree(tmpdir1)

    k_arr = np.geomspace(1E-4, 1E2, 512)
    a_arr = 1./(1+np.linspace(0, 6., 30)[::-1])
    pk = ccl.halos.halomod_Pk2D(cosmo, hmc, prof1,
                                prof2=prof2,
                                normprof1=False,
                                normprof2=True,
                                lk_arr=np.log(k_arr),
                                a_arr=a_arr)
    # Commented out until these features are pushed to the pip release of CCL
    # smooth_transition=(lambda a: 0.7),
    # supress_1h=(lambda a: 0.01))
    clb = ccl.angular_cl(cosmo, ccltr1, ccltr2, d['ell'], p_of_k_a=pk)

    assert np.all(np.fabs(clb[2:]/d['cl'][0][2:]-1) < 1E-4)
Ejemplo n.º 8
0
    def compute_tracer_ccl(self, name, tracer, mapper):
        cosmo = self.get_cosmo_ccl()
        hm_par = self.get_halomodel_params()

        dtype = mapper.get_dtype()
        ccl_pr = hm_par['prof_NFW']
        ccl_pr_2pt = hm_par['prof_2pt']
        with_hm = tracer.get('use_halo_model', False)
        normed_profile = True
        # Get Tracers
        if dtype == 'galaxy_density':
            # Import z, pz
            z, pz = mapper.get_nz(dz=0)
            bias = (z, np.ones_like(z))
            mag_bias = None
            mag_s = tracer.get('magnif_s', None)
            if mag_s:
                mag_bias = (z, np.ones_like(z) * mag_s)
            # Get tracer
            ccl_tr = ccl.NumberCountsTracer(cosmo,
                                            has_rsd=False,
                                            dndz=(z, pz),
                                            bias=bias,
                                            mag_bias=mag_bias)
            if with_hm:
                hod_pars = tracer.get('hod_params', {})
                ccl_pr = ccl.halos.HaloProfileHOD(hm_par['cM'], **hod_pars)
                ccl_pr_2pt = ccl.halos.Profile2ptHOD()
        elif dtype == 'galaxy_shear':
            # Import z, pz
            z, pz = mapper.get_nz(dz=0)
            # # Calculate bias IA
            ia_bias = None
            if self.config['wl_ia']:
                # TODO: Improve this in yml file
                A, eta, z0 = self.config['wl_ia']
                # pyccl2 -> has already the factor inside. Only needed bz
                bz = A * ((1. + z) / (1. + z0))**eta * 0.0139 / 0.013872474
                ia_bias = (z, bz)
            # Get tracer
            ccl_tr = ccl.WeakLensingTracer(cosmo,
                                           dndz=(z, pz),
                                           ia_bias=ia_bias)
        elif dtype == 'cmb_convergence':
            # TODO: correct z_source
            ccl_tr = ccl.CMBLensingTracer(cosmo, z_source=1100)
        elif dtype == 'cmb_tSZ':
            normed_profile = False
            ccl_tr = ccl.tSZTracer(cosmo, z_max=3.)
            if with_hm:
                pars = tracer.get('gnfw_params', {})
                ccl_pr = ccl.halos.HaloProfilePressureGNFW(**pars)
        else:
            raise ValueError('Type of tracer not recognized. It can be \
                             galaxy_density, galaxy_shear, cmb_tSZ, or \
                             cmb_convergence!')
        return {
            'name': name,
            'ccl_tr': ccl_tr,
            'ccl_pr': ccl_pr,
            'ccl_pr_2pt': ccl_pr_2pt,
            'with_hm': with_hm,
            'normed': normed_profile
        }