コード例 #1
0
    def test_workspace_covar_flat_benchmark(self):
        cw = nmt.NmtCovarianceWorkspaceFlat()
        cw.compute_coupling_coefficients(self.w, self.w)

        covar = nmt.gaussian_covariance_flat(cw, self.l, self.cltt, self.cltt,
                                             self.cltt, self.cltt)
        covar_bench = np.loadtxt("test/benchmarks/bm_f_nc_np_cov.txt",
                                 unpack=True)
        self.assertTrue(
            (np.fabs(covar - covar_bench) <=
             np.fmin(np.fabs(covar), np.fabs(covar_bench)) * 1E-5).all())
コード例 #2
0
    def test_workspace_covar_flat_errors(self):
        cw = nmt.NmtCovarianceWorkspaceFlat()

        with self.assertRaises(ValueError):  #Write uninitialized
            cw.write_to("wsp.dat")

        cw.compute_coupling_coefficients(self.w, self.w)  #All good
        self.assertEqual(cw.wsp.bin.n_bands, self.w.wsp.bin.n_bands)

        with self.assertRaises(RuntimeError):  #Write uninitialized
            cw.write_to("tests/wsp.dat")

        cw.read_from('test/benchmarks/bm_f_nc_np_cw00.dat')  #Correct reading
        self.assertEqual(cw.wsp.bin.n_bands, self.w.wsp.bin.n_bands)

        #gaussian_covariance
        with self.assertRaises(ValueError):  #Wrong input power spectra
            nmt.gaussian_covariance_flat(cw, self.l, self.cltt, self.cltt,
                                         self.cltt, self.cltt[:15])

        with self.assertRaises(RuntimeError):  #Incorrect reading
            cw.read_from('none')
        w2 = nmt.NmtWorkspaceFlat()
        w2.read_from("test/benchmarks/bm_f_nc_np_w00.dat")
        w2.wsp.fs.nx = self.w.wsp.fs.nx // 2
        with self.assertRaises(ValueError):  #Incompatible resolutions
            cw.compute_coupling_coefficients(self.w, w2)
        w2.wsp.fs.nx = self.w.wsp.fs.nx
        w2.wsp.bin.n_bands = self.w.wsp.bin.n_bands // 2
        with self.assertRaises(RuntimeError):  #Incompatible resolutions
            cw.compute_coupling_coefficients(self.w, w2)
        w2.wsp.bin.n_bands = self.w.wsp.bin.n_bands

        w2.read_from("test/benchmarks/bm_f_nc_np_w02.dat")
        with self.assertRaises(ValueError):  #Spin-2
            cw.compute_coupling_coefficients(self.w, w2)
コード例 #3
0
ファイル: power_specter.py プロジェクト: LSSTDESC/DEHSC_LSS
    def get_covar_analytic(self, lth, clth, bpws, tracers, wsp):
        """
        Estimate the power spectrum covariance analytically
        :param lth: list of multipoles.
        :param clth: list of guess power spectra sampled at the multipoles stored in `lth`.
        :param bpws: NaMaster bandpowers.
        :param tracers: tracers.
        :param wsp: NaMaster workspace.
        """
        #Create a dummy file for the covariance MCM
        f = open(self.get_output_fname('gaucov_sims', ext='npz'), "w")
        f.close()

        covar = np.zeros([self.ncross * self.nell, self.ncross * self.nell])
        cwsp = self.get_covar_mcm(tracers, bpws)

        ix_1 = 0
        for i1 in range(self.nbins):
            for j1 in range(i1, self.nbins):
                ix_2 = 0
                for i2 in range(self.nbins):
                    for j2 in range(i2, self.nbins):
                        ca1b1 = clth[self.ordering[i1, i2]]
                        ca1b2 = clth[self.ordering[i1, j2]]
                        ca2b1 = clth[self.ordering[j1, i2]]
                        ca2b2 = clth[self.ordering[j1, j2]]
                        cov_here = nmt.gaussian_covariance_flat(
                            cwsp, 0, 0, 0, 0, lth, [ca1b1], [ca1b2], [ca2b1],
                            [ca2b2], wsp)
                        covar[ix_1 * self.nell:(ix_1 + 1) *
                              self.nell, :][:, ix_2 * self.nell:(ix_2 + 1) *
                                            self.nell] = cov_here
                        ix_2 += 1
                ix_1 += 1

        return covar
コード例 #4
0
    def test_workspace_covar_flat_errors(self):
        cw = nmt.NmtCovarianceWorkspaceFlat()

        with self.assertRaises(ValueError):  # Write uninitialized
            cw.write_to("wsp.fits")

        cw.compute_coupling_coefficients(self.f0, self.f0, self.b)  # All good
        self.assertEqual(cw.wsp.bin.n_bands, self.w.wsp.bin.n_bands)

        with self.assertRaises(RuntimeError):  # Write uninitialized
            cw.write_to("tests/wsp.fits")

        cw.read_from('test/benchmarks/bm_f_nc_np_cw00.fits')  # Correct reading
        self.assertEqual(cw.wsp.bin.n_bands, self.w.wsp.bin.n_bands)

        # gaussian_covariance
        with self.assertRaises(ValueError):  # Wrong input power spectra
            nmt.gaussian_covariance_flat(cw, 0, 0, 0, 0, self.ll, [self.cltt],
                                         [self.cltt], [self.cltt],
                                         [self.cltt[:15]], self.w)
        with self.assertRaises(ValueError):  # Wrong input power shapes
            nmt.gaussian_covariance_flat(cw, 0, 0, 0, 0, self.ll,
                                         [self.cltt, self.cltt], [self.cltt],
                                         [self.cltt], [self.cltt[:15]], self.w)
        with self.assertRaises(ValueError):  # Wrong input spins
            nmt.gaussian_covariance_flat(cw, 0, 2, 0, 0, self.ll, [self.cltt],
                                         [self.cltt], [self.cltt], [self.cltt],
                                         self.w)

        with self.assertRaises(RuntimeError):  # Incorrect reading
            cw.read_from('none')
        with self.assertRaises(ValueError):  # Incompatible resolutions
            cw.compute_coupling_coefficients(self.f0, self.f0_half, self.b)
        with self.assertRaises(RuntimeError):  # Incompatible bandpowers
            cw.compute_coupling_coefficients(self.f0, self.f0, self.b, self.f0,
                                             self.f0, self.b_half)
コード例 #5
0
    def test_workspace_covar_flat_benchmark(self):
        def compare_covars(c, cb):
            # Check first and second diagonals
            for k in [0, 1]:
                d = np.diag(c, k=k)
                db = np.diag(cb, k=k)
                self.assertTrue(
                    (np.fabs(d - db) <=
                     np.fmin(np.fabs(d), np.fabs(db)) * 1E-4).all())

        cw = nmt.NmtCovarianceWorkspaceFlat()
        cw.compute_coupling_coefficients(self.f0, self.f0, self.b)

        # [0,0 ; 0,0]
        covar = nmt.gaussian_covariance_flat(cw, 0, 0, 0, 0, self.ll,
                                             [self.cltt], [self.cltt],
                                             [self.cltt], [self.cltt], self.w)
        covar_bench = np.loadtxt("test/benchmarks/bm_f_nc_np_cov.txt",
                                 unpack=True)
        compare_covars(covar, covar_bench)
        # [0,2 ; 0,2]
        covar = nmt.gaussian_covariance_flat(
            cw,
            0,
            2,
            0,
            2,
            self.ll, [self.cltt], [self.clte, 0 * self.clte],
            [self.clte, 0 * self.clte],
            [self.clee, 0 * self.clee, 0 * self.clee, self.clbb],
            self.w02,
            wb=self.w02)
        covar_bench = np.loadtxt("test/benchmarks/bm_f_nc_np_cov0202.txt")
        compare_covars(covar, covar_bench)
        # [0,0 ; 0,2]
        covar = nmt.gaussian_covariance_flat(cw,
                                             0,
                                             0,
                                             0,
                                             2,
                                             self.ll, [self.cltt],
                                             [self.clte, 0 * self.clte],
                                             [self.cltt],
                                             [self.clte, 0 * self.clte],
                                             self.w,
                                             wb=self.w02)
        covar_bench = np.loadtxt("test/benchmarks/bm_f_nc_np_cov0002.txt")
        compare_covars(covar, covar_bench)
        # [0,0 ; 2,2]
        covar = nmt.gaussian_covariance_flat(cw,
                                             0,
                                             0,
                                             2,
                                             2,
                                             self.ll,
                                             [self.clte, 0 * self.clte],
                                             [self.clte, 0 * self.clte],
                                             [self.clte, 0 * self.clte],
                                             [self.clte, 0 * self.clte],
                                             self.w,
                                             wb=self.w22)
        covar_bench = np.loadtxt("test/benchmarks/bm_f_nc_np_cov0022.txt")
        compare_covars(covar, covar_bench)
        # [2,2 ; 2,2]
        covar = nmt.gaussian_covariance_flat(
            cw,
            2,
            2,
            2,
            2,
            self.ll, [self.clee, 0 * self.clee, 0 * self.clee, self.clbb],
            [self.clee, 0 * self.clee, 0 * self.clee, self.clbb],
            [self.clee, 0 * self.clee, 0 * self.clee, self.clbb],
            [self.clee, 0 * self.clee, 0 * self.clee, self.clbb],
            self.w22,
            wb=self.w22)
        covar_bench = np.loadtxt("test/benchmarks/bm_f_nc_np_cov2222.txt")
        compare_covars(covar, covar_bench)
コード例 #6
0
w00.compute_coupling_matrix(f0, f0, b)
#Coupling matrix used to estimate angular spectrum
cl00_coupled = nmt.compute_coupled_cell_flat(f0, f0, b)
cl00_uncoupled = w00.decouple_cell(cl00_coupled)[0]
print(cl00_uncoupled)

amp = abs((ells_uncoupled**2) * cl00_uncoupled / (2 * np.pi))**(1 / 2)

print(
    "\n*************************  Covariance matrix  *************************************\n"
)

cw = nmt.NmtCovarianceWorkspaceFlat()
cw.compute_coupling_coefficients(f0, f0, b)
covar = nmt.gaussian_covariance_flat(cw, 0, 0, 0, 0, ells_uncoupled,
                                     [cl00_uncoupled], [cl00_uncoupled],
                                     [cl00_uncoupled], [cl00_uncoupled], w00)

print(covar)
std_power = (np.diag(covar))
std_amp = np.sqrt(abs((ells_uncoupled**2) * std_power / (2 * np.pi))**(1 / 2))

"--------------------------------- Fitting a power law -------------------------------------"

# def power_law(x,a,p):
#     return a*np.power(x,p)

# a_fit, p_fit = curve_fit(power_law, lambdas_inv, amp, p0 = [1e-2,5/3])[0]

# lambdas_inv_curve = np.linspace(min(lambdas_inv),max(lambdas_inv),100)
# curve = power_law(lambdas_inv_curve, a_fit,p_fit)
コード例 #7
0
_, sq = read_flat_map("tmp_flat.fits", 1)
_, su = read_flat_map("tmp_flat.fits", 2)

b = nmt.NmtBinFlat(ledges[:-1], ledges[1:])
leff = b.get_effective_ells()

#No contaminants
prefix = 'bm_f_nc_np'
f0 = nmt.NmtFieldFlat(lx, ly, msk, [dt])
f2 = nmt.NmtFieldFlat(lx, ly, msk, [dq, du])
w00 = nmt.NmtWorkspaceFlat()
w00.compute_coupling_matrix(f0, f0, b)
cw00 = nmt.NmtCovarianceWorkspaceFlat()
cw00.compute_coupling_coefficients(w00, w00)
cw00.write_to(prefix + '_cw00.dat')
cov = nmt.gaussian_covariance_flat(cw00, l, cltt + nltt, cltt + nltt,
                                   cltt + nltt, cltt + nltt)
np.savetxt(prefix + "_cov.txt", cov)
clb00 = w00.couple_cell(l, np.array([nltt]))
c00 = w00.decouple_cell(nmt.compute_coupled_cell_flat(f0, f0, b),
                        cl_bias=clb00)
w00.write_to(prefix + '_w00.dat')
np.savetxt(prefix + '_c00.txt', np.transpose([leff, c00[0]]))
w02 = nmt.NmtWorkspaceFlat()
w02.compute_coupling_matrix(f0, f2, b)
clb02 = w02.couple_cell(l, np.array([nlte, 0 * nlte]))
c02 = w02.decouple_cell(nmt.compute_coupled_cell_flat(f0, f2, b),
                        cl_bias=clb02)
w02.write_to(prefix + '_w02.dat')
np.savetxt(prefix + '_c02.txt', np.transpose([leff, c02[0], c02[1]]))
w22 = nmt.NmtWorkspaceFlat()
w22.compute_coupling_matrix(f2, f2, b)
コード例 #8
0
    w.compute_coupling_matrix(f0, f0, b)
    w.write_to("w_flat_covar.fits")
w.read_from("w_flat_covar.fits")
cl_0 = compute_master(f0, f0, w)[0]

# Let's now compute the Gaussian estimate of the covariance!
print("Covariance")
# First we generate a NmtCovarianceWorkspaceFlat object to precompute
# and store the necessary coupling coefficients
cw = nmt.NmtCovarianceWorkspaceFlat()
if not os.path.isfile("cw_flat.fits"):
    # This is the time-consuming operation
    cw.compute_coupling_coefficients(f0, f0, b)
    cw.write_to("cw_flat.fits")
cw.read_from("cw_flat.fits")
covar = nmt.gaussian_covariance_flat(cw, 0, 0, 0, 0, larr, [clarr], [clarr],
                                     [clarr], [clarr], w)

# Let's now compute the sample covariance
print("Sample covariance")
nsamp = 1000
covar_sample = np.zeros([len(cl_0), len(cl_0)])
mean_sample = np.zeros(len(cl_0))
for i in np.arange(nsamp):
    print(i)
    f = get_sample_field()
    cl = compute_master(f, f, w)[0]
    covar_sample += cl[None, :] * cl[:, None]
    mean_sample += cl
mean_sample /= nsamp
covar_sample = covar_sample / nsamp - mean_sample[None, :] * mean_sample[:,
                                                                         None]
コード例 #9
0
    w.compute_coupling_matrix(f0, f0, b)
    w.write_to("w_flat_covar.dat")
w.read_from("w_flat_covar.dat")
cl_0 = compute_master(f0, f0, w)[0]

#Let's now compute the Gaussian estimate of the covariance!
print("Covariance")
#First we generate a NmtCovarianceWorkspaceFlat object to precompute
#and store the necessary coupling coefficients
cw = nmt.NmtCovarianceWorkspaceFlat()
if not os.path.isfile("cw_flat.dat"):
    cw.compute_coupling_coefficients(
        w, w)  #<- Thisi is the time-consuming operation
    cw.write_to("cw_flat.dat")
cw.read_from("cw_flat.dat")
covar = nmt.gaussian_covariance_flat(cw, larr, clarr, clarr, clarr, clarr)

#Let's now compute the sample covariance
print("Sample covariance")
nsamp = 1000
covar_sample = np.zeros([len(cl_0), len(cl_0)])
mean_sample = np.zeros(len(cl_0))
for i in np.arange(nsamp):
    print(i)
    f = get_sample_field()
    cl = compute_master(f, f, w)[0]
    covar_sample += cl[None, :] * cl[:, None]
    mean_sample += cl
mean_sample /= nsamp
covar_sample = covar_sample / nsamp - mean_sample[None, :] * mean_sample[:,
                                                                         None]
コード例 #10
0
    def get_covar_analytic(self, lth, clth, bpws, tracers, wsp):
        """
        Estimate the power spectrum covariance analytically
        :param lth: list of multipoles.
        :param clth: list of guess power spectra sampled at the multipoles stored in `lth`.
        :param bpws: NaMaster bandpowers.
        :param tracers: tracers.
        :param wsp: NaMaster workspace.
        """
        # Create a dummy file for the covariance MCM
        f = open(self.get_output_fname('gaucov_analytic', ext='npz'), "w")
        f.close()

        covar = np.zeros([self.ncross, self.nbands, self.ncross, self.nbands])
        # Get covar MCM for counts tracers
        cwsp = self.get_covar_mcm(tracers, bpws)

        tracer_combs = []
        for i1 in range(self.ntracers):
            for j1 in range(i1, self.ntracers):
                tracer_combs.append((i1, j1))

        ix_1 = 0
        for k1, tup1 in enumerate(tracer_combs):
            tr_i1, tr_j1 = tup1
            ix_2 = ix_1
            for tr_i2, tr_j2 in tracer_combs[k1:]:
                ps_inds1 = self.tracers2maps[tr_i1][tr_i2]
                ps_inds2 = self.tracers2maps[tr_i1][tr_j2]
                ps_inds3 = self.tracers2maps[tr_j1][tr_i2]
                ps_inds4 = self.tracers2maps[tr_j1][tr_j2]

                ca1b1 = clth[ps_inds1[:, 0], ps_inds1[:, 1]]
                ca1b2 = clth[ps_inds2[:, 0], ps_inds2[:, 1]]
                ca2b1 = clth[ps_inds3[:, 0], ps_inds3[:, 1]]
                ca2b2 = clth[ps_inds4[:, 0], ps_inds4[:, 1]]

                cov_here = nmt.gaussian_covariance_flat(
                    cwsp[tr_i1][tr_j1][tr_i2][tr_j2], tracers[tr_i1].spin,
                    tracers[tr_j1].spin, tracers[tr_i2].spin,
                    tracers[tr_j2].spin, lth, ca1b1, ca1b2, ca2b1, ca2b2,
                    wsp[tr_i1][tr_j1], wsp[tr_i2][tr_j2])

                if set((tracers[tr_i1].spin, tracers[tr_j1].spin)) == set(
                    (0, 0)) and set(
                        (tracers[tr_i2].spin, tracers[tr_j2].spin)) == set(
                            (0, 0)):
                    covar[ix_1, :, ix_2, :] = cov_here
                    if (tr_i1, tr_j1) != (tr_i2, tr_j2):
                        covar[ix_2, :, ix_1, :] = cov_here.T
                    ix_2 += 1
                elif set((tracers[tr_i1].spin, tracers[tr_j1].spin)) == set(
                    (0, 2)) and set(
                        (tracers[tr_i2].spin, tracers[tr_j2].spin)) == set(
                            (0, 2)):
                    cov_here = cov_here.reshape(
                        [self.nbands, 2, self.nbands, 2])
                    cov_te_te = cov_here[:, 0, :, 0]
                    cov_te_tb = cov_here[:, 0, :, 1]
                    cov_tb_te = cov_here[:, 1, :, 0]
                    cov_tb_tb = cov_here[:, 1, :, 1]

                    covar[ix_1, :, ix_2, :] = cov_te_te
                    covar[ix_1, :, ix_2 + 1, :] = cov_te_tb
                    covar[ix_1 + 1, :, ix_2, :] = cov_tb_te
                    covar[ix_1 + 1, :, ix_2 + 1, :] = cov_tb_tb
                    if (tr_i1, tr_j1) != (tr_i2, tr_j2):
                        covar[ix_2, :, ix_1, :] = cov_te_te.T
                        covar[ix_2 + 1, :, ix_1, :] = cov_te_tb.T
                        covar[ix_2, :, ix_1 + 1, :] = cov_tb_te.T
                        covar[ix_2 + 1, :, ix_1 + 1, :] = cov_tb_tb.T
                    ix_2 += 2
                elif set((tracers[tr_i1].spin, tracers[tr_j1].spin)) == set(
                    (0, 0)) and set(
                        (tracers[tr_i2].spin, tracers[tr_j2].spin)) == set(
                            (0, 2)):
                    cov_here = cov_here.reshape(
                        [self.nbands, 1, self.nbands, 2])
                    cov_tt_te = cov_here[:, 0, :, 0]
                    cov_tt_tb = cov_here[:, 0, :, 1]

                    covar[ix_1, :, ix_2, :] = cov_tt_te
                    covar[ix_1, :, ix_2 + 1, :] = cov_tt_tb
                    if (tr_i1, tr_j1) != (tr_i2, tr_j2):
                        covar[ix_2, :, ix_1, :] = cov_tt_te.T
                        covar[ix_2 + 1, :, ix_1, :] = cov_tt_tb.T
                    ix_2 += 2
                elif set((tracers[tr_i1].spin, tracers[tr_j1].spin)) == set(
                    (0, 2)) and set(
                        (tracers[tr_i2].spin, tracers[tr_j2].spin)) == set(
                            (0, 0)):
                    cov_here = cov_here.reshape(
                        [self.nbands, 1, self.nbands, 2])
                    cov_tt_te = cov_here[:, 0, :, 0]
                    cov_tt_tb = cov_here[:, 0, :, 1]

                    covar[ix_1, :, ix_2, :] = cov_tt_te
                    covar[ix_1 + 1, :, ix_2, :] = cov_tt_tb
                    if (tr_i1, tr_j1) != (tr_i2, tr_j2):
                        covar[ix_2, :, ix_1, :] = cov_tt_te.T
                        covar[ix_2, :, ix_1 + 1, :] = cov_tt_tb.T
                    ix_2 += 1
                elif set((tracers[tr_i1].spin, tracers[tr_j1].spin)) == set(
                    (0, 0)) and set(
                        (tracers[tr_i2].spin, tracers[tr_j2].spin)) == set(
                            (2, 2)):
                    cov_here = cov_here.reshape(
                        [self.nbands, 1, self.nbands, 4])
                    cov_tt_ee = cov_here[:, 0, :, 0]
                    cov_tt_eb = cov_here[:, 0, :, 1]
                    cov_tt_be = cov_here[:, 0, :, 2]
                    cov_tt_bb = cov_here[:, 0, :, 3]

                    covar[ix_1, :, ix_2, :] = cov_tt_ee
                    covar[ix_1, :, ix_2 + 1, :] = cov_tt_eb
                    covar[ix_1, :, ix_2 + 2, :] = cov_tt_be
                    covar[ix_1, :, ix_2 + 3, :] = cov_tt_bb
                    if (tr_i1, tr_j1) != (tr_i2, tr_j2):
                        covar[ix_2, :, ix_1, :] = cov_tt_ee.T
                        covar[ix_2 + 1, :, ix_1, :] = cov_tt_eb.T
                        covar[ix_2 + 2, :, ix_1, :] = cov_tt_be.T
                        covar[ix_2 + 3, :, ix_1, :] = cov_tt_bb.T
                    ix_2 += 4
                elif set((tracers[tr_i1].spin, tracers[tr_j1].spin)) == set(
                    (2, 2)) and set(
                        (tracers[tr_i2].spin, tracers[tr_j2].spin)) == set(
                            (0, 0)):
                    cov_here = cov_here.reshape(
                        [self.nbands, 1, self.nbands, 4])
                    cov_tt_ee = cov_here[:, 0, :, 0]
                    cov_tt_eb = cov_here[:, 0, :, 1]
                    cov_tt_be = cov_here[:, 0, :, 2]
                    cov_tt_bb = cov_here[:, 0, :, 3]

                    covar[ix_1, :, ix_2, :] = cov_tt_ee
                    covar[ix_1 + 2, :, ix_2, :] = cov_tt_eb
                    covar[ix_1 + 2, :, ix_2, :] = cov_tt_be
                    covar[ix_1 + 3, :, ix_2, :] = cov_tt_bb
                    if (tr_i1, tr_j1) != (tr_i2, tr_j2):
                        covar[ix_2, :, ix_1, :] = cov_tt_ee.T
                        covar[ix_2, :, ix_1 + 2, :] = cov_tt_eb.T
                        covar[ix_2, :, ix_1 + 2, :] = cov_tt_be.T
                        covar[ix_2, :, ix_1 + 3, :] = cov_tt_bb.T
                    ix_2 += 1
                elif set((tracers[tr_i1].spin, tracers[tr_j1].spin)) == set(
                    (0, 2)) and set(
                        (tracers[tr_i2].spin, tracers[tr_j2].spin)) == set(
                            (2, 2)):
                    cov_here = cov_here.reshape(
                        [self.nbands, 2, self.nbands, 4])
                    cov_te_ee = cov_here[:, 0, :, 0]
                    cov_te_eb = cov_here[:, 0, :, 1]
                    cov_te_be = cov_here[:, 0, :, 2]
                    cov_te_bb = cov_here[:, 0, :, 3]
                    cov_tb_ee = cov_here[:, 1, :, 0]
                    cov_tb_eb = cov_here[:, 1, :, 1]
                    cov_tb_be = cov_here[:, 1, :, 2]
                    cov_tb_bb = cov_here[:, 1, :, 3]

                    covar[ix_1, :, ix_2, :] = cov_te_ee
                    covar[ix_1, :, ix_2 + 1, :] = cov_te_eb
                    covar[ix_1, :, ix_2 + 2, :] = cov_te_be
                    covar[ix_1, :, ix_2 + 3, :] = cov_te_bb
                    covar[ix_1 + 1, :, ix_2, :] = cov_tb_ee
                    covar[ix_1 + 1, :, ix_2 + 1, :] = cov_tb_eb
                    covar[ix_1 + 1, :, ix_2 + 2, :] = cov_tb_be
                    covar[ix_1 + 1, :, ix_2 + 3, :] = cov_tb_bb
                    if (tr_i1, tr_j1) != (tr_i2, tr_j2):
                        covar[ix_2, :, ix_1, :] = cov_te_ee.T
                        covar[ix_2 + 1, :, ix_1, :] = cov_te_eb.T
                        covar[ix_2 + 2, :, ix_1, :] = cov_te_be.T
                        covar[ix_2 + 3, :, ix_1, :] = cov_te_bb.T
                        covar[ix_2, :, ix_1 + 1, :] = cov_tb_ee.T
                        covar[ix_2 + 1, :, ix_1 + 1, :] = cov_tb_eb.T
                        covar[ix_2 + 2, :, ix_1 + 1, :] = cov_tb_be.T
                        covar[ix_2 + 3, :, ix_1 + 1, :] = cov_tb_bb.T
                    ix_2 += 4
                elif set((tracers[tr_i1].spin, tracers[tr_j1].spin)) == set(
                    (2, 2)) and set(
                        (tracers[tr_i2].spin, tracers[tr_j2].spin)) == set(
                            (0, 2)):
                    cov_here = cov_here.reshape(
                        [self.nbands, 2, self.nbands, 4])
                    cov_te_ee = cov_here[:, 0, :, 0]
                    cov_te_eb = cov_here[:, 0, :, 1]
                    cov_te_be = cov_here[:, 0, :, 2]
                    cov_te_bb = cov_here[:, 0, :, 3]
                    cov_tb_ee = cov_here[:, 1, :, 0]
                    cov_tb_eb = cov_here[:, 1, :, 1]
                    cov_tb_be = cov_here[:, 1, :, 2]
                    cov_tb_bb = cov_here[:, 1, :, 3]

                    covar[ix_1, :, ix_2, :] = cov_te_ee
                    covar[ix_1 + 1, :, ix_2, :] = cov_te_eb
                    covar[ix_1 + 2, :, ix_2, :] = cov_te_be
                    covar[ix_1 + 3, :, ix_2, :] = cov_te_bb
                    covar[ix_1, :, ix_2 + 1, :] = cov_tb_ee
                    covar[ix_1 + 1, :, ix_2 + 1, :] = cov_tb_eb
                    covar[ix_1 + 2, :, ix_2 + 1, :] = cov_tb_be
                    covar[ix_1 + 3, :, ix_2 + 1, :] = cov_tb_bb
                    if (tr_i1, tr_j1) != (tr_i2, tr_j2):
                        covar[ix_2, :, ix_1, :] = cov_te_ee.T
                        covar[ix_2, :, ix_1 + 1, :] = cov_te_eb.T
                        covar[ix_2, :, ix_1 + 2, :] = cov_te_be.T
                        covar[ix_2, :, ix_1 + 3, :] = cov_te_bb.T
                        covar[ix_2 + 1, :, ix_1, :] = cov_tb_ee.T
                        covar[ix_2 + 1, :, ix_1 + 1, :] = cov_tb_eb.T
                        covar[ix_2 + 1, :, ix_1 + 2, :] = cov_tb_be.T
                        covar[ix_2 + 1, :, ix_1 + 3, :] = cov_tb_bb.T
                    ix_2 += 2
                else:
                    cov_here = cov_here.reshape(
                        [self.nbands, 4, self.nbands, 4])
                    cov_ee_ee = cov_here[:, 0, :, 0]
                    cov_ee_eb = cov_here[:, 0, :, 1]
                    cov_ee_be = cov_here[:, 0, :, 2]
                    cov_ee_bb = cov_here[:, 0, :, 3]
                    cov_eb_ee = cov_here[:, 1, :, 0]
                    cov_eb_eb = cov_here[:, 1, :, 1]
                    cov_eb_be = cov_here[:, 1, :, 2]
                    cov_eb_bb = cov_here[:, 1, :, 3]
                    cov_be_ee = cov_here[:, 2, :, 0]
                    cov_be_eb = cov_here[:, 2, :, 1]
                    cov_be_be = cov_here[:, 2, :, 2]
                    cov_be_bb = cov_here[:, 2, :, 3]
                    cov_bb_ee = cov_here[:, 3, :, 0]
                    cov_bb_eb = cov_here[:, 3, :, 1]
                    cov_bb_be = cov_here[:, 3, :, 2]
                    cov_bb_bb = cov_here[:, 3, :, 3]

                    covar[ix_1, :, ix_2, :] = cov_ee_ee
                    covar[ix_1, :, ix_2 + 1, :] = cov_ee_eb
                    covar[ix_1, :, ix_2 + 2, :] = cov_ee_be
                    covar[ix_1, :, ix_2 + 3, :] = cov_ee_bb
                    covar[ix_1 + 1, :, ix_2, :] = cov_eb_ee
                    covar[ix_1 + 1, :, ix_2 + 1, :] = cov_eb_eb
                    covar[ix_1 + 1, :, ix_2 + 2, :] = cov_eb_be
                    covar[ix_1 + 1, :, ix_2 + 3, :] = cov_eb_bb
                    covar[ix_1 + 2, :, ix_2, :] = cov_be_ee
                    covar[ix_1 + 2, :, ix_2 + 1, :] = cov_be_eb
                    covar[ix_1 + 2, :, ix_2 + 2, :] = cov_be_be
                    covar[ix_1 + 2, :, ix_2 + 3, :] = cov_be_bb
                    covar[ix_1 + 3, :, ix_2, :] = cov_bb_ee
                    covar[ix_1 + 3, :, ix_2 + 1, :] = cov_bb_eb
                    covar[ix_1 + 3, :, ix_2 + 2, :] = cov_bb_be
                    covar[ix_1 + 3, :, ix_2 + 3, :] = cov_bb_bb
                    if (tr_i1, tr_j1) != (tr_i2, tr_j2):
                        covar[ix_2, :, ix_1, :] = cov_ee_ee.T
                        covar[ix_2 + 1, :, ix_1, :] = cov_ee_eb.T
                        covar[ix_2 + 2, :, ix_1, :] = cov_ee_be.T
                        covar[ix_2 + 3, :, ix_1, :] = cov_ee_bb.T
                        covar[ix_2, :, ix_1 + 1, :] = cov_eb_ee.T
                        covar[ix_2 + 1, :, ix_1 + 1, :] = cov_eb_eb.T
                        covar[ix_2 + 2, :, ix_1 + 1, :] = cov_eb_be.T
                        covar[ix_2 + 3, :, ix_1 + 1, :] = cov_eb_bb.T
                        covar[ix_2, :, ix_1 + 2, :] = cov_be_ee.T
                        covar[ix_2 + 1, :, ix_1 + 2, :] = cov_be_eb.T
                        covar[ix_2 + 2, :, ix_1 + 2, :] = cov_be_be.T
                        covar[ix_2 + 3, :, ix_1 + 2, :] = cov_be_bb.T
                        covar[ix_2, :, ix_1 + 3, :] = cov_bb_ee.T
                        covar[ix_2 + 1, :, ix_1 + 3, :] = cov_bb_eb.T
                        covar[ix_2 + 2, :, ix_1 + 3, :] = cov_bb_be.T
                        covar[ix_2 + 3, :, ix_1 + 3, :] = cov_bb_bb.T
                    ix_2 += 4
            if set((tracers[tr_i1].spin, tracers[tr_j1].spin)) == set(
                (0, 0)) and set(
                    (tracers[tr_i2].spin, tracers[tr_j2].spin)) == set((0, 0)):
                ix_1 += 1

            elif set((tracers[tr_i1].spin, tracers[tr_j1].spin)) == set(
                (0, 0)) and set(
                    (tracers[tr_i2].spin, tracers[tr_j2].spin)) == set((0, 2)):
                ix_1 += 1
            elif set((tracers[tr_i1].spin, tracers[tr_j1].spin)) == set(
                (0, 2)) and set(
                    (tracers[tr_i2].spin, tracers[tr_j2].spin)) == set((0, 0)):
                ix_1 += 2

            elif set((tracers[tr_i1].spin, tracers[tr_j1].spin)) == set(
                (0, 2)) and set(
                    (tracers[tr_i2].spin, tracers[tr_j2].spin)) == set((0, 2)):
                ix_1 += 2

            elif set((tracers[tr_i1].spin, tracers[tr_j1].spin)) == set(
                (0, 0)) and set(
                    (tracers[tr_i2].spin, tracers[tr_j2].spin)) == set((2, 2)):
                ix_1 += 1
            elif set((tracers[tr_i1].spin, tracers[tr_j1].spin)) == set(
                (2, 2)) and set(
                    (tracers[tr_i2].spin, tracers[tr_j2].spin)) == set((0, 0)):
                ix_1 += 4

            elif set((tracers[tr_i1].spin, tracers[tr_j1].spin)) == set(
                (0, 2)) and set(
                    (tracers[tr_i2].spin, tracers[tr_j2].spin)) == set((2, 2)):
                ix_1 += 2
            elif set((tracers[tr_i1].spin, tracers[tr_j1].spin)) == set(
                (2, 2)) and set(
                    (tracers[tr_i2].spin, tracers[tr_j2].spin)) == set((0, 2)):
                ix_1 += 4

            else:
                ix_1 += 4

        covar = covar.reshape(
            [self.ncross * self.nbands, self.ncross * self.nbands])

        return covar
コード例 #11
0
        if o.covar_coup != 'NONE':
            cwsp.write_to(o.covar_coup)
    else:
        cwsp.read_from(o.covar_coup)

    ix_1 = 0
    for i1 in range(nbins):
        for j1 in range(i1, nbins):
            ix_2 = 0
            for i2 in range(nbins):
                for j2 in range(i2, nbins):
                    ca1b1 = clth[ordering[i1, i2]]
                    ca1b2 = clth[ordering[i1, j2]]
                    ca2b1 = clth[ordering[j1, i2]]
                    ca2b2 = clth[ordering[j1, j2]]
                    cov_here = nmt.gaussian_covariance_flat(
                        cwsp, lth, ca1b1, ca1b2, ca2b1, ca2b2)
                    covar[ix_1 * n_ell:(ix_1 + 1) *
                          n_ell, :][:,
                                    ix_2 * n_ell:(ix_2 + 1) * n_ell] = cov_here
                    ix_2 += 1
            ix_1 += 1

elif o.covar_opt == 'gaus_sim':
    #Read theory power spectra
    raise ValueError("Gaussian simulations not implemented yet")
    '''
  covar=Non
  data=np.loadtxt(o.cl_theory,unpack=True)
  lth=data[0]
  clth=data[1:]
  if len(clth)!=n_cross :