Exemple #1
0
def test_mgrowth():
    """
    Compare the modified growth function computed by CCL against the exact 
    result for a particular modification of the growth rate.
    """
    # Define differential growth rate arrays
    nz_mg = 128
    z_mg = np.zeros(nz_mg)
    df_mg = np.zeros(nz_mg)
    for i in range(0, nz_mg):
        z_mg[i] = 4. * (i + 0.0) / (nz_mg - 1.)
        df_mg[i] = 0.1 / (1. + z_mg[i])

    # Define two test cosmologies, without and with modified growth respectively
    p1 = ccl.Parameters(Omega_c=0.25,
                        Omega_b=0.05,
                        Omega_k=0.,
                        N_nu_rel=0.,
                        N_nu_mass=0.,
                        m_nu=0.,
                        w0=-1.,
                        wa=0.,
                        h=0.7,
                        A_s=2.1e-9,
                        n_s=0.96)
    p2 = ccl.Parameters(Omega_c=0.25,
                        Omega_b=0.05,
                        Omega_k=0.,
                        N_nu_rel=0.,
                        N_nu_mass=0.,
                        m_nu=0.,
                        w0=-1.,
                        wa=0.,
                        h=0.7,
                        A_s=2.1e-9,
                        n_s=0.96,
                        z_mg=z_mg,
                        df_mg=df_mg)
    cosmo1 = ccl.Cosmology(p1)
    cosmo2 = ccl.Cosmology(p2)

    # We have included a growth modification \delta f = K*a, with K==0.1
    # (arbitrarily). This case has an analytic solution, given by
    # D(a) = D_0(a)*exp(K*(a-1)). Here we compare the growth computed by CCL
    # with the analytic solution.
    a = 1. / (1. + z_mg)

    d1 = ccl.growth_factor(cosmo1, a)
    d2 = ccl.growth_factor(cosmo2, a)
    f1 = ccl.growth_rate(cosmo1, a)
    f2 = ccl.growth_rate(cosmo2, a)

    f2r = f1 + 0.1 * a
    d2r = d1 * np.exp(0.1 * (a - 1.))

    # Check that ratio of calculated and analytic results is within tolerance
    assert_allclose(d2r / d2, np.ones(d2.size), rtol=GROWTH_TOLERANCE)
    assert_allclose(f2r / f2, np.ones(f2.size), rtol=GROWTH_TOLERANCE)
Exemple #2
0
    def get_cosmo(self, dic_par):
        omega_c = dic_par['omega_c']
        omega_b = dic_par['omega_b']
        omega_k = dic_par['omega_k']
        omega_nu = dic_par['omega_nu']
        if 'w' in dic_par:
            w = dic_par['w']
        else:
            w = -1.
        if 'wa' in dic_par:
            wa = dic_par['wa']
        else:
            wa = 0.
        h0 = dic_par['h0']
        has_sigma8 = ('sigma_8' in dic_par)
        has_A_s = ('A_s' in dic_par)
        n_s = dic_par['n_s']
        if has_sigma8 and has_A_s:
            raise ValueError("Specifying both sigma8 and A_s: pick one")
        elif has_sigma8:
            sigma8 = dic_par['sigma_8']
            params = ccl.Parameters(Omega_c=omega_c,
                                    Omega_b=omega_b,
                                    Omega_k=omega_k,
                                    Omega_n=omega_nu,
                                    w0=w,
                                    wa=wa,
                                    sigma8=sigma8,
                                    n_s=n_s,
                                    h=h0)
        elif has_A_s:
            A_s = dic_par['A_s']
            params = ccl.Parameters(Omega_c=omega_c,
                                    Omega_b=omega_b,
                                    Omega_k=omega_k,
                                    Omega_n=omega_nu,
                                    w0=w,
                                    wa=wa,
                                    A_s=A_s,
                                    n_s=n_s,
                                    h=h0)
        else:
            raise ValueError("Need either sigma 8 or A_s in pyccl.")

        cosmo = ccl.Cosmology(
            params,
            transfer_function=dic_par['transfer_function'],
            matter_power_spectrum=dic_par['matter_power_spectrum'])

        return cosmo
def reference_models():
    """
    Create a set of reference Cosmology() objects.
    """
    # Standard LCDM model
    p1 = ccl.Parameters(Omega_c=0.27,
                        Omega_b=0.045,
                        h=0.67,
                        A_s=1e-10,
                        n_s=0.96)
    cosmo1 = ccl.Cosmology(p1)

    # LCDM model with curvature
    p2 = ccl.Parameters(Omega_c=0.27,
                        Omega_b=0.045,
                        h=0.67,
                        A_s=1e-10,
                        n_s=0.96,
                        Omega_k=0.05)
    cosmo2 = ccl.Cosmology(p2)

    # wCDM model
    p3 = ccl.Parameters(Omega_c=0.27,
                        Omega_b=0.045,
                        h=0.67,
                        A_s=1e-10,
                        n_s=0.96,
                        w0=-0.95,
                        wa=0.05)
    cosmo3 = ccl.Cosmology(p3)

    # BBKS Pk
    p4 = ccl.Parameters(Omega_c=0.27,
                        Omega_b=0.045,
                        h=0.67,
                        sigma8=0.8,
                        n_s=0.96)
    cosmo4 = ccl.Cosmology(p4, transfer_function='bbks')

    # E&H Pk
    p5 = ccl.Parameters(Omega_c=0.27,
                        Omega_b=0.045,
                        h=0.67,
                        sigma8=0.8,
                        n_s=0.96)
    cosmo5 = ccl.Cosmology(p5, transfer_function='eisenstein_hu')

    # Return (only do one cosmology for now, for speed reasons)
    return [cosmo1, cosmo4, cosmo5]  # cosmo2, cosmo3
Exemple #4
0
def compare_distances_mnu_hiz(z, chi_bench,dm_bench, Omega_v, w0, wa, Neff_mnu, mnu):
    """
    Compare distances calculated by pyccl with the distances in the benchmark 
    file.
    """
    # Set Omega_K in a consistent way
    Omega_k = 1.0 - Omega_c - Omega_b - Omega_v    
    
    # Create new Parameters and Cosmology objects
    p = ccl.Parameters(Omega_c=Omega_c, Omega_b=Omega_b, Neff=Neff, 
                       h=h, A_s=A_s, n_s=n_s, Omega_k=Omega_k,
                       w0=w0, wa=wa, m_nu=mnu)
    cosmo = ccl.Cosmology(p)
    
    # Calculate distance using pyccl
    a = 1. / (1. + z)
    chi = ccl.comoving_radial_distance(cosmo, a)
    # Compare to benchmark data
    assert_allclose(chi, chi_bench, atol=1e-12, rtol=DISTANCES_TOLERANCE_MNU)

    #compare distance moudli where a!=1
    a_not_one = (a!=1).nonzero()
    dm = ccl.distance_modulus(cosmo,a[a_not_one])

    assert_allclose(dm, dm_bench[a_not_one], atol=1e-3, rtol = DISTANCES_TOLERANCE_MNU)
Exemple #5
0
def compare_distances(z, chi_bench, Omega_v, w0, wa):
    """
    Compare distances calculated by pyccl with the distances in the benchmark 
    file.
    """
    # Set Omega_K in a consistent way
    Omega_k = 1.0 - Omega_c - Omega_b - Omega_n - Omega_v

    # Create new Parameters and Cosmology objects
    p = ccl.Parameters(Omega_c=Omega_c,
                       Omega_b=Omega_b,
                       Omega_n=Omega_n,
                       h=h,
                       A_s=A_s,
                       n_s=n_s,
                       Omega_k=Omega_k,
                       w0=w0,
                       wa=wa)
    p.parameters.Omega_g = 0.  # Hack to set to same value used for benchmarks
    cosmo = ccl.Cosmology(p)

    # Calculate distance using pyccl
    a = 1. / (1. + z)
    chi = ccl.comoving_radial_distance(cosmo, a) * h

    # Compare to benchmark data
    assert_allclose(chi, chi_bench, atol=1e-12, rtol=DISTANCES_TOLERANCE)
Exemple #6
0
def test_cosmology_init():
    """
    Check that Cosmology objects can only be constructed in a valid way.
    """
    # Create test cosmology object
    params = ccl.Parameters(Omega_c=0.25, Omega_b=0.05, h=0.7, A_s=2.1e-9, 
                            n_s=0.96)
    
    # Make sure error raised if incorrect type of Parameters object passed
    assert_raises(TypeError, ccl.Cosmology, params=params.parameters)
    assert_raises(TypeError, ccl.Cosmology, params="x")
    
    # Make sure error raised if wrong config type passed
    assert_raises(TypeError, ccl.Cosmology, params=params, config="string")
    
    # Make sure error raised if invalid transfer/power spectrum etc. type passed
    assert_raises(KeyError, ccl.Cosmology, params=params, 
                  matter_power_spectrum='x')
    assert_raises(KeyError, ccl.Cosmology, params=params, 
                  transfer_function='x')
    assert_raises(KeyError, ccl.Cosmology, params=params, 
                  baryons_power_spectrum='x')
    assert_raises(KeyError, ccl.Cosmology, params=params, 
                  mass_function='x')
    assert_raises(KeyError, ccl.Cosmology, params=params, 
                  halo_concentration='x')
Exemple #7
0
def compare_distances(z, chi_bench,dm_bench, Omega_v, w0, wa):
    """
    Compare distances calculated by pyccl with the distances in the benchmark 
    file.
    This test is only valid when radiation is explicitly set to 0.
    """
    # Set Omega_K in a consistent way
    Omega_k = 1.0 - Omega_c - Omega_b - Omega_v    
    
    # Create new Parameters and Cosmology objects
    p = ccl.Parameters(Omega_c=Omega_c, Omega_b=Omega_b, Neff = Neff, 
                       h=h, A_s=A_s, n_s=n_s, Omega_k=Omega_k,
                       w0=w0, wa=wa)
    p.parameters.Omega_g = 0. # Hack to set to same value used for benchmarks
    cosmo = ccl.Cosmology(p)
    
    # Calculate distance using pyccl
    a = 1. / (1. + z)
    chi = ccl.comoving_radial_distance(cosmo, a) * h
    # Compare to benchmark data
    assert_allclose(chi, chi_bench, atol=1e-12, rtol=DISTANCES_TOLERANCE)

    #compare distance moudli where a!=1
    a_not_one = (a!=1).nonzero()
    dm = ccl.distance_modulus(cosmo,a[a_not_one])

    assert_allclose(dm, dm_bench[a_not_one], atol=1e-3, rtol = DISTANCES_TOLERANCE*10)
Exemple #8
0
def main(dic_par):

    cosmo = ccl.Cosmology(
        ccl.Parameters(
            Omega_c=dic_par['omega_c'],
            Omega_b=dic_par['omega_b'],
            h=dic_par['h0'],
            sigma8=dic_par['sigma_8'],
            n_s=dic_par['n_s'],
        ),
        transfer_function=dic_par['transfer_function'],
        matter_power_spectrum=dic_par['matter_power_spectrum'])
    tracers, cltracers = getTracers(cosmo, dic_par)
    binning = getBinning(tracers)
    binning_sacc = sacc.SACC(tracers, binning)
    theories = getTheories(cosmo, binning_sacc, cltracers)
    mean = getTheoryVec(binning_sacc, theories)
    precision, covmatrix = getPrecisionMatrix(binning_sacc, theories)
    chol = la.cholesky(covmatrix)
    csacc = sacc.SACC(tracers, binning, mean, precision)
    csacc.printInfo()
    ## generate mean sim
    generate_sim("sims/sim_mean.sacc",
                 csacc,
                 add_random=False,
                 store_precision=True,
                 cholesky=chol)
    #Generate file containing only noiseless realization and precision matrix
    nsim = 10
    for i in np.arange(nsim):
        generate_sim("sims/sim_%03d.sacc" % i, csacc, cholesky=chol)
Exemple #9
0
def compare_growth(z, gfac_bench, Omega_v, w0, wa):
    """
    Compare growth factor calculated by pyccl with the values in the benchmark 
    file. This test only works if radiation is explicitly set to 0.
    """

    # Set Omega_K in a consistent way
    Omega_k = 1.0 - Omega_c - Omega_b - Omega_v

    # Create new Parameters and Cosmology objects

    p = ccl.Parameters(Omega_c=Omega_c,
                       Omega_b=Omega_b,
                       Neff=Neff,
                       m_nu=m_nu,
                       h=h,
                       A_s=A_s,
                       n_s=n_s,
                       Omega_k=Omega_k,
                       w0=w0,
                       wa=wa)

    p.parameters.Omega_g = 0.  # Hack to set to same value used for benchmarks
    cosmo = ccl.Cosmology(p)

    # Calculate distance using pyccl
    a = 1. / (1. + z)
    gfac = ccl.growth_factor_unnorm(cosmo, a)

    # Compare to benchmark data
    assert_allclose(gfac, gfac_bench, atol=1e-12, rtol=GROWTH_TOLERANCE)
Exemple #10
0
def test_parameters_set():
    """
    Check that Parameters object allows parameters to be set in a sensible way.
    """
    params = ccl.Parameters(Omega_c=0.25,
                            Omega_b=0.05,
                            h=0.7,
                            A_s=2.1e-9,
                            n_s=0.96)

    # Check that values of sigma8 and A_s won't be misinterpreted by the C code
    assert_raises(ValueError,
                  ccl.Parameters,
                  Omega_c=0.25,
                  Omega_b=0.05,
                  h=0.7,
                  A_s=2e-5,
                  n_s=0.96)
    assert_raises(ValueError,
                  ccl.Parameters,
                  Omega_c=0.25,
                  Omega_b=0.05,
                  h=0.7,
                  sigma8=9e-6,
                  n_s=0.96)

    # Check that error is raised when unrecognized parameter requested
    assert_raises(KeyError, lambda: params['wibble'])
Exemple #11
0
def reference_models_nu():
    """
    Create a set of reference cosmological models with massive neutrinos.
    This is separate because certain functionality is not yes implemented
    for massive neutrino cosmologies so will throw errors. 
    """

    # Emulator Pk w/neutrinos list
    p1 = ccl.Parameters(Omega_c=0.27,
                        Omega_b=0.022 / 0.67**2,
                        h=0.67,
                        sigma8=0.8,
                        n_s=0.96,
                        Neff=3.04,
                        m_nu=[0.02, 0.02, 0.02])
    cosmo1 = ccl.Cosmology(p1,
                           transfer_function='emulator',
                           matter_power_spectrum='emu')

    # Emulator Pk with neutrinos, force equalize
    #p2 = ccl.Parameters(Omega_c=0.27, Omega_b=0.022/0.67**2, h=0.67, sigma8=0.8,
    #                    n_s=0.96, Neff=3.04, m_nu=0.11)
    #cosmo2 = ccl.Cosmology(p1, transfer_function='emulator',
    #                       matter_power_spectrum='emu', emulator_neutrinos='equalize')

    return [cosmo1]
Exemple #12
0
def calc(zs, Om, w=None):
    if w == None:
        p6 = ccl.Parameters(Omega_c=Om - 0.05,
                            Omega_b=0.05,
                            h=0.7,
                            sigma8=0.9,
                            n_s=0.96)
    else:
        p6 = ccl.Parameters(Omega_c=Om - 0.05,
                            Omega_b=0.05,
                            h=0.7,
                            sigma8=0.9,
                            n_s=0.96,
                            w0=w)
    cosmo = ccl.Cosmology(p6)

    sfs = 1. / (1 + zs)
    return ccl.background.growth_factor(cosmo, sfs)
Exemple #13
0
    def get_cosmo(self, dic_par):
        Omega_c = dic_par.get('Omega_c', 0.255)
        Omega_b = dic_par.get('Omega_b', 0.045)
        Omega_k = dic_par.get('Omega_k', 0.0)
        mnu = dic_par.get('mnu', 0.06)
        w = dic_par.get('w', -1.0)
        wa = dic_par.get('wa', 0.0)
        h0 = dic_par.get('h0', 0.67)
        n_s = dic_par.get('n_s', 0.96)
        has_sigma8 = ('sigma_8' in dic_par)
        has_A_s = ('A_s' in dic_par)
        if has_sigma8 and has_A_s:
            raise ValueError("Specifying both sigma8 and A_s: pick one")
        elif has_A_s:
            A_s = dic_par['A_s']
            params = ccl.Parameters(Omega_c=Omega_c,
                                    Omega_b=Omega_b,
                                    Omega_k=Omega_k,
                                    w0=w,
                                    wa=wa,
                                    A_s=A_s,
                                    n_s=n_s,
                                    h=h0)

        else:
            sigma8 = dic_par.get('sigma_8', 0.8)
            params = ccl.Parameters(Omega_c=Omega_c,
                                    Omega_b=Omega_b,
                                    Omega_k=Omega_k,
                                    w0=w,
                                    wa=wa,
                                    sigma8=sigma8,
                                    n_s=n_s,
                                    h=h0)

        transfer_function = dic_par.get('transfer_function', 'boltzmann_class')
        matter_power_spectrum = dic_par.get('matter_power_spectrum', 'halofit')
        cosmo = ccl.Cosmology(
            params,
            transfer_function=dic_par['transfer_function'],
            matter_power_spectrum=dic_par['matter_power_spectrum'])
        return cosmo
def reference_models():
    """
    Create a set of reference Cosmology() objects.
    """
    # Standard LCDM model
    p1 = ccl.Parameters(Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10, n_s=0.96)
    cosmo1 = ccl.Cosmology(p1)
    
    # LCDM model with curvature
    p2 = ccl.Parameters(Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10, 
                        n_s=0.96, Omega_k=0.05)
    cosmo2 = ccl.Cosmology(p2)
    
    # wCDM model
    p3 = ccl.Parameters(Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10, 
                        n_s=0.96, w0=-0.95, wa=0.05)
    cosmo3 = ccl.Cosmology(p3)

    # BBKS Pk
    p4 = ccl.Parameters(Omega_c=0.27, Omega_b=0.045, h=0.67, sigma8=0.8, n_s=0.96)
    cosmo4 = ccl.Cosmology(p4, transfer_function='bbks')

    # E&H Pk
    p5 = ccl.Parameters(Omega_c=0.27, Omega_b=0.045, h=0.67, sigma8=0.8, n_s=0.96)
    cosmo5 = ccl.Cosmology(p5, transfer_function='eisenstein_hu')

    # Emulator Pk
    p6 = ccl.Parameters(Omega_c=0.27, Omega_b=0.022/0.67**2, h=0.67, sigma8=0.8, 
                        n_s=0.96, Neff=3.04, m_nu=0.)
    cosmo6 = ccl.Cosmology(p6, transfer_function='emulator', 
                           matter_power_spectrum='emu')

    # Baryons Pk
    p8 = ccl.Parameters(Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10, n_s=0.96)
    cosmo8 = ccl.Cosmology(p8, baryons_power_spectrum='bcm')
    
    # Baryons Pk with choice of BCM parameters other than default
    p9 = ccl.Parameters(Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10, n_s=0.96,
                        bcm_log10Mc=math.log10(1.7e14), bcm_etab=0.3, bcm_ks=75.)
    cosmo9 = ccl.Cosmology(p9, baryons_power_spectrum='bcm')
    
    # Emulator Pk w/neutrinos force equalize
    #p10 = ccl.Parameters(Omega_c=0.27, Omega_b=0.022/0.67**2, h=0.67, sigma8=0.8, 
    #                    n_s=0.96, Neff=3.04, m_nu=[0.02, 0.02, 0.02])
    #cosmo10 = ccl.Cosmology(p7, transfer_function='emulator', 
    #                       matter_power_spectrum='emu', emulator_neutrinos='equalize')

    # Return (do a few cosmologies, for speed reasons)
    return [cosmo1, cosmo4, cosmo5, cosmo9] # cosmo2, cosmo3, cosmo6
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)
Exemple #16
0
def compare_class_distances(z, chi_bench, Neff=3.0, m_nu=0.0, Omega_k=0.0):
    """
    Compare distances calculated by pyccl with the distances in the CLASS 
    benchmark file.
    """
    # Create new Parameters and Cosmology objects
    p = ccl.Parameters(Omega_c=Omega_c,
                       Omega_b=Omega_b,
                       Neff=Neff,
                       h=h,
                       A_s=A_s,
                       n_s=n_s,
                       Omega_k=Omega_k,
                       m_nu=m_nu)
    cosmo = ccl.Cosmology(p)

    # Calculate distance using pyccl
    a = 1. / (1. + z)
    chi = ccl.comoving_radial_distance(cosmo, a)
    # Compare to benchmark data
    assert_allclose(chi, chi_bench, rtol=DISTANCES_TOLERANCE_CLASS)
Exemple #17
0
def compare_class_distances(z, chi_bench, dm_bench, Neff=3.0, m_nu=0.0, 
                            Omega_k=0.0, w0=-1.0, wa=0.0):
    """
    Compare distances calculated by pyccl with the distances in the CLASS 
    benchmark file.
    """
    # Create new Parameters and Cosmology objects
    p = ccl.Parameters(Omega_c=Omega_c, Omega_b=Omega_b, Neff=Neff, 
                       h=h, A_s=A_s, n_s=n_s, Omega_k=Omega_k, m_nu=m_nu,
                       w0=w0, wa=wa)
    cosmo = ccl.Cosmology(p)
    
    # Calculate distance using pyccl
    a = 1. / (1. + z)
    chi = ccl.comoving_radial_distance(cosmo, a)
    # Compare to benchmark data
    assert_allclose(chi, chi_bench, rtol=DISTANCES_TOLERANCE_CLASS)

    # Compare distance moudli where a!=1
    a_not_one = a != 1
    dm = ccl.distance_modulus(cosmo, a[a_not_one])
    assert_allclose(dm, dm_bench[a_not_one], rtol=DISTANCES_TOLERANCE_CLASS)
def reference_models():
    """
    Create a set of reference Cosmology() objects.
    """
    # Standard LCDM model
    p1 = ccl.Parameters(Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10, n_s=0.96)
    cosmo1 = ccl.Cosmology(p1)
    
    # LCDM model with curvature
    p2 = ccl.Parameters(Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10, 
                        n_s=0.96, Omega_k=0.05)
    cosmo2 = ccl.Cosmology(p2)
    
    # wCDM model
    p3 = ccl.Parameters(Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10, 
                        n_s=0.96, w0=-0.95, wa=0.05)
    cosmo3 = ccl.Cosmology(p3)

    # BBKS Pk
    p4 = ccl.Parameters(Omega_c=0.27, Omega_b=0.045, h=0.67, sigma8=0.8, n_s=0.96)
    cosmo4 = ccl.Cosmology(p4,transfer_function='bbks')

    # E&H Pk
    p5 = ccl.Parameters(Omega_c=0.27, Omega_b=0.045, h=0.67, sigma8=0.8, n_s=0.96)
    cosmo5 = ccl.Cosmology(p5,transfer_function='eisenstein_hu')

    # Baryons Pk
    p6 = ccl.Parameters(Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10, n_s=0.96)
    cosmo6 = ccl.Cosmology(p6,baryons_power_spectrum='bcm')
    
    # Baryons Pk with choice of BCM parameters other than default
    p7 = ccl.Parameters(Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10, n_s=0.96,
                        bcm_log10Mc=math.log10(1.7e14), bcm_etab=0.3, bcm_ks=75.)
    cosmo7 = ccl.Cosmology(p7,baryons_power_spectrum='bcm')

    # Return 
    return [cosmo1,cosmo4,cosmo5,cosmo7] # cosmo2, cosmo3, cosmo6
Exemple #19
0
    q = [line.split()][0][4]
    if isfloat(ra):
        dla_ra.append(float(ra))
        dla_dec.append(float(dec))
        dla_z.append(float(d))
        qso_z.append(float(q))

dz = .01
rdshift = np.arange(0, 7.2, dz)
n_dla = stats.gaussian_kde(dla_z, bw_method=0.1)(rdshift)
n_qso = stats.gaussian_kde(qso_z, bw_method=0.1)(rdshift)

#set ccl parameters
parameters = ccl.Parameters(Omega_c=0.27,
                            Omega_b=0.045,
                            h=0.69,
                            sigma8=0.83,
                            n_s=0.96)
cosmo = ccl.Cosmology(parameters)
lens = ccl.ClTracerCMBLensing(cosmo)

#use ccl to predict cls
bias_qso = np.ones(rdshift.size)
bias_dla = np.ones(rdshift.size)

b = nmt.NmtBin(2048, nlb=bsize)
ell_arr = b.get_effective_ells()

source_dla = ccl.ClTracerNumberCounts(cosmo,
                                      False,
                                      False,
Exemple #20
0
    'omega_cdm': 0.11910,
    'tau_reio': 0.0865,
    'P_k_max_h/Mpc': 20.,
    'YHe': 0.245370,
    'N_ncdm': 0,
    'z_pk': ", ".join(map(str, np.concatenate((zlow, zhigh))))
}

OmegaH = 1e-3
OmegaC = (params['omega_b'] + params['omega_cdm']) / params['h']**2
OmegaB = (params['omega_b']) / params['h']**2
h = params['h']
cosmo = ccl.Cosmology(ccl.Parameters(
    Omega_c=OmegaC,
    Omega_b=OmegaB,
    h=h,
    A_s=params['A_s'],
    n_s=params['n_s'],
),
                      matter_power_spectrum='linear')


def Tspin(z, OmegaH, OmegaM):
    ## Formula from Tzu-Ching, in mK, arXiv:0709.3672
    return 0.3 * (OmegaH / 1e-3) * np.sqrt(
        (1 + z) / (2.5) * 0.29 / (OmegaM + (1. - OmegaM) / (1 + z)**3))


# first let's compute background values at our zs
for name, zs in [("zlow", zlow)]:  #,("zhigh",zhigh)]:
    f = open("background_%s.dat" % (name), 'w')
Exemple #21
0
#
# This takes an input sacc files, replaces measurements with CCL theory predictions + scatter and
# resaves
#

import sacc
import sys
import numpy as np
import scipy.linalg as la
try:
    import pyccl as ccl
except:
    print("Need CCL!")
    sys.exit(1)

p = ccl.Parameters(Omega_c=0.27, Omega_b=0.045, h=0.67, A_s=1e-10, n_s=0.96)
ccl_cosmo = ccl.Cosmology(p)
s = sacc.SACC.loadFromHDF("test.sacc")


#
# first, let's convert sacc tracers to CCL tracers
#
def sacc2ccl_tracer(t):
    if len(t.z) != 1:
        toret = ccl.ClTracerNumberCounts(ccl_cosmo,
                                         has_rsd=False,
                                         has_magnification=False,
                                         n=(t.z, t.Nz),
                                         bias=(t.z, t.extraColumn('b')),
                                         mag_bias=(t.z, np.zeros(len(t.z))))
Exemple #22
0
def getTheories(ccl_cosmo,s,ctracers) :
    theo={}
    for t1i,t2i,ells,_ in s.sortTracers(): 
        cls=ccl.angular_cl(ccl_cosmo,ctracers[t1i],ctracers[t2i],ells)
        theo[(t1i,t2i)]=cls
        theo[(t2i,t1i)]=cls
    return theo

def getTheoryVec(s, cls_theory):
    vec=np.zeros((s.size(),))
    for t1i,t2i,ells,ndx in s.sortTracers():
        vec[ndx]=cls_theory[(t1i,t2i)]
    return sacc.MeanVec(vec)
print 'Setting up cosmology'
cosmo = ccl.Cosmology(ccl.Parameters(Omega_c=0.266,Omega_b=0.049,h=hhub,sigma8=0.8,n_s=0.96,),matter_power_spectrum='linear',transfer_function='eisenstein_hu')

#Compute grid scale
zmax=2.5
ngrid=3072
a_grid=2*ccl.comoving_radial_distance(cosmo,1./(1+zmax))*(1+2./ngrid)/ngrid*hhub
print "Grid smoothing : %.3lf Mpc/h"%a_grid

print 'Reading SACC file'
#SACC File with the N(z) to analyze
binning_sacc = sacc.SACC.loadFromHDF('../test/catalog0.sacc')
#Bias file (it can also be included in the SACC file in the line before)
bias_tab = astropy.table.Table.read('../test/bz_lsst.txt',format='ascii')
tracers = binning_sacc.tracers
print 'Got ',len(tracers),' tracers'
cltracers=[ccl.ClTracerNumberCounts(cosmo,False,False,n=(t.z,t.Nz),bias=(bias_tab['col1'],bias_tab['col2']),r_smooth=0.5*a_grid) for t in tracers]