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 = _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) return cl
def dNdz_tomog(z, dNdz_type, zmin, zmax, pz_func): """Calculates dNdz in a particular tomographic bin, convolved with a photo-z model (defined by the user), and normalized. Args: z (float or array_like): Spectroscopic redshifts to evaluate dNdz at. dNdz_type (:obj:`str`): Type of redshift distribution. zmin (float): Minimum photo-z of the bin. zmax (float): Maximum photo-z of the bin. pz_func (callable): User-defined photo-z function. Return: dNdz (float or array_like): dNdz values evalued at each z. """ # Ensure that an array will be passed to specs_dNdz_tomog_vec z = np.atleast_1d(z) # Do type-check for pz_func argument if not isinstance(pz_func, PhotoZFunction): raise TypeError("pz_func must be a PhotoZFunction instance.") # Get dNdz type if dNdz_type not in dNdz_types.keys(): raise ValueError("'%s' not a valid dNdz_type." % dNdz_type) # Call dNdz tomography function status = 0 dNdz, status = lib.specs_dNdz_tomog_vec(dNdz_types[dNdz_type], zmin, zmax, pz_func.pz_func, z, z.size, status) check(status) return dNdz
def compute_power(self): """Interfaces with src/ccl_power.c: ccl_cosmology_compute_power(). Sets up the splines for the power spectrum. """ status = 0 status = lib.cosmology_compute_power(self.cosmo, status) check(status)
def compute_growth(self): """Interfaces with src/ccl_background.c: ccl_cosmology_compute_growth(). Sets up the splines for the growth function. """ status = 0 status = lib.cosmology_compute_growth(self.cosmo, status) check(status)
def compute_distances(self): """Interfaces with src/compute_background.c: ccl_cosmology_compute_distances(). Sets up the splines for the distances. """ status = 0 status = lib.cosmology_compute_distances(self.cosmo, status) check(status)
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: Value(s) of the correlation function at the input angular separation(s). """ 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): 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) if scalar: return wth[0] return wth
def angular_cl(cosmo, cltracer1, cltracer2, ell, l_limber=-1., l_logstep=1.05, l_linstep=20., 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 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 = _cosmology_obj(cosmo) if non_limber_method not in nonlimber_methods.keys(): raise KeyError("'%s' is not a valide 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, 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, 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, nonlimber_methods[non_limber_method], ell, len(ell), status) check(status) return cl