def setup(self): # Initialize cosmology par = self.get_cosmological_parameters() dpk = self.get_pk() a = 1./(1+dpk['z'][::-1]) self.cosmo = ccl.CosmologyCalculator(Omega_c=par['Omega_m']-par['Omega_b'], Omega_b=par['Omega_b'], h=par['h'], n_s=par['n_s'], A_s=par['A_s'], w0=par['w0'], pk_linear={'a': a, 'k': dpk['k'], 'delta_matter:delta_matter': dpk['pk_lin'][::-1][:]}, pk_nonlin={'a': a, 'k': dpk['k'], 'delta_matter:delta_matter': dpk['pk_nl'][::-1][:]}) # Initialize tracers if self.config.get('tracers_from_kernels', False): tpar = self.get_tracer_parameters() ker = self.get_tracer_kernels() a_g = 1./(1+ker['z_cl'][::-1]) self.t_g = [] for k in ker['kernels_cl']: t = ccl.Tracer() barr = np.ones_like(a_g) t.add_tracer(self.cosmo, (ker['chi_cl'], k), transfer_a=(a_g, barr)) self.t_g.append(t) self.t_s = [] for k in ker['kernels_sh']: t = ccl.Tracer() t.add_tracer(self.cosmo, kernel=(ker['chi_sh'], k), der_bessel=-1, der_angles=2) self.t_s.append(t) else: nzs = self.get_tracer_dndzs() tpar = self.get_tracer_parameters() z_g = nzs['z_cl'] z_s = nzs['z_sh'] self.t_g = [ccl.NumberCountsTracer(self.cosmo, True, (z_g, nzs['dNdz_cl'][:, ni]), bias=(z_g, np.full(len(z_g), b))) for ni, b in zip(range(0, 10), tpar['b_g'])] self.t_s = [ccl.WeakLensingTracer(self.cosmo, (z_s, nzs['dNdz_sh'][:, ni]), True) for ni in range(0, 5)]
def get_tracer(tracer_type, cosmo=None, **tracer_kwargs): if cosmo is None: cosmo = COSMO z = np.linspace(0., 1., 2000) n = dndz(z) b = np.sqrt(1. + z) if tracer_type == 'nc': ntr = 3 tr = ccl.NumberCountsTracer(cosmo, True, dndz=(z, n), bias=(z, b), mag_bias=(z, b), **tracer_kwargs) elif tracer_type == 'wl': ntr = 2 tr = ccl.WeakLensingTracer(cosmo, dndz=(z, n), ia_bias=(z, b), **tracer_kwargs) elif tracer_type == 'cl': ntr = 1 tr = ccl.CMBLensingTracer(cosmo, 1100., **tracer_kwargs) else: ntr = 0 tr = ccl.Tracer(**tracer_kwargs) return tr, ntr
def get_tracer(tracer_type): z = np.linspace(0., 1., 2000) n = dndz(z) b = np.sqrt(1. + z) if tracer_type == 'nc': ntr = 3 tr = ccl.NumberCountsTracer(COSMO, True, dndz=(z, n), bias=(z, b), mag_bias=(z, b)) elif tracer_type == 'wl': ntr = 2 tr = ccl.WeakLensingTracer(COSMO, dndz=(z, n), ia_bias=(z, b)) elif tracer_type == 'cl': ntr = 1 tr = ccl.CMBLensingTracer(COSMO, 1100.) else: ntr = 0 tr = ccl.Tracer() return tr, ntr
def get_tracer(): chis = np.linspace(CHIMIN, CHIMAX, NCHI) ws = np.ones(NCHI) t = ccl.Tracer() t.add_tracer(COSMO, kernel=(chis, ws)) return t
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)