Example #1
0
def correlation_3d(cosmo, a, r):
    """
    Compute the 3D correlation function.

    Args:
        cosmo (:obj:`Cosmology`): A Cosmology object.
        a (float): scale factor.
        r (float or array_like): distance(s) at which to calculate the 3D correlation function (in Mpc).        
    Returns:
        Value(s) of the correlation function at the input distance(s).
    """
    cosmo_in = cosmo
    cosmo = _cosmology_obj(cosmo)
    status = 0

    # Convert scalar input into an array
    scalar = False
    if isinstance(r, float) or isinstance(r, int):
        scalar = True
        r = np.array([
            r,
        ])

    # Call 3D correlation function
    xi, status = lib.correlation_3d_vec(cosmo, a, r, len(r), status)
    check(status, cosmo_in)
    if scalar: return xi[0]
    return xi
Example #2
0
File: cls.py Project: EiffL/CCL
    def get_internal_function(self, cosmo, function, a):
        """
        Method to evaluate any internal function of redshift for this tracer.

        Args:
            cosmo (:obj:`Cosmology`): Cosmology object.
            function (:obj:`str`): Specifies which function to evaluate. Must 
                be one of the types specified in the `pyccl.cls.function_types` 
                dictionary.
            a (:obj: float or array-like): list of scale factors at which to 
                evaluate the function.
            
        Returns:
            Array of function values at the input scale factors.
        """
        # Access ccl_cosmology object
        cosmo_in = cosmo
        cosmo = _cosmology_obj(cosmo)

        # Access CCL_ClTracer objects
        clt = self.cltracer

        # Check that specified function type exists
        if function not in function_types.keys():
            raise KeyError("Internal function type '%s' not recognized." %
                           function)

        # Check input types
        status = 0
        is_scalar = False
        if isinstance(a, float):
            is_scalar = True
            aarr = np.array([a])
            na = 1
        elif isinstance(a, np.ndarray):
            aarr = a
            na = a.size
        else:
            aarr = a
            na = len(a)

        # Evaluate function
        farr, status = lib.clt_fa_vec(cosmo, self.cltracer,
                                      function_types[function], aarr, na,
                                      status)
        check(status, cosmo_in)
        if is_scalar:
            return farr[0]
        else:
            return farr
Example #3
0
def correlation(cosmo, ell, C_ell, theta, corr_type='gg', method='fftlog'):
    """Compute the angular correlation function.

    Args:
        cosmo (:obj:`Cosmology`): A Cosmology object.
        ell (array_like): Multipoles corresponding to the input angular power spectrum.
        C_ell (array_like): Input angular power spectrum.
        theta (float or array_like): Angular separation(s) at which to calculate the angular correlation function (in degrees).
        corr_type (string): Type of correlation function. Choices: 'GG' (galaxy-galaxy), 'GL' (galaxy-shear), 'L+' (shear-shear, xi+), 'L-' (shear-shear, xi-).
        method (string, optional): Method to compute the correlation function. Choices: 'Bessel' (direct integration over Bessel function), 'FFTLog' (fast integration with FFTLog), 'Legendre' (brute-force sum over Legendre polynomials).
    
    Returns:
        float or array_like: Value(s) of the correlation function at the input angular separations.

    """
    cosmo_in = cosmo
    cosmo = _cosmology_obj(cosmo)
    status = 0

    # Convert to lower case
    corr_type = corr_type.lower()
    method = method.lower()

    if corr_type not in correlation_types.keys():
        raise KeyError("'%s' is not a valid correlation type." % corr_type)

    if method.lower() not in correlation_methods.keys():
        raise KeyError("'%s' is not a valid correlation method." % method)

    # Convert scalar input into an array
    scalar = False
    if isinstance(theta, float) or isinstance(theta, int):
        scalar = True
        theta = np.array([
            theta,
        ])

    # Call correlation function
    wth, status = lib.correlation_vec(cosmo, ell, C_ell, theta,
                                      correlation_types[corr_type],
                                      correlation_methods[method], len(theta),
                                      status)
    check(status, cosmo_in)
    if scalar: return wth[0]
    return wth
Example #4
0
File: cls.py Project: zdu863/CCL
def angular_cl(cosmo, cltracer1, cltracer2, ell):
    """
    Calculate the angular (cross-)power spectrum for a pair of tracers.

    Args:
        cosmo (:obj:`Cosmology`): A Cosmology object.
        cltracer1, cltracer2 (:obj:): ClTracer objects, of any kind.
        ell (float or array_like): Angular wavenumber(s) to evaluate the
            angular power spectrum at.

    Returns:
        cl (float or array_like): Angular (cross-)power spectrum values, C_ell,
            for the pair of tracers, as a function of `ell`.

    """
    # Access ccl_cosmology object
    cosmo_in = cosmo
    cosmo = _cosmology_obj(cosmo)

    # Access CCL_ClTracer objects
    clt1 = _cltracer_obj(cltracer1)
    clt2 = _cltracer_obj(cltracer2)

    status = 0
    # Return Cl values, according to whether ell is an array or not
    if isinstance(ell, float) or isinstance(ell, int) :
        # Use single-value function
        cl, status = lib.angular_cl(cosmo, ell, clt1, clt2, status)
    elif isinstance(ell, np.ndarray):
        # Use vectorised function
        cl, status = lib.angular_cl_vec(cosmo, clt1, clt2, ell, ell.size, status)
    else:
        # Use vectorised function
        cl, status = lib.angular_cl_vec(cosmo, clt1, clt2, ell, len(ell), status)
    check(status, cosmo_in)
    return cl
Example #5
0
File: cls.py Project: EiffL/CCL
    def __init__(self,
                 cosmo,
                 tracer_type=None,
                 has_rsd=False,
                 has_magnification=False,
                 has_intrinsic_alignment=False,
                 z=None,
                 n=None,
                 bias=None,
                 mag_bias=None,
                 bias_ia=None,
                 f_red=None,
                 z_source=1100.):
        """
        ClTracer is a class for handling tracers that have an angular power
        spectrum.

        Note: unless otherwise stated, defaults are None.

        Args:
            cosmo (:obj:`Cosmology`): Cosmology object.
            tracer_type (:obj:`str`): Specifies which type of tracer is being
                specified. Must be one of the types specified in the
                `tracer_types` dict in `cls.py`.
            has_rsd (bool, optional): Flag for whether the tracer has a
                redshift-space distortion term. Defaults to False.
            has_magnification (bool, optional): Flag for whether the tracer has
                a magnification term. Defaults to False.
            has_intrinsic_alignment (bool, optional): Flag for whether the
                tracer has an intrinsic alignment term. Defaults to False.
            z (array_like, optional): Array of redshifts that the following
                functions are sampled at. This is overriden if tuples of the
                form (z, fn(z)) are specified for those kwargs instead (this
                allows the functions to be sampled differently in z).
            n (array_like or tuple, optional): Array of N(z) sampled at the
                redshifts given in the z array, or a tuple of arrays (z, N(z)).
                The units are arbitrary; N(z) will be normalized to unity.
            bias (array_like or tuple, optional): Array of galaxy bias b(z)
                sampled at the redshifts given in the z array, or a tuple of
                arrays (z, b(z)).
            mag_bias (array_like or tuple, optional): Array of magnification
                bias s(z) sampled at the redshifts given in the z array, or a
                tuple of arrays (z, s(z)).
            bias_ia (array_like or tuple, optional): Array of intrinsic
                alignment amplitudes b_IA(z), or a tuple of arrays (z, b_IA(z)).
            f_red (array_like or tuple, optional): Array of red galaxy
                fractions f_red(z), or a tuple of arrays (z, f_red(z)).
            z_source (float, optional): Redshift of source plane for CMB lensing.
        """
        # Verify cosmo object
        cosmo = _cosmology_obj(cosmo)

        # Check tracer type
        if tracer_type not in tracer_types.keys():
            raise KeyError("'%s' is not a valid tracer_type." % tracer_type)

        # Convert array arguments that are 'None' into 'NoneArr' type, and
        # check whether arrays were specified as tuples or with a common z array
        self.z_n, self.n = _check_array_params(z, n, 'n')
        self.z_b, self.b = _check_array_params(z, bias, 'bias')
        self.z_s, self.s = _check_array_params(z, mag_bias, 'mag_bias')
        self.z_ba, self.ba = _check_array_params(z, bias_ia, 'bias_ia')
        self.z_rf, self.rf = _check_array_params(z, f_red, 'f_red')
        self.z_source = z_source

        # Construct new ccl_cl_tracer
        status = 0
        return_val = lib.cl_tracer_new_wrapper(cosmo,
                                               tracer_types[tracer_type],
                                               int(has_rsd),
                                               int(has_magnification),
                                               int(has_intrinsic_alignment),
                                               self.z_n, self.n, self.z_b,
                                               self.b, self.z_s, self.s,
                                               self.z_ba, self.ba, self.z_rf,
                                               self.rf, self.z_source, status)

        if (isinstance(return_val, int)):
            self.has_cltracer = False
            check(return_val)
        else:
            self.has_cltracer = True
            self.cltracer, status = return_val
Example #6
0
File: cls.py Project: EiffL/CCL
def angular_cl(cosmo,
               cltracer1,
               cltracer2,
               ell,
               l_limber=-1.,
               l_logstep=1.05,
               l_linstep=20.,
               dchi=3.,
               dlk=0.003,
               zmin=0.05,
               non_limber_method="native"):
    """
    Calculate the angular (cross-)power spectrum for a pair of tracers.

    Args:
        cosmo (:obj:`Cosmology`): A Cosmology object.
        cltracer1, cltracer2 (:obj:): ClTracer objects, of any kind.
        ell (float or array_like): Angular wavenumber(s) to evaluate the
            angular power spectrum at.
        l_limber (float) : Angular wavenumber beyond which Limber's
            approximation will be used
        l_logstep (float) : logarithmic step in ell at low multipoles
        l_linstep (float) : linear step in ell at high multipoles
        dchi (float) : comoving distance step size in non-limber native integrals
        dlk (float) : logarithmic step for the k non-limber native integral
        zmin (float) : minimal redshift for the integrals
        non_limber_method (str) : non-Limber integration method. Supported:
            "native" and "angpow"

    Returns:
        cl (float or array_like): Angular (cross-)power spectrum values, C_ell,
            for the pair of tracers, as a function of `ell`.

    """
    # Access ccl_cosmology object
    cosmo_in = cosmo
    cosmo = _cosmology_obj(cosmo)

    if non_limber_method not in nonlimber_methods.keys():
        raise KeyError("'%s' is not a valid non-Limber integration method." %
                       non_limber_method)

    # Access CCL_ClTracer objects
    clt1 = _cltracer_obj(cltracer1)
    clt2 = _cltracer_obj(cltracer2)

    status = 0
    # Return Cl values, according to whether ell is an array or not
    if isinstance(ell, float) or isinstance(ell, int):
        # Use single-value function
        cl_one, status = lib.angular_cl_vec(
            cosmo, clt1, clt2, l_limber, l_logstep, l_linstep, dchi, dlk, zmin,
            nonlimber_methods[non_limber_method], [ell], 1, status)
        cl = cl_one[0]
    elif isinstance(ell, np.ndarray):
        # Use vectorised function
        cl, status = lib.angular_cl_vec(cosmo, clt1, clt2, l_limber, l_logstep,
                                        l_linstep, dchi, dlk, zmin,
                                        nonlimber_methods[non_limber_method],
                                        ell, ell.size, status)
    else:
        # Use vectorised function
        cl, status = lib.angular_cl_vec(cosmo, clt1, clt2, l_limber, l_logstep,
                                        l_linstep, dchi, dlk, zmin,
                                        nonlimber_methods[non_limber_method],
                                        ell, len(ell), status)
    check(status)
    return cl