示例#1
0
def test_bins_constant():
    # Tests constant bandpower initialization
    assert (BT.bc.get_n_bands() == (BT.lmax - 2)//BT.nlb)
    assert (BT.bc.get_ell_list(5)[2] == 2+BT.nlb*5+2)
    b = nmt.NmtBin(nside=1024, nlb=4, lmax=2000)
    assert (b.bin.ell_max == 2000)
示例#2
0
lTh = f['ls']
clTh = (f['cls'] + f['nls'])
clTh_all = (f['cls'] + f['nls'])[np.triu_indices(f['cls'].shape[0])]

fmasks = ["data/mask_lss_sph1.fits", "data/mask_lss_sph1.fits"]

mask_lss_ar = []

for fmask in fmasks:
    mask_lss = hp.ud_grade(hp.read_map(fmask, verbose=False), nside_out=nside)
    mask_lss_ar.append(mask_lss)

#Set up binning scheme
fsky = np.mean(np.product(mask_lss_ar, axis=0))
d_ell = int(1. / fsky)
b = nmt.NmtBin(nside, nlb=d_ell)

if not os.path.isfile(run_path + '_ells.txt'):
    np.savetxt(run_path + '_ells.txt', b.get_effective_ells())

##############################################################################
##############################################################################
##############################################################################

w00 = nmt.NmtWorkspace()
w02 = nmt.NmtWorkspace()
w22 = nmt.NmtWorkspace()

w00.read_from(run_path + "_w00_11.dat")
w02.read_from(run_path + "_w02_11.dat")
w22.read_from(run_path + "_w22_11.dat")
示例#3
0
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)

source_qso = ccl.ClTracerNumberCounts(cosmo,
                                      False,
                                      False,
                                      z=rdshift,
                                      n=n_qso,
示例#4
0
#     check = des_maps[i] / (des_N_mean * des_mask) - 1
#     check[np.isnan(check)] = 0
#
#     print(np.all(mapi == check))
#
# ###### Test ######

if o.plot_stuff:
    hp.mollview(des_mask)
    for mapi in des_maps_dg:
        hp.mollview(mapi)

#Set up binning scheme
fsky = np.mean(des_mask)
d_ell = int(1. / fsky)
b = nmt.NmtBin(des_nside, nlb=d_ell)


#Generate an initial simulation
def get_fields(maps_dg):
    """
    Generate a simulated field.
    It returns two NmtField objects for a spin-0 and a spin-2 field.

    :param fsk: a fm.FlatMapInfo object.
    :param mask: a sky mask.
    :param w_cont: deproject any contaminants? (not implemented yet)
    """
    fields = []
    for mapi in maps_dg:
        fields.append(nmt.NmtField(des_mask, [mapi]))
示例#5
0
 def test_bins_constant(self):
     # Tests constant bandpower initialization
     self.assertEqual(self.bc.get_n_bands(), (self.lmax - 2)//self.nlb)
     self.assertEqual(self.bc.get_ell_list(5)[2], 2+self.nlb*5+2)
     b = nmt.NmtBin(nside=1024, nlb=4, lmax=2000)
     self.assertEqual(b.bin.ell_max, 2000)
示例#6
0
            posterior = pebbles.Posterior(lkl, fit, pwr, NSIDE, sim, cos, ins, nmc=NMC)
            samples = posterior.load_samples()
            # calculate summary statistics
            mean = np.mean(samples, axis=0)
            median = np.median(samples, axis=0)
            std = np.std(samples, axis=0)
            # calculate marginalized quantities and bin them in histograms for quicker
            # plotting
            np.savetxt(_plot_dir / "{:s}.txt".format(posterior.meta.simulation_tag), np.array([mean, median, std]))        

    if STEPS.cross:
        # Loop through the cleaned simulations and calculate the cross spectrum with
        # foreground templates.
        print("Cross correlating with synchrotron and dust templates.")
        mask = pebbles.configurations.masking.so_mask_hits(NSIDE)
        nmtbin = nmt.NmtBin(NSIDE, nlb=20)
        beam = pebbles.powerspectra.beam_profile(NSIDE, 30.)
        for sim, cos, ins, fit in JOBS('SIMSETS', 'COSMOLOGIES', 'INSTRUMENTS', 'FITTING_MODELS'):
            s1 = pysm.nominal.models('s1', NSIDE)[0]
            sync = nmt.NmtField(mask, [s1['A_Q'], s1['A_U']], purify_b=True)
            d1 = pysm.nominal.models('d1', NSIDE)[0]
            dust = nmt.NmtField(mask, [d1['A_Q'], d1['A_U']], purify_b=True)
            wsp = nmt.NmtWorkspace()
            wsp.compute_coupling_matrix(dust, sync, nmtbin)
            peb = pebbles.Pebbles(NSIDE, sim, cos, ins, nmc=NMC)
            cls_dust = np.zeros((NMC, 4, nmtbin.get_n_bands()))
            cls_sync = np.zeros((NMC, 4, nmtbin.get_n_bands()))
            for imc in tqdm(range(NMC), ncols=82):
                qu = np.zeros((2, 12 * NSIDE ** 2))
                qu[0] += peb.load_cleaned_amp_maps(fit, 'cmb', 'q', imc)
                qu[1] += peb.load_cleaned_amp_maps(fit, 'cmb', 'u', imc)
                 nside_out=nside_out)
sw_q = hp.ud_grade(hp.read_map(
    "../../sandbox_validation/data/cont_wl_psf_ns64.fits",
    field=0,
    verbose=False),
                   nside_out=nside_out)
sw_u = hp.ud_grade(hp.read_map(
    "../../sandbox_validation/data/cont_wl_psf_ns64.fits",
    field=1,
    verbose=False),
                   nside_out=nside_out)
hp.write_map("msk.fits", mask, overwrite=True)
hp.write_map("mps.fits", [dl, dw_q, dw_u], overwrite=True)
hp.write_map("tmp.fits", [sl, sw_q, sw_u], overwrite=True)

b = nmt.NmtBin(nside_out, nlb=16)
leff = b.get_effective_ells()
lfull = np.arange(3 * nside_out)

#No contaminants
prefix = 'bm_nc_np'
f0 = nmt.NmtField(mask, [dl])
f2 = nmt.NmtField(mask, [dw_q, dw_u])
w00 = nmt.NmtWorkspace()
w00.compute_coupling_matrix(f0, f0, b)
cw00 = nmt.NmtCovarianceWorkspace()
cw00.compute_coupling_coefficients(w00, w00)
cw00.write_to(prefix + '_cw00.dat')
cov = nmt.gaussian_covariance(cw00, (cltt + nltt)[:3 * nside_out],
                              (cltt + nltt)[:3 * nside_out],
                              (cltt + nltt)[:3 * nside_out],
示例#8
0
                                             field=[0, 1],
                                             verbose=False)
    #PSF
    fgp[1, 0, :], fgp[1, 1, :] = hp.read_map("data/cont_wl_ss_ns%d.fits" %
                                             o.nside_out,
                                             field=[0, 1],
                                             verbose=False)
    #Small-scales
    if o.plot_stuff:
        hp.mollview(np.sum(fgt, axis=0)[0, :] * mask)
        hp.mollview(np.sum(fgp, axis=0)[0, :] * mask)
        hp.mollview(np.sum(fgp, axis=0)[1, :] * mask)

#Binning scheme
d_ell = int(1. / fsky)
b = nmt.NmtBin(o.nside_out, nlb=d_ell)

#Generate some initial fields
print(" - Res: %.3lf arcmin. " %
      (np.sqrt(4 * np.pi *
               (180 * 60 / np.pi)**2 / hp.nside2npix(o.nside_out))))


def get_fields():
    #Signal
    st, sq, su = hp.synfast([cltt, clee, clbb, clte],
                            o.nside_out,
                            new=True,
                            verbose=False,
                            pol=True)
    #Inhomogeneous white noise
示例#9
0
import numpy as np
import healpy as hp
import matplotlib.pyplot as mp
import pymaster as nmt
from numpy import pi
from qubic import (plot_spectra, read_spectra)


nside = 512
b = nmt.NmtBin(nside, nlb=20, is_Dell=True)
leff = b.get_effective_ells()
# input spectra
spectra = read_spectra(0.01)

# pixwin corrections
pw = hp.pixwin(nside, pol=True)
pw = [pw[0][:3 * nside], pw[1][:3 * nside]]
pwb2 = b.bin_cell(np.array(pw))
pwb3 = pwb2 / (leff * (leff + 1)) * 2 * pi

# read the files with the reconstructed l*(l+1)*Cl
cl_mean = hp.read_cl('cls_BBEE_512.fits')
cl_std = hp.read_cl('scls_BBEE_512.fits')

fact = leff * (leff + 1) / (2 * np.pi)
kw_Xpol = {'fmt': 'bo', 'markersize': 3}
mp.figure()
mp.title('BB')
plot_spectra(spectra[2], color='g', label='Input Spectra')
mp.errorbar(leff, cl_mean[3] / (pwb3[1] * pwb3[1]), cl_std[3] / (pwb3[1] * pwb3[1]), label='Pure-$B$ Estimator',
            fmt='r.')