コード例 #1
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')))
コード例 #2
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')) )
コード例 #3
0
def websky_decode(data, cosmology, mass_interp):
    """Go from a raw websky catalog to pos, z and m200"""
    chi = np.sum(data.T[:3]**2, 0)**0.5  # comoving Mpc
    a = pyccl.scale_factor_of_chi(cosmology, chi)
    z = 1 / a - 1
    R = data.T[6].astype(float) * 1e6 * utils.pc  # m. This is *not* r200!
    rho_m = calc_rho_c(0, cosmology) * cosmology["Omega_m"]
    m200m = 4 / 3 * np.pi * rho_m * R**3
    m200 = mass_interp(m200m, z)
    ra, dec = utils.rect2ang(data.T[:3])
    return bunch.Bunch(z=z, ra=ra, dec=dec, m200=m200)
コード例 #4
0
    def __init__(self, cosmo, z_max=6., n_chi=1024):
        self.chi_max = ccl.comoving_radial_distance(cosmo, 1. / (1 + z_max))
        chi = np.linspace(0, self.chi_max, n_chi)
        a_arr = ccl.scale_factor_of_chi(cosmo, chi)
        H0 = cosmo['h'] / ccl.physical_constants.CLIGHT_HMPC
        OM = cosmo['Omega_c'] + cosmo['Omega_b']
        Ez = ccl.h_over_h0(cosmo, a_arr)
        fz = ccl.growth_rate(cosmo, a_arr)
        w_arr = 3 * cosmo['T_CMB'] * H0**3 * OM * Ez * chi**2 * (1 - fz)

        self._trc = []
        self.add_tracer(cosmo, kernel=(chi, w_arr), der_bessel=-1)
コード例 #5
0
ファイル: cosmology.py プロジェクト: j-dr/pyaddgals
    def zofR(self, r):
        """Calculate redshift from comoving radial distance.

        Parameters
        ----------
        r : np.array
            Array of comoving radial distances

        Returns
        -------
        z : np.array
            Array of redshifts corresponding to input comoving radial distance

        """
        z = 1 / ccl.scale_factor_of_chi(self._cosmo, r) - 1

        return z
コード例 #6
0
ファイル: theory.py プロジェクト: damonge/SZCl_like
    def __init__(self, cosmo, z_max=6., n_chi=1024):
        self.chi_max = ccl.comoving_radial_distance(cosmo, 1. / (1 + z_max))
        chi_arr = np.linspace(0, self.chi_max, n_chi)
        a_arr = ccl.scale_factor_of_chi(cosmo, chi_arr)
        # avoid recomputing every time
        # Units of eV * Mpc / cm^3

        # sigma_T = 6.65e-29 m2
        # m_e = 9.11e-31 kg
        # c = 3e8  m/s

        # eV2J = 1.6e-19 eV/J (J=kg m2/s2)
        # cm2pc = 3.1e18 cm/pc

        # prefac = (sigma_t*(10**2)**2/(m_e*c**2/J2eV))*cm2pc*10**6

        prefac = 4.01710079e-06
        w_arr = prefac * a_arr

        self._trc = []
        self.add_tracer(cosmo, kernel=(chi_arr, w_arr))
コード例 #7
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)))
コード例 #8
0
ファイル: test_tracers.py プロジェクト: wwk5c5gh3/CCL
def test_tracers_analytic(set_up, alpha, beta, gamma, is_factorizable,
                          w_transfer, mismatch, der_bessel, der_angles):
    cosmo = set_up
    zmax = 0.8
    zi = 0.4
    zf = 0.6
    nchi = 1024
    nk = 512

    # x arrays
    chii = ccl.comoving_radial_distance(cosmo, 1. / (1 + zi))
    chif = ccl.comoving_radial_distance(cosmo, 1. / (1 + zf))
    chimax = ccl.comoving_radial_distance(cosmo, 1. / (1 + zmax))
    chiarr = np.linspace(0.1, chimax, nchi)
    if mismatch:
        # Remove elements around the edges
        mask = (chiarr < 0.9 * chif) & (chiarr > 1.1 * chii)
        chiarr_transfer = chiarr[mask]
    else:
        chiarr_transfer = chiarr
    aarr_transfer = ccl.scale_factor_of_chi(cosmo, chiarr_transfer)[::-1]
    aarr = ccl.scale_factor_of_chi(cosmo, chiarr)[::-1]
    lkarr = np.log(10.**np.linspace(-6, 3, nk))

    # Kernel
    wchi = np.ones_like(chiarr)
    wchi[chiarr < chii] = 0
    wchi[chiarr > chif] = 0

    # Transfer
    t = ccl.Tracer()
    if w_transfer:
        ta = (chiarr_transfer**gamma)[::-1]
        tk = np.exp(beta * lkarr)
        if is_factorizable:
            # 1D
            t.add_tracer(cosmo,
                         kernel=(chiarr, wchi),
                         transfer_k=(lkarr, tk),
                         transfer_a=(aarr_transfer, ta),
                         der_bessel=der_bessel,
                         der_angles=der_angles)
        else:
            # 2D
            tka = ta[:, None] * tk[None, :]
            t.add_tracer(cosmo,
                         kernel=(chiarr, wchi),
                         transfer_ka=(aarr_transfer, lkarr, tka),
                         der_bessel=der_bessel,
                         der_angles=der_angles)
    else:
        t.add_tracer(cosmo,
                     kernel=(chiarr, wchi),
                     der_bessel=der_bessel,
                     der_angles=der_angles)

    # Power spectrum
    pkarr = np.ones_like(aarr)[:, None] * (np.exp(alpha * lkarr))[None, :]
    pk2d = ccl.Pk2D(a_arr=aarr, lk_arr=lkarr, pk_arr=pkarr, is_logp=False)

    # C_ells
    larr = np.linspace(2, 3000, 100)
    # 1D
    cl = ccl.angular_cl(cosmo, t, t, larr, p_of_k_a=pk2d)
    # Prediction
    clpred = get_prediction(larr, chii, chif, alpha, beta, gamma, der_bessel,
                            der_angles)

    assert np.all(np.fabs(cl / clpred - 1) < 5E-3)
コード例 #9
0
 def L_pix(cosmo, chi, theta):
     a = ccl.scale_factor_of_chi(cosmo, chi)
     return chi*a*theta