def check_cls(cosmo): """ Check that cls functions can be run. """ # Number density input z = np.linspace(0., 1., 200) n = np.ones(z.shape) # Bias input b = np.sqrt(1. + z) # ell range input ell_scl = 4 ell_lst = [2, 3, 4, 5, 6, 7, 8, 9] ell_arr = np.arange(2, 10) # ClTracer test objects lens1 = ccl.ClTracerLensing(cosmo, False, n=n, z=z) lens2 = ccl.ClTracerLensing(cosmo, True, n=(z,n), bias_ia=(z,n), f_red=(z,n)) nc1 = ccl.ClTracerNumberCounts(cosmo, False, False, n=(z,n), bias=(z,b)) nc2 = ccl.ClTracerNumberCounts(cosmo, True, False, n=(z,n), bias=(z,b)) nc3 = ccl.ClTracerNumberCounts(cosmo, True, True, n=(z,n), bias=(z,b), mag_bias=(z,b)) cmbl=ccl.ClTracerCMBLensing(cosmo,1100.) # Check valid ell input is accepted assert_( all_finite(ccl.angular_cl(cosmo, lens1, lens1, ell_scl)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens1, lens1, ell_lst)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens1, lens1, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc1, nc1, ell_scl)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc1, nc1, ell_lst)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc1, nc1, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, cmbl, cmbl, ell_arr)) ) # Check various cross-correlation combinations assert_( all_finite(ccl.angular_cl(cosmo, lens1, lens2, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens1, nc1, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens1, nc2, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens1, nc3, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens1, cmbl, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens2, nc1, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens2, nc2, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens2, nc3, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens2, cmbl, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc1, nc2, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc1, nc3, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc1, cmbl, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc2, nc3, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc2, cmbl, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc3, cmbl, ell_arr)) ) # Check that reversing order of ClTracer inputs works assert_( all_finite(ccl.angular_cl(cosmo, nc1, lens1, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc1, lens2, ell_arr)) )
clt_dlo_n12b = ccl.ClTracerNumberCounts(cosmo, False, False, (zarr_dlo_n12b, nzarr_dlo_n12b), (zarr_dlo_n12b, bzarr_dlo_n12b)) clt_qso_n12b = ccl.ClTracerNumberCounts(cosmo, False, False, (zarr_qso_n12b, nzarr_qso_n12b), (zarr_qso_n12b, bzarr_qso_n12b)) clt_dlo_g16 = ccl.ClTracerNumberCounts(cosmo, False, False, (zarr_dlo_g16, nzarr_dlo_g16), (zarr_dlo_g16, bzarr_dlo_g16)) clt_qso_g16 = ccl.ClTracerNumberCounts(cosmo, False, False, (zarr_qso_g16, nzarr_qso_g16), (zarr_qso_g16, bzarr_qso_g16)) clt_qsu = ccl.ClTracerNumberCounts(cosmo, False, False, (zarr_qsu, nzarr_qsu), (zarr_qsu, bzarr_qsu)) clt_cmbl = ccl.ClTracerCMBLensing(cosmo) larr_b = np.concatenate((1. * np.arange(500), 500 + 10 * np.arange(950))) cl_dc_n12 = ccl.angular_cl(cosmo, clt_dlo_n12, clt_cmbl, larr_b, l_limber=-1) cl_qc_n12 = ccl.angular_cl(cosmo, clt_qso_n12, clt_cmbl, larr_b, l_limber=-1) cl_dc_n12b = ccl.angular_cl(cosmo, clt_dlo_n12b, clt_cmbl, larr_b,
def check_cls_nu(cosmo): """ Check that cls functions can be run. """ # Number density input z = np.linspace(0., 1., 200) n = np.exp(-((z-0.5)/0.1)**2) # Bias input b = np.sqrt(1. + z) # ell range input ell_scl = 4 ell_lst = [2, 3, 4, 5, 6, 7, 8, 9] ell_arr = np.arange(2, 10) # Check if power spectrum type is valid for CMB cmb_ok = True if cosmo.configuration.matter_power_spectrum_method \ == ccl.core.matter_power_spectrum_types['emu']: cmb_ok = False # ClTracer test objects lens1 = ccl.ClTracerLensing(cosmo, False, n=n, z=z) lens2 = ccl.ClTracerLensing(cosmo, True, n=(z,n), bias_ia=(z,n), f_red=(z,n)) nc1 = ccl.ClTracerNumberCounts(cosmo, False, False, n=(z,n), bias=(z,b)) # Check that for massive neutrinos including rsd raises an error (not yet implemented) assert_raises(RuntimeError, ccl.ClTracerNumberCounts, cosmo, True, False, n=(z,n), bias=(z,b)) cmbl=ccl.ClTracerCMBLensing(cosmo,1100.) # Check valid ell input is accepted assert_( all_finite(ccl.angular_cl(cosmo, lens1, lens1, ell_scl)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens1, lens1, ell_lst)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens1, lens1, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc1, nc1, ell_scl)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc1, nc1, ell_lst)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc1, nc1, ell_arr)) ) if cmb_ok: assert_( all_finite(ccl.angular_cl(cosmo, cmbl, cmbl, ell_arr)) ) # Check various cross-correlation combinations assert_( all_finite(ccl.angular_cl(cosmo, lens1, lens2, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens1, nc1, ell_arr)) ) if cmb_ok: assert_( all_finite(ccl.angular_cl(cosmo, lens1, cmbl, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens2, nc1, ell_arr)) ) if cmb_ok: assert_( all_finite(ccl.angular_cl(cosmo, lens2, cmbl, ell_arr)) ) if cmb_ok: assert_( all_finite(ccl.angular_cl(cosmo, nc1, cmbl, ell_arr)) ) # Check that reversing order of ClTracer inputs works assert_( all_finite(ccl.angular_cl(cosmo, nc1, lens1, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc1, lens2, ell_arr)) ) # Check get_internal_function() a_scl = 0.5 a_lst = [0.2, 0.4, 0.6, 0.8, 1.] a_arr = np.linspace(0.2, 1., 5) assert_( all_finite(nc1.get_internal_function(cosmo, 'dndz', a_scl)) ) assert_( all_finite(nc1.get_internal_function(cosmo, 'dndz', a_lst)) ) assert_( all_finite(nc1.get_internal_function(cosmo, 'dndz', a_arr)) ) # Check that invalid options raise errors assert_raises(KeyError, nc1.get_internal_function, cosmo, 'x', a_arr) assert_raises(ValueError, ccl.ClTracerNumberCounts, cosmo, True, True, n=(z,n), bias=(z,b)) assert_raises(KeyError, ccl.ClTracer, cosmo, 'x', True, True, n=(z,n), bias=(z,b)) assert_raises(ValueError, ccl.ClTracerLensing, cosmo, has_intrinsic_alignment=True, n=(z,n), bias_ia=(z,n)) assert_no_warnings(ccl.cls._cltracer_obj, nc1) assert_no_warnings(ccl.cls._cltracer_obj, nc1.cltracer) assert_raises(TypeError, ccl.cls._cltracer_obj, None)
def check_cls(cosmo): """ Check that cls functions can be run. """ # Number density input z = np.linspace(0., 1., 200) n = np.exp(-((z-0.5)/0.1)**2) # Bias input b = np.sqrt(1. + z) # ell range input ell_scl = 4 ell_lst = [2, 3, 4, 5, 6, 7, 8, 9] ell_arr = np.arange(2, 10) # Check if power spectrum type is valid for CMB cmb_ok = True if cosmo.configuration.matter_power_spectrum_method \ == ccl.core.matter_power_spectrum_types['emu']: cmb_ok = False # ClTracer test objects lens1 = ccl.ClTracerLensing(cosmo, False, n=n, z=z) lens2 = ccl.ClTracerLensing(cosmo, True, n=(z,n), bias_ia=(z,n), f_red=(z,n)) nc1 = ccl.ClTracerNumberCounts(cosmo, False, False, n=(z,n), bias=(z,b)) nc2 = ccl.ClTracerNumberCounts(cosmo, True, False, n=(z,n), bias=(z,b)) nc3 = ccl.ClTracerNumberCounts(cosmo, True, True, n=(z,n), bias=(z,b), mag_bias=(z,b)) cmbl=ccl.ClTracerCMBLensing(cosmo,1100.) # Check valid ell input is accepted assert_( all_finite(ccl.angular_cl(cosmo, lens1, lens1, ell_scl)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens1, lens1, ell_lst)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens1, lens1, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc1, nc1, ell_scl)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc1, nc1, ell_lst)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc1, nc1, ell_arr)) ) if cmb_ok: assert_( all_finite(ccl.angular_cl(cosmo, cmbl, cmbl, ell_arr)) ) # Check non-limber calculations assert_( all_finite(ccl.angular_cl(cosmo, nc1, nc1, ell_arr, l_limber=20, non_limber_method="native"))) assert_( all_finite(ccl.angular_cl(cosmo, nc1, nc1, ell_arr, l_limber=20, non_limber_method="angpow"))) # Check various cross-correlation combinations assert_( all_finite(ccl.angular_cl(cosmo, lens1, lens2, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens1, nc1, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens1, nc2, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens1, nc3, ell_arr)) ) if cmb_ok: assert_( all_finite(ccl.angular_cl(cosmo, lens1, cmbl, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens2, nc1, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens2, nc2, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, lens2, nc3, ell_arr)) ) if cmb_ok: assert_( all_finite(ccl.angular_cl(cosmo, lens2, cmbl, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc1, nc2, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc1, nc3, ell_arr)) ) if cmb_ok: assert_( all_finite(ccl.angular_cl(cosmo, nc1, cmbl, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc2, nc3, ell_arr)) ) if cmb_ok: assert_( all_finite(ccl.angular_cl(cosmo, nc2, cmbl, ell_arr)) ) if cmb_ok: assert_( all_finite(ccl.angular_cl(cosmo, nc3, cmbl, ell_arr)) ) # Check that reversing order of ClTracer inputs works assert_( all_finite(ccl.angular_cl(cosmo, nc1, lens1, ell_arr)) ) assert_( all_finite(ccl.angular_cl(cosmo, nc1, lens2, ell_arr)) ) # Wrong non limber method assert_raises(KeyError, ccl.angular_cl, cosmo, lens1, lens1, ell_scl, non_limber_method='xx')
zarr_dlo, nzarr_dlo = get_nz_oversample(bn, nz, 256) bzarr_dlo = bdla * np.ones_like(zarr_dlo) nz, bins = np.histogram(data_dla['zqso'], range=[0, 7], bins=50) zarr_qso, nzarr_qso = get_nz_oversample(bn, nz, 256) bzarr_qso = bqso * np.ones_like(zarr_qso) cosmo = ccl.Cosmology(Omega_c=0.27, Omega_b=0.045, h=0.69, sigma8=0.83, n_s=0.96) clt_dlo = ccl.ClTracerNumberCounts(cosmo, False, False, (zarr_dlo, nzarr_dlo), (zarr_dlo, bzarr_dlo)) clt_qso = ccl.ClTracerNumberCounts(cosmo, False, False, (zarr_qso, nzarr_qso), (zarr_qso, bzarr_qso)) clt_cmbl = ccl.ClTracerCMBLensing(cosmo, z_source=1100.) def get_fisher(xp): ll = np.arange(xp.lmin, xp.lmax) cl_dd = ccl.angular_cl(cosmo, clt_dlo, clt_dlo, ll) #,l_limber=-1) cl_dq = ccl.angular_cl(cosmo, clt_dlo, clt_qso, ll) #,l_limber=-1) cl_dc = ccl.angular_cl(cosmo, clt_dlo, clt_cmbl, ll) #,l_limber=-1) cl_qq = ccl.angular_cl(cosmo, clt_qso, clt_qso, ll) #,l_limber=-1) cl_qc = ccl.angular_cl(cosmo, clt_qso, clt_cmbl, ll) #,l_limber=-1) cl_cc = ccl.angular_cl(cosmo, clt_cmbl, clt_cmbl, ll) #,l_limber=-1) cl_aa = cl_dd + 2 * cl_dq + cl_qq cl_aq = cl_dq + cl_qq cl_ac = cl_dc + cl_qc nl_dd = cl_dd + xp.cl_noise_dla(ll) nl_dc = cl_dc
dla_z.append(float(d)) qso_z.append(float(q)) dz = .01 rdshift = np.arange(0, 7.2, dz) n_dla = stats.gaussian_kde(dla_z, bw_method=0.1)(rdshift) n_qso = stats.gaussian_kde(qso_z, bw_method=0.1)(rdshift) #set ccl parameters parameters = ccl.Parameters(Omega_c=0.27, Omega_b=0.045, h=0.69, sigma8=0.83, n_s=0.96) cosmo = ccl.Cosmology(parameters) lens = ccl.ClTracerCMBLensing(cosmo) #use ccl to predict cls bias_qso = np.ones(rdshift.size) bias_dla = np.ones(rdshift.size) b = nmt.NmtBin(2048, nlb=bsize) ell_arr = b.get_effective_ells() source_dla = ccl.ClTracerNumberCounts(cosmo, False, False, z=rdshift, n=n_dla, bias=bias_dla) theory_dla = ccl.angular_cl(cosmo, lens, source_dla, ell_arr, l_limber=-1)