Beispiel #1
0
    def load_kernel(self, block, kernel_name, kernel_dict):
        # the name is of the form N_SAMPLENAME or W_SAMPLENAME, or K_SAMPLENAME
        kernel_type = kernel_name[0]
        sample_name = "nz_" + kernel_name[2:]
        if kernel_name[2:] == names.wl_number_density:
            sample_name = names.wl_number_density

        if kernel_type == "K":
            nbin = 1
        else:
            z = block[sample_name, 'z']
            nbin = block[sample_name, 'nbin']

        # Now load n(z) or W(z) for each bin in the range
        for i in range(nbin):
            if kernel_type == "N":
                kernel = limber.get_named_nchi_spline(
                    block, sample_name, i + 1, z, self.a_of_chi, self.chi_of_z)
            elif kernel_type == "W":
                kernel = limber.get_named_w_spline(
                    block, sample_name, i + 1, z, self.chi_max, self.a_of_chi)
            elif kernel_type == "K":
                if self.chi_star is None:
                    raise ValueError(
                        "Need to calculate chistar (comoving distance to last scattering) e.g. with camb to use CMB lensing.")
                kernel = limber.get_cmb_kappa_spline(
                    self.chi_max, self.chi_star, self.a_of_chi)
            else:
                raise ValueError("Unknown kernel type {0} ({1})".format(
                    kernel_type, kernel_name))
            if kernel is None:
                raise ValueError("Could not load one of the W(z) or n(z) splines needed for limber integral (name={}, type={}, bin={})".format(
                    kernel_name, kernel_type, i + 1))
            kernel_dict[i] = kernel
Beispiel #2
0
    def get_combined_shear_ia_spline(self, block, kernel_name, sample_name, i,
                                     z):
        # Get basic W spline that this thing starts from.
        # Might have it already or need to make it fresh (and store it)
        W_kernel_name = "W_" + kernel_name[2:]
        W_dict = self.kernels_A[W_kernel_name]
        W = W_dict.get(i)
        if W is None:
            print(sample_name, i + 1)
            W = limber.get_named_w_spline(block, sample_name, i + 1, z,
                                          self.chi_max, self.a_of_chi)
            if W is None:
                raise ValueError(
                    "Could not load the W(z) splines needed for limber integral (fast shear+IA, name={} bin={})"
                    .format(sample_name, i + 1))
            W_dict[i] = W

        # This one is quick to calculate so I won't mess around caching it
        N = limber.get_named_nchi_spline(block, sample_name, i + 1, z,
                                         self.a_of_chi, self.chi_of_z)

        # Check that the P_II(k,z) does not
        z1, k1, P_II = block.get_grid(names.intrinsic_power, "z", "k_h", "p_k")
        z2, k2, P_GI = block.get_grid(names.matter_intrinsic_power, "z", "k_h",
                                      "p_k")
        assert np.allclose(
            k1, k2
        ), "Non-matching PII and PGI in the  Fast Shear+IA C_ell calculator"
        assert np.allclose(
            z1, z2
        ), "Non-matching PII and PGI in the  Fast Shear+IA C_ell calculator"

        chi = self.chi_of_z(z)
        chi1 = self.chi_of_z(z1)

        if (P_GI[:, 0] == 0).all():
            # If there are no intrinsic alignments we can just use W
            kernel = W
        else:
            F1 = P_II[:, 0] / P_GI[:, 0]
            F_test = P_II[:, -1] / P_GI[:, -1]
            assert np.allclose(
                F1, F_test
            ), "Scale dependent IA cannot be used with Fast Shear+IA C_ell calculator"
            F = GSLSpline(chi1, F1)
            Q = W(chi) + F(chi) * N(chi) / lensing_prefactor(block)
            kernel = GSLSpline(chi, Q)

        return kernel