Beispiel #1
0
    def eval_sigma_crit(self, z_len, z_src):
        a_len = self.cosmo._get_a_from_z(z_len)
        a_src = np.atleast_1d(self.cosmo._get_a_from_z(z_src))
        cte = ccl.physical_constants.CLIGHT**2 / (
            4.0 * np.pi * ccl.physical_constants.GNEWT *
            ccl.physical_constants.SOLAR_MASS
        ) * ccl.physical_constants.MPC_TO_METER

        z_cut = (a_src < a_len)
        if np.isscalar(a_len):
            a_len = np.repeat(a_len, len(a_src))

        res = np.zeros_like(a_src)

        if np.any(z_cut):
            Ds = ccl.angular_diameter_distance(self.cosmo.be_cosmo,
                                               a_src[z_cut])
            Dl = ccl.angular_diameter_distance(self.cosmo.be_cosmo,
                                               a_len[z_cut])
            Dls = ccl.angular_diameter_distance(self.cosmo.be_cosmo,
                                                a_len[z_cut], a_src[z_cut])

            res[z_cut] = (cte * Ds / (Dl * Dls)) * self.cor_factor

        res[~z_cut] = np.Inf

        return np.squeeze(res)
Beispiel #2
0
def test_background_a_interface(a, func):
    if func is ccl.distance_modulus and np.any(a == 1):
        with pytest.raises(ccl.CCLError):
            func(COSMO, a)
    else:
        val = func(COSMO, a)
        assert np.all(np.isfinite(val))
        assert np.shape(val) == np.shape(a)
        if (func is ccl.angular_diameter_distance):
            val = func(COSMO, a, a)
            assert np.all(np.isfinite(val))
            assert np.shape(val) == np.shape(a)
            if (isinstance(a, float) or isinstance(a, int)):
                val1 = ccl.angular_diameter_distance(COSMO, 1., a)
                val2 = ccl.comoving_angular_distance(COSMO, a) * a
            else:
                val1 = ccl.angular_diameter_distance(COSMO, np.ones(len(a)), a)
                val2 = ccl.comoving_angular_distance(COSMO, a) * a
            assert np.allclose(val1, val2)
Beispiel #3
0
def test_distances_flat():
    # We first define equivalent CCL and jax_cosmo cosmologies
    cosmo_ccl = ccl.Cosmology(
        Omega_c=0.3,
        Omega_b=0.05,
        h=0.7,
        sigma8=0.8,
        n_s=0.96,
        Neff=0,
        transfer_function="eisenstein_hu",
        matter_power_spectrum="linear",
    )

    cosmo_jax = Cosmology(
        Omega_c=0.3,
        Omega_b=0.05,
        h=0.7,
        sigma8=0.8,
        n_s=0.96,
        Omega_k=0.0,
        w0=-1.0,
        wa=0.0,
    )

    # Test array of scale factors
    a = np.linspace(0.01, 1.0)

    chi_ccl = ccl.comoving_radial_distance(cosmo_ccl, a)
    chi_jax = bkgrd.radial_comoving_distance(cosmo_jax, a) / cosmo_jax.h
    assert_allclose(chi_ccl, chi_jax, rtol=0.5e-2)

    chi_ccl = ccl.comoving_angular_distance(cosmo_ccl, a)
    chi_jax = bkgrd.transverse_comoving_distance(cosmo_jax, a) / cosmo_jax.h
    assert_allclose(chi_ccl, chi_jax, rtol=0.5e-2)

    chi_ccl = ccl.angular_diameter_distance(cosmo_ccl, a)
    chi_jax = bkgrd.angular_diameter_distance(cosmo_jax, a) / cosmo_jax.h
    assert_allclose(chi_ccl, chi_jax, rtol=0.5e-2)
Beispiel #4
0
    def update(self, H0, Om0, Ob0, sigma8, ns):
        """Recalculate cluster counts for the updated cosmological parameters given.
        
        Args:
            H0 (:obj:`float`): The Hubble constant at redshift 0, in km/s/Mpc.
            Om0 (:obj:`float`): Dimensionless total (dark + baryonic) matter density parameter at redshift 0.
            Ob0 (:obj:`float`): Dimensionless baryon matter density parameter at redshift 0.
            sigma8 (:obj:`float`): Defines the amplitude of the matter power spectrum.
            ns (:obj:`float`): Scalar spectral index of matter power spectrum.  
                
        """

        self._get_new_cosmo(H0, Om0, Ob0, sigma8, ns)
        
        self._doClusterCount()
        
        # For quick Q, fRel calc (these are in MockSurvey rather than SelFn as used by drawSample)
        self.theta500Splines=[]
        self.fRelSplines=[]
        self.Ez=ccl.h_over_h0(self.cosmoModel,self.a)
        self.Ez2=np.power(self.Ez, 2)
        self.DAz=ccl.angular_diameter_distance(self.cosmoModel,self.a)
        self.criticalDensity=ccl.physical_constants.RHO_CRITICAL*(self.Ez*self.cosmoModel['h'])**2
        for k in range(len(self.z)):
            # NOTE: Q fit uses theta500, as does fRel (hardcoded M500 - T relation in there)
            # This bit here may not be strictly necessary, since we don't need to map on to binning
            if self.delta != 500 or self.rhoType != "critical":
                interpLim_minLog10M500c=np.log10(self.mdef.translate_mass(self.cosmoModel, self.M.min(), 
                                                                          self.a[k], self._M500cDef))
                interpLim_maxLog10M500c=np.log10(self.mdef.translate_mass(self.cosmoModel, self.M.max(), 
                                                                          self.a[k], self._M500cDef))
            else:
                interpLim_minLog10M500c=self.log10M.min()
                interpLim_maxLog10M500c=self.log10M.max()
            zk=self.z[k]
            interpPoints=100
            fitM500s=np.power(10, np.linspace(interpLim_minLog10M500c, interpLim_maxLog10M500c, interpPoints))
            fitTheta500s=np.zeros(len(fitM500s))
            fitFRels=np.zeros(len(fitM500s))
            criticalDensity=self.criticalDensity[k]
            DA=self.DAz[k]
            Ez=self.Ez[k]
            R500Mpc=np.power((3*fitM500s)/(4*np.pi*500*criticalDensity), 1.0/3.0)    
            fitTheta500s=np.degrees(np.arctan(R500Mpc/DA))*60.0
            fitFRels=signals.calcFRel(zk, fitM500s, Ez)
            tckLog10MToTheta500=interpolate.splrep(np.log10(fitM500s), fitTheta500s)
            tckLog10MToFRel=interpolate.splrep(np.log10(fitM500s), fitFRels)
            self.theta500Splines.append(tckLog10MToTheta500)
            self.fRelSplines.append(tckLog10MToFRel)

        # Stuff to enable us to draw mock samples (see drawSample)
        # Interpolators here need to be updated each time we change cosmology
        if self.enableDrawSample == True:

            # For drawing from overall z distribution
            zSum=self.clusterCount.sum(axis = 1)
            pz=np.cumsum(zSum)/self.numClusters
            self.zRoller=_spline(pz, self.z, k = 3)
            
            # For drawing from each log10M distribution at each point on z grid
            # And quick fRel, Q calc using interpolation
            # And we may as well have E(z), DA on the z grid also
            self.log10MRollers=[]
            for i in range(len(self.z)):
                ngtm=self._cumulativeNumberDensity(self.z[i])
                mask=ngtm > 0
                self.log10MRollers.append(_spline((ngtm[mask] / ngtm[0])[::-1], np.log10(self.M[mask][::-1]), k=3))
Beispiel #5
0
def calc_angsize(physsize, z, cosmology):
    """Given a physical size in m, returns the angular size in radians"""
    z = np.asanyarray(z)
    d_A = pyccl.angular_diameter_distance(
        cosmology, 1 / (z.reshape(-1) + 1)).reshape(z.shape) * 1e6 * utils.pc
    return np.arctan2(physsize, d_A)