def check_corr(cosmo):

    # Number density input
    z = np.linspace(0., 1., 200)
    n = np.ones(z.shape)

    # 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))

    ells = np.arange(3000)
    cls = ccl.angular_cl(cosmo, lens1, lens2, ells)

    t = np.logspace(-2, np.log10(5.), 20)  #degrees
    corrfunc = ccl.correlation(cosmo,
                               ells,
                               cls,
                               t,
                               corr_type='L+',
                               method='FFTLog')
    assert_(all_finite(corrfunc))
Beispiel #2
0
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)) )
Beispiel #3
0
def test_two_point_some(kind, tmpdir):

    cosmo = ccl.Cosmology(Omega_c=0.27,
                          Omega_b=0.045,
                          Omega_k=0.0,
                          w0=-1.0,
                          wa=0.0,
                          sigma8=0.8,
                          n_s=0.96,
                          h=0.67)

    sources = {}
    for i, mn in enumerate([0.25, 0.75]):
        sources['src%d' % i] = DummySource()
        z = np.linspace(0, 2, 50)
        nz = np.exp(-0.5 * (z - mn)**2 / 0.25 / 0.25)

        if ('g' in kind and i == 0) or kind == 'gg':
            sources['src%d' % i].tracer_ = ccl.ClTracerNumberCounts(
                cosmo,
                has_rsd=False,
                has_magnification=False,
                z=z,
                n=nz,
                bias=np.ones_like(z) * 2.0)
        else:
            sources['src%d' % i].tracer_ = ccl.ClTracerLensing(
                cosmo, has_intrinsic_alignment=False, z=z, n=nz)

        sources['src%d' % i].scale_ = i / 2.0 + 1.0

    # compute the statistic
    tracers = [v.tracer_ for k, v in sources.items()]
    scale = np.prod([v.scale_ for k, v in sources.items()])
    data = os.path.join(tmpdir, 'stat.csv')
    if kind == 'cl':
        ell = np.logspace(1, 3, 10)
        cell = ccl.angular_cl(cosmo, *tracers, ell) * scale
        pd.DataFrame({'l': ell, 'cl': cell}).to_csv(data, index=False)
    else:
        theta = np.logspace(1, 2, 100)
        ell = _ell_for_xi()
        cell = ccl.angular_cl(cosmo, *tracers, ell)
        xi = ccl.correlation(cosmo, ell, cell, theta / 60.0,
                             corr_type=kind) * scale
        pd.DataFrame({'t': theta, 'xi': xi}).to_csv(data, index=False)

    stat = TwoPointStatistic(data=data, kind=kind, sources=['src0', 'src1'])
    stat.compute(cosmo, {}, sources, systematics=None)

    if kind == 'cl':
        assert np.allclose(stat.measured_statistic_, cell)
    else:
        assert np.allclose(stat.measured_statistic_, xi)

    assert np.allclose(stat.measured_statistic_, stat.predicted_statistic_)
def setup_data():
    """Set up data for test."""
    pi = np.pi

    # Set up ccl cosmology object
    cosmo = ccl.Cosmology(Omega_c=0.25,
                          Omega_b=0.05,
                          n_s=0.96,
                          sigma8=0.8,
                          h=0.7)

    # Set up a simple n(z)
    z = np.linspace(0., 1., 50)
    n = np.exp(-((z - 0.5) / 0.1)**2)

    lens_tracer = ccl.ClTracerLensing(cosmo, False, n=n, z=z)

    # Set up ell and get Cl's
    ell = np.arange(2, 4000, dtype=np.float64)
    Cl = ccl.angular_cl(cosmo, lens_tracer, lens_tracer, ell)

    # Set up theta
    theta_min = 0.6 / 60  # degree
    theta_max = 600.0 / 60  # degree
    n_theta = 100

    theta = np.logspace(np.log10(theta_min),
                        np.log10(theta_max),
                        n_theta,
                        endpoint=True)

    # Get CCL xi's
    xi_plus = ccl.correlation(cosmo,
                              ell,
                              Cl,
                              theta,
                              corr_type="L+",
                              method="fftlog")
    xi_minus = ccl.correlation(cosmo,
                               ell,
                               Cl,
                               theta,
                               corr_type="L-",
                               method="fftlog")

    # Get FFTLog xi's
    xi_plus_fftlog = fftlog.Cl2xi(Cl, ell, theta, bessel_order=0)
    xi_minus_fftlog = fftlog.Cl2xi(Cl, ell, theta, bessel_order=4)

    return (xi_plus_fftlog, xi_minus_fftlog), (xi_plus, xi_minus), (theta,
                                                                    theta)
Beispiel #5
0
    def render(self, cosmo, params, systematics=None):
        """
        Render a source by applying systematics.

        Parameters
        ----------
        cosmo : pyccl.Cosmology
            A pyccl.Cosmology object.
        params : dict
            A dictionary mapping parameter names to their current values.
        systematics : dict
            A dictionary mapping systematic names to their objects. The
            default of `None` corresponds to no systematics.
        """
        systematics = systematics or {}

        self.z_ = self._z_orig.copy()
        self.nz_ = self._nz_orig.copy()
        self.scale_ = self.scale
        if self.has_intrinsic_alignment:
            self.f_red_ = np.ones_like(self.z_) * params[self.f_red]
            self.bias_ia_ = np.ones_like(self.z_) * params[self.bias_ia]

        for systematic in self.systematics:
            systematics[systematic].apply(cosmo, params, self)

        if self.has_intrinsic_alignment:
            tracer = ccl.ClTracerLensing(cosmo,
                                         has_intrinsic_alignment=True,
                                         n=(self.z_, self.nz_),
                                         bias_ia=(self.z_, self.bias_ia_),
                                         f_red=(self.z_, self.f_red_))
        else:
            tracer = ccl.ClTracerLensing(cosmo,
                                         has_intrinsic_alignment=False,
                                         n=(self.z_, self.nz_))
        self.tracer_ = tracer
def check_corr(cosmo):
    
    # Number density input
    z = np.linspace(0., 1., 200)
    n = np.ones(z.shape)

    # 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))

    ells = np.arange(3000)
    cls = ccl.angular_cl(cosmo, lens1, lens2, ells)

    t_arr = np.logspace(-2., np.log10(5.), 20) # degrees
    t_lst = [t for t in t_arr]
    t_scl = 2.
    t_int = 2
    
    # Make sure correlation functions work for valid inputs
    corr1 = ccl.correlation(cosmo, ells, cls, t_arr, corr_type='L+', 
                            method='FFTLog')
    corr2 = ccl.correlation(cosmo, ells, cls, t_lst, corr_type='L+', 
                            method='FFTLog')
    corr3 = ccl.correlation(cosmo, ells, cls, t_scl, corr_type='L+', 
                            method='FFTLog')
    corr4 = ccl.correlation(cosmo, ells, cls, t_int, corr_type='L+', 
                            method='FFTLog')
    assert_( all_finite(corr1))
    assert_( all_finite(corr2))
    assert_( all_finite(corr3))
    assert_( all_finite(corr4))
    
    # Check that exceptions are raised for invalid input
    assert_raises(KeyError, ccl.correlation, cosmo, ells, cls, t_arr, 
                  corr_type='xx', method='FFTLog')
    assert_raises(KeyError, ccl.correlation, cosmo, ells, cls, t_arr, 
                  corr_type='L+', method='xx')
Beispiel #7
0
def get_theory(var):
    #Get cosmological parameters
    var_tot = get_cosmo(var)
    #Cosmology
    cosmo = ccl.Cosmology(h=var_tot[0],
                          Omega_c=var_tot[1] / var_tot[0]**2.,
                          Omega_b=var_tot[2] / var_tot[0]**2.,
                          A_s=(10.**(-10.)) * np.exp(var_tot[3]),
                          n_s=var_tot[4])
    #Tracers
    lens = np.array([
        ccl.ClTracerLensing(cosmo,
                            False,
                            z=z.astype(np.float64),
                            n=pz[x].astype(np.float64)) for x in range(n_bins)
    ])
    #Cl's
    ell = np.arange(n_ells)
    cls = np.zeros((n_bins, n_bins, n_ells))
    for count1 in range(n_bins):
        for count2 in range(n_bins):
            cls[count1, count2] = ccl.angular_cl(cosmo, lens[count1],
                                                 lens[count2], ell)
    cls = np.transpose(cls, axes=[2, 0, 1])
    #Correlation function
    xi_th = np.zeros((2, n_bins, n_bins, n_theta))
    for count1 in range(n_bins):
        for count2 in range(n_bins):
            for count3 in range(n_theta):
                xi_th[0, count1, count2,
                      count3] = ccl.correlation(cosmo,
                                                ell,
                                                cls[:, count1, count2],
                                                theta[count3],
                                                corr_type='L+',
                                                method='FFTLog')
                xi_th[1, count1, count2,
                      count3] = ccl.correlation(cosmo,
                                                ell,
                                                cls[:, count1, count2],
                                                theta[count3],
                                                corr_type='L-',
                                                method='FFTLog')
    xi_th = np.transpose(xi_th, axes=[0, 3, 1, 2])
    #Reshape and eventually KL transform
    if is_kl:
        xi_th = kl_transform(xi_th, datat='corr')
    xi_th = reshape(xi_th, datat='corr')
    return xi_th
Beispiel #8
0
    cov_mat[p_pm_1,p_theta_1,p_j_1,p_i_1,p_pm_2,p_theta_2,p_i_2,p_j_2] = cov_file[count]
    cov_mat[p_pm_1,p_theta_1,p_j_1,p_i_1,p_pm_2,p_theta_2,p_j_2,p_i_2] = cov_file[count]
#Check that the covariance matrix is symmetric
check_symm(cov_mat, (0, 1, 2, 3, 4, 5, 7, 6))
check_symm(cov_mat, (0, 1, 3, 2, 4, 5, 6, 7))
check_symm(cov_mat, (0, 1, 3, 2, 4, 5, 7, 6))
check_symm(cov_mat, (4, 5, 6, 7, 0, 1, 2, 3))
print 'Read covariance matrix'
sys.stdout.flush()


#Calculate theory correlation function
#Cosmology
cosmo = ccl.Cosmology(Omega_c=vrs.Omega_c, Omega_b=vrs.Omega_b, h=vrs.h, sigma8=vrs.sigma8, n_s=vrs.n_s)
#Tracers
lens = np.array([ccl.ClTracerLensing(cosmo, False, z=z.astype(np.float64), n=pz[x].astype(np.float64)) for x in range(n_bins)])
#Cl's
ell = np.arange(n_ells)
cls = np.zeros((n_bins, n_bins, n_ells))
for count1 in range(n_bins):
    for count2 in range(n_bins):
        cls[count1,count2] = ccl.angular_cl(cosmo, lens[count1], lens[count2], ell)
cls = np.transpose(cls,axes=[2,0,1])
#Correlation function
xi_th = np.zeros((2, n_bins, n_bins, n_theta))
for count1 in range(n_bins):
    for count2 in range(n_bins):
        for count3 in range(n_theta):
            xi_th[0,count1,count2,count3] = ccl.correlation(cosmo, ell, cls[:,count1,count2], theta[count3], corr_type='L+', method='FFTLog')
            xi_th[1,count1,count2,count3] = ccl.correlation(cosmo, ell, cls[:,count1,count2], theta[count3], corr_type='L-', method='FFTLog')
xi_th = np.transpose(xi_th,axes=[0,3,1,2])
Beispiel #9
0
    raise IOError('Input arrays have disagreeing shapes. z.shape = ' +
                  str(z.shape) + '. pz.shape = ' + str(pz.shape) + '.')

#Calculate cosmology
cosmo = ccl.Cosmology(Omega_c=vrs.Omega_c,
                      Omega_b=vrs.Omega_b,
                      h=vrs.h,
                      sigma8=vrs.sigma8,
                      n_s=vrs.n_s)  #A_s=vrs.A_s
print 'Calculated cosmology'
sys.stdout.flush()

#Calculate tracers
lens = np.array([
    ccl.ClTracerLensing(cosmo,
                        False,
                        z=z.astype(np.float64),
                        n=pz[x].astype(np.float64)) for x in range(len(pz))
])
print 'Calculated tracers'
sys.stdout.flush()

#Calculate Cl's
angular_cl = np.zeros((len(pz), len(pz), vrs.L_MAX + 1))
for count1 in range(len(pz)):
    for count2 in range(len(pz)):
        angular_cl[count1][count2] = ccl.angular_cl(cosmo, lens[count1],
                                                    lens[count2],
                                                    range(vrs.L_MAX + 1))
angular_cl = np.swapaxes(angular_cl, 2, 0)
print 'Calculated Cl\'s'
sys.stdout.flush()
Beispiel #10
0
def tx_data(tmpdir_factory):
    tmpdir = str(tmpdir_factory.mktemp("data"))

    cosmo = ccl.Cosmology(
        Omega_c=0.27,
        Omega_b=0.045,
        Omega_k=0.0,
        w0=-1.0,
        wa=0.0,
        sigma8=0.8,
        n_s=0.96,
        h=0.67)

    seed = 42
    rng = np.random.RandomState(seed=seed)
    eps = 0.01

    tracers = []
    for i, mn in enumerate([0.25, 0.75]):
        z = np.linspace(0, 2, 50)
        nz = np.exp(-0.5 * (z - mn)**2 / 0.25 / 0.25)

        df = pd.DataFrame({'z': z, 'nz': nz})
        df.to_csv(
            os.path.join(tmpdir, 'pz%d.csv' % i),
            index=False)

        tracers.append(ccl.ClTracerLensing(
            cosmo,
            has_intrinsic_alignment=False,
            z=z,
            n=nz))

    dv = []
    ndv = []
    for i in range(len(tracers)):
        for j in range(i, len(tracers)):
            ell = np.logspace(1, 4, 10)
            pell = ccl.angular_cl(cosmo, tracers[i], tracers[j], ell)
            npell = pell + rng.normal(size=pell.shape[0]) * eps * pell

            df = pd.DataFrame({'l': ell, 'cl': npell})
            df.to_csv(
                os.path.join(tmpdir, 'cl%d%d.csv' % (i, j)),
                index=False)
            dv.append(pell)
            ndv.append(npell)

    # a fake covariance matrix
    dv = np.concatenate(dv, axis=0)
    ndv = np.concatenate(ndv, axis=0)
    nelts = len(tracers) * (len(tracers) + 1) // 2
    cov = np.identity(len(pell) * nelts)
    for i in range(len(dv)):
        cov[i, i] *= (eps * dv[i]) ** 2
    assert len(dv) == cov.shape[0]
    _i = []
    _j = []
    _val = []
    for i in range(cov.shape[0]):
        for j in range(cov.shape[1]):
            _i.append(i)
            _j.append(j)
            _val.append(cov[i, j])
    df = pd.DataFrame({'i': _i, 'j': _j, 'cov': _val})
    df.to_csv(
        os.path.join(tmpdir, 'cov.csv'),
        index=False)

    cinv = np.linalg.inv(cov)
    delta = ndv - dv
    loglike = -0.5 * np.dot(delta, np.dot(cinv, delta))

    config = """\
parameters:
  Omega_k: 0.0
  Omega_c: 0.27
  Omega_b: 0.045
  h: 0.67
  n_s: 0.96
  sigma8: 0.8
  w0: -1.0
  wa: 0.0

  # lens bin zero
  src0_delta_z: 0.0
  src1_delta_z: 0.0

two_point:
  module: firecrown.ccl.two_point
  sources:
    src0:
      kind: WLSource
      nz_data: {tmpdir}/pz0.csv
      has_intrinsic_alignment: False
      systematics:
        - pz_delta_0

    src1:
      kind: WLSource
      nz_data: {tmpdir}/pz1.csv
      has_intrinsic_alignment: False
      systematics:
        - pz_delta_1

  systematics:
    pz_delta_0:
      kind: PhotoZShiftBias
      delta_z: src0_delta_z

    pz_delta_1:
      kind: PhotoZShiftBias
      delta_z: src1_delta_z

  likelihood:
    kind: ConstGaussianLogLike
    data: {tmpdir}/cov.csv
    data_vector:
      - cl_src0_src0
      - cl_src0_src1
      - cl_src1_src1

  statistics:
    cl_src0_src0:
      sources: ['src0', 'src0']
      kind: 'cl'
      data: {tmpdir}/cl00.csv

    cl_src0_src1:
      sources: ['src0', 'src1']
      kind: 'cl'
      data: {tmpdir}/cl01.csv

    cl_src1_src1:
      sources: ['src1', 'src1']
      kind: 'cl'
      data: {tmpdir}/cl11.csv""".format(tmpdir=tmpdir)

    with open(os.path.join(tmpdir, 'config.yaml'), 'w') as fp:
        fp.write(config)

    return {
        'cosmo': cosmo,
        'tmpdir': tmpdir,
        'loglike': loglike,
        'config': config}
Beispiel #11
0
if not os.path.isfile('cls_flat.txt'):
    import pyccl as ccl
    z = np.linspace(0.2, 1.2, 256)
    pz = np.exp(-((z - 0.7) / 0.1)**2)
    bz = np.ones_like(z)
    plt.figure()
    plt.plot(z, pz)
    plt.xlabel('$z$', fontsize=16)
    plt.ylabel('$p(z)$', fontsize=16)
    cosmo = ccl.Cosmology(Omega_c=0.27,
                          Omega_b=0.045,
                          h=0.67,
                          A_s=2.1e-9,
                          n_s=0.96)
    clust = ccl.ClTracerNumberCounts(cosmo, False, False, z=z, n=pz, bias=bz)
    lens = ccl.ClTracerLensing(cosmo, False, z=z, n=pz)
    ell = np.arange(20000)
    cltt = ccl.angular_cl(cosmo, clust, clust, ell)
    clte = ccl.angular_cl(cosmo, clust, lens, ell)
    clee = ccl.angular_cl(cosmo, lens, lens, ell)
    clbb = np.zeros_like(clee)

    np.savetxt("cls_flat.txt", np.transpose([ell, cltt, clee, clbb, clte]))
ell, cltt, clee, clbb, clte = np.loadtxt("cls_flat.txt", unpack=True)
cltt[0] = 0
clee[0] = 0
clbb[0] = 0
clte[0] = 0
if plotres:
    plt.figure()
    plt.plot(ell, cltt, 'r-', label='$\\delta_g-\\delta_g$')
Beispiel #12
0
seed = 42
tmpdir = '.'
rng = np.random.RandomState(seed=seed)
eps = 0.01

tracers = []
for i, mn in enumerate([0.25, 0.75]):
    z = np.linspace(0, 2, 50)
    nz = np.exp(-0.5 * (z - mn)**2 / 0.25 / 0.25)

    df = pd.DataFrame({'z': z, 'nz': nz})
    df.to_csv(os.path.join(tmpdir, 'pz%d.csv' % i), index=False)

    tracers.append(
        ccl.ClTracerLensing(cosmo, has_intrinsic_alignment=False, z=z, n=nz))

dv = []
ndv = []
for i in range(len(tracers)):
    for j in range(i, len(tracers)):
        ell = np.logspace(1, 4, 10)
        pell = ccl.angular_cl(cosmo, tracers[i], tracers[j], ell)
        npell = pell + rng.normal(size=pell.shape[0]) * eps * pell

        df = pd.DataFrame({'l': ell, 'cl': npell})
        df.to_csv(os.path.join(tmpdir, 'cl%d%d.csv' % (i, j)), index=False)
        dv.append(pell)
        ndv.append(npell)

# a fake covariance matrix
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')