How to use pyccl - 10 common examples

To help you get started, we’ve selected a few pyccl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LSSTDESC / CLMM / clmm / modbackend / ccl.py View on Github external
def eval_sigma_crit (self, z_len, z_src):
        a_len = _get_a_from_z (z_len)
        a_src = np.atleast_1d (_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.PC_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, a_src[z_cut])
            Dl  = ccl.angular_diameter_distance (self.cosmo, a_len)
            Dls = ccl.angular_diameter_distance (self.cosmo, a_len, a_src[z_cut])
        
            res[z_cut] = (cte * Ds / (Dl * Dls)) * self.cor_factor * 1.0e-6 / self.cosmo['h']

        res[~z_cut] = np.Inf

        return np.squeeze (res)
github LSSTDESC / CLMM / clmm / modbackend / ccl.py View on Github external
def eval_sigma_crit (self, z_len, z_src):
        a_len = _get_a_from_z (z_len)
        a_src = np.atleast_1d (_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.PC_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, a_src[z_cut])
            Dl  = ccl.angular_diameter_distance (self.cosmo, a_len)
            Dls = ccl.angular_diameter_distance (self.cosmo, a_len, a_src[z_cut])
        
            res[z_cut] = (cte * Ds / (Dl * Dls)) * self.cor_factor * 1.0e-6 / self.cosmo['h']

        res[~z_cut] = np.Inf

        return np.squeeze (res)
github LSSTDESC / CLMM / clmm / modbackend / ccl.py View on Github external
def eval_sigma_crit (self, z_len, z_src):
        a_len = _get_a_from_z (z_len)
        a_src = np.atleast_1d (_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.PC_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, a_src[z_cut])
            Dl  = ccl.angular_diameter_distance (self.cosmo, a_len)
            Dls = ccl.angular_diameter_distance (self.cosmo, a_len, a_src[z_cut])
        
            res[z_cut] = (cte * Ds / (Dl * Dls)) * self.cor_factor * 1.0e-6 / self.cosmo['h']

        res[~z_cut] = np.Inf

        return np.squeeze (res)
github LSSTDESC / CLMM / clmm / modbackend / ccl.py View on Github external
def eval_sigma_crit (self, z_len, z_src):
        a_len = _get_a_from_z (z_len)
        a_src = np.atleast_1d (_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.PC_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, a_src[z_cut])
            Dl  = ccl.angular_diameter_distance (self.cosmo, a_len)
            Dls = ccl.angular_diameter_distance (self.cosmo, a_len, a_src[z_cut])
        
            res[z_cut] = (cte * Ds / (Dl * Dls)) * self.cor_factor * 1.0e-6 / self.cosmo['h']

        res[~z_cut] = np.Inf
github LSSTDESC / CLMM / clmm / modbackend / ccl.py View on Github external
self.hdpm_opts = {'nfw': {'truncated': False, 
                                  'projected_analytic': True, 
                                  'cumul2d_analytic': True},
                          'einasto': {},
                          'hernquist': {}}

        self.halo_profile_model = ''
        self.massdef = ''
        self.delta_mdef = 0
        self.hdpm = None
        self.MDelta = 0.0

        self.set_cosmo_params_dict ({})
        self.set_halo_density_profile (halo_profile_model, massdef, delta_mdef)
        
        self.cor_factor = 2.77533742639e+11 * _patch_comoving_coord_cluster_toolkit_rho_m (1.0, 0.0) / ccl.physical_constants.RHO_CRITICAL
github LSSTDESC / CLMM / clmm / modbackend / ccl.py View on Github external
def set_cosmo_params_dict (self, cosmo_dict):
        h = 0.67
        Omega_c = 0.27
        Omega_b = 0.045
        
        if 'H0' in cosmo_dict:
            h = cosmo_dict['H0'] / 100.0
        if 'Omega_b' in cosmo_dict:
            Omega_b = cosmo_dict['Omega_b']
        if 'Omega_c' in cosmo_dict:
            Omega_c = cosmo_dict['Omega_c']
        
        self.cosmo = ccl.Cosmology (Omega_c = Omega_c, Omega_b = Omega_b, h = h, sigma8 = 0.8, n_s = 0.96, T_CMB = 0.0, Neff = 0.0,
                                    transfer_function='bbks', matter_power_spectrum='linear')
github LSSTDESC / CLMM / examples / demo_polaraveraging.py View on Github external
from astropy import units as u
import pickle
import polaraveraging
import clmm

cosmo_object_type = "astropy"
try:
    import pyccl
except:
    cosmo_object_type = "astropy"
if cosmo_object_type == "astropy":
    from astropy.cosmology import FlatLambdaCDM
    cosmo = FlatLambdaCDM(70., Om0 = 0.3) # astropy cosmology setting, will be replaced by ccl
elif cosmo_object_type == "ccl":
    import pyccl as ccl
    cosmo = ccl.Cosmology(Omega_c=0.25, Omega_b = 0.05,h = 0.7,n_s = 0.97, sigma8 = 0.8, Omega_k = 0.)

cl = clmm.load_cluster('9687686568.p')

ra_l = cl.ra
dec_l = cl.dec
z = cl.z

e1 = cl.galcat['e1']
e2 = cl.galcat['e2']

ra_s = cl.galcat['ra']
dec_s = cl.galcat['dec'] 

theta, g_t , g_x = polaraveraging._compute_shear(ra_l, dec_l, ra_s, dec_s, e1, e2, sky = "flat")  #calculate distance and tangential shear and cross shear for each source galaxy
#theta, g_t , g_x = compute_shear(ra_l, dec_l, ra_s, dec_s, e1, e2, sky = "curved") #curved sky
rMpc = polaraveraging._theta_units_conversion(theta,"Mpc",z,cosmo,cosmo_object_type=cosmo_object_type)
github LSSTDESC / CLMM / clmm / modbackend / ccl.py View on Github external
raise ValueError (f"Halo density profile mass definition {massdef} not currently supported")

        # Check if we have already an instance of the required object, if not create one
        if not ((halo_profile_model == self.halo_profile_model) and (massdef == self.massdef) and (delta_mdef == self.delta_mdef)):
            self.halo_profile_model = halo_profile_model
            self.massdef = massdef
            
            cur_cdelta = 0.0
            cur_mdelta = 0.0
            cur_values = False
            if self.hdpm:
                cur_cdelta = self.conc.c
                cur_values = True
            
            self.mdef = ccl.halos.MassDef (delta_mdef, self.mdef_dict[massdef])
            self.conc = ccl.halos.ConcentrationConstant (self.mdef)
            self.mdef.concentration = self.conc
            self.hdpm = self.hdpm_dict[halo_profile_model] (self.conc, **self.hdpm_opts[halo_profile_model])
            if cur_values:
                self.conc.c = cur_cdelta
github LSSTDESC / CLMM / clmm / modbackend / ccl.py View on Github external
def __init__ (self, massdef = 'mean', delta_mdef = 200, halo_profile_model = 'nfw', z_max = 5.0):

        self.mdef_dict = {'mean':      'matter', 
                          'critial':   'critical',
                          'virial':    'critical'}
        self.hdpm_dict = {'nfw':       ccl.halos.HaloProfileNFW, 
                          'einasto':   ccl.halos.HaloProfileEinasto,
                          'hernquist': ccl.halos.HaloProfileHernquist}
        self.hdpm_opts = {'nfw': {'truncated': False, 
                                  'projected_analytic': True, 
                                  'cumul2d_analytic': True},
                          'einasto': {},
                          'hernquist': {}}

        self.halo_profile_model = ''
        self.massdef = ''
        self.delta_mdef = 0
        self.hdpm = None
        self.MDelta = 0.0

        self.set_cosmo_params_dict ({})
        self.set_halo_density_profile (halo_profile_model, massdef, delta_mdef)
github LSSTDESC / CLMM / clmm / modbackend / ccl.py View on Github external
if not massdef in self.mdef_dict:
            raise ValueError (f"Halo density profile mass definition {massdef} not currently supported")

        # Check if we have already an instance of the required object, if not create one
        if not ((halo_profile_model == self.halo_profile_model) and (massdef == self.massdef) and (delta_mdef == self.delta_mdef)):
            self.halo_profile_model = halo_profile_model
            self.massdef = massdef
            
            cur_cdelta = 0.0
            cur_mdelta = 0.0
            cur_values = False
            if self.hdpm:
                cur_cdelta = self.conc.c
                cur_values = True
            
            self.mdef = ccl.halos.MassDef (delta_mdef, self.mdef_dict[massdef])
            self.conc = ccl.halos.ConcentrationConstant (self.mdef)
            self.mdef.concentration = self.conc
            self.hdpm = self.hdpm_dict[halo_profile_model] (self.conc, **self.hdpm_opts[halo_profile_model])
            if cur_values:
                self.conc.c = cur_cdelta