示例#1
0
def fts(result, lmin, lmax, deltal):
    shape,wcs, delta, modlmap = list(result.values())
    fc = omaps.FourierCalc(shape,wcs)
    p2d,kgal,_ = fc.power2d(delta)
    bin_edges = np.arange(lmin, lmax, deltal)
    binner = stats.bin2D(modlmap,bin_edges)
    cents, p1d = binner.bin(p2d)
    result = OrderedDict([('cents', cents), ('p1d', p1d)])
    return result
示例#2
0
def init_geometry(ishape,iwcs):
    modlmap = enmap.modlmap(ishape,iwcs)
    bin_edges = np.arange(args.kellmin,args.kellmax,args.dell)
    binner = stats.bin2D(modlmap,bin_edges)
    if args.beam<1e-5:
        kbeam = None
    else:
        kbeam = maps.gauss_beam(modlmap,args.beam)
    lmax = modlmap.max()
    ells = np.arange(2,lmax,1)
    wnoise_TT = ells*0.+(args.noise*(np.pi/180./60.))**2.
    wnoise_PP = 2.*wnoise_TT
    nT = modlmap*0.+(args.noise*(np.pi/180./60.))**2.
    nP = 2.*nT
    ncomp = 3 if pol else 1
    ps = np.zeros((ncomp,ncomp,ells.size))
    ps[0,0] = wnoise_TT
    if pol:
        ps[1,1] = wnoise_PP
        ps[2,2] = wnoise_PP
    oshape = (3,)+ishape if pol else ishape

    if not(args.flat) and args.noise_pad>1.e-5:
        # Pad noise sim geometry
        pad_width_deg = args.noise_pad
        pad_width = pad_width_deg * np.pi/180.
        res = maps.resolution(oshape[-2:],iwcs)
        pad_pixels = int(pad_width/res)
        template = enmap.zeros(oshape,iwcs)
        btemplate = enmap.pad(template,pad_pixels)
        bshape,bwcs = btemplate.shape,btemplate.wcs
        del template
        del btemplate
        ngen = maps.MapGen(bshape,bwcs,ps)
    else:
        ngen = maps.MapGen(oshape,iwcs,ps)
    
    tmask = maps.mask_kspace(ishape,iwcs,lmin=args.tellmin,lmax=args.tellmax)
    pmask = maps.mask_kspace(ishape,iwcs,lmin=args.pellmin,lmax=args.pellmax)
    kmask = maps.mask_kspace(ishape,iwcs,lmin=args.kellmin,lmax=args.kellmax)

    qest = lensing.qest(ishape,iwcs,theory,noise2d=nT,beam2d=kbeam,kmask=tmask,noise2d_P=nP,kmask_P=pmask,kmask_K=kmask,pol=pol,grad_cut=None,unlensed_equals_lensed=True)

    taper,w2 = maps.get_taper_deg(ishape,iwcs,taper_width_degrees = args.taper_width,pad_width_degrees = args.pad_width)
    fc = maps.FourierCalc(oshape,iwcs,iau=args.iau)

    
    purifier = maps.Purify(ishape,iwcs,taper) if args.purify else None

    
    return qest,ngen,kbeam,binner,taper,fc,purifier
示例#3
0
 def __init__(self,
              shape,
              wcs,
              beams,
              rmss,
              lknees,
              alphas,
              aniss,
              inhoms,
              nsplits,
              plancks,
              response_dict,
              ps_dict,
              ellmin=100):
     """
     TODO: inhomogenity
     noise cross covariance
     """
     self.fc = maps.FourierCalc(shape, wcs)
     self.narrays = len(beams)
     self.modlmap = enmap.modlmap(shape, wcs)
     self.beams = beams
     self.inhoms = inhoms
     self.nsplits = nsplits
     self.plancks = plancks.astype(np.bool)
     self.ngens = []
     antemplate = covtools.get_anisotropic_noise_template(shape, wcs)
     for rms, lknee, alpha, anis in zip(rmss, lknees, alphas, aniss):
         if anis:
             template = antemplate.copy()
         else:
             template = 1
         p2d = covtools.rednoise(enmap.modlmap(shape, wcs), rms, lknee,
                                 alpha) * template
         p2d[self.modlmap < ellmin] = 0
         self.ngens.append(maps.MapGen(shape, wcs, p2d[None, None, ...]))
     self.fgens = {}
     assert "cmb" in ps_dict.keys()
     self.components = ps_dict.keys()
     for key in ps_dict.keys():
         self.fgens[key] = maps.MapGen(shape, wcs, ps_dict[key][None, None,
                                                                ...])
     self.shape = shape
     self.wcs = wcs
     self.rdict = response_dict
     self.ellmin = ellmin
示例#4
0
imap = mgen.get_map()

bmap2 = maps.convolve_gaussian(imap.copy(),fwhm=fwhm,nsigma=5.0)
print(bmap2.shape)

bmap = maps.filter_map(imap.copy(),kbeam)

taper,w2 = maps.get_taper(shape)

io.plot_img(imap*taper,io.dout_dir+"bmap0.png",high_res=True)
io.plot_img(bmap*taper,io.dout_dir+"bmap1.png",high_res=True)
io.plot_img(bmap2*taper,io.dout_dir+"bmap2.png",high_res=True)

bin_edges = np.arange(200,3000,100)
binner = stats.bin2D(modlmap,bin_edges)
fc = maps.FourierCalc(shape,wcs)
p2d,_,_ = fc.power2d(imap*taper)
cents,p1di = binner.bin(p2d/w2)
p2d,_,_ = fc.power2d(bmap*taper)
cents,p1db = binner.bin(p2d/w2)
p2d,_,_ = fc.power2d(bmap2*taper)
cents,p1db2 = binner.bin(p2d/w2)

pl = io.Plotter(yscale='log')
pl.add(ells,ps[0,0]*ells**2.)
pl.add(ells,ps[0,0]*ells**2.*maps.gauss_beam(ells,fwhm)**2.)
pl.add(cents,p1di*cents**2.)
pl.add(cents,p1db*cents**2.,label="fourier")
pl.add(cents,p1db2*cents**2.,label="real")
pl._ax.set_xlim(2,3000)
pl._ax.set_ylim(1e-12,1e-8)
示例#5
0
args = parser.parse_args()

# Load dictionary of array specs from yaml file
config = tutils.Config(arrays=args.arrays.split(','))

narrays = len(arrays)
freqs = []
for i in range(narrays):
    f = config.darrays[arrays[i]]['freq']
    freqs.append(f)

# Get the common map geometry from the coadd map of the first array
shape, wcs = enmap.read_fits_geometry(coaddfname(0))
Ny, Nx = shape[-2:]
# Set up a fourier space calculator (for power spectra)
fc = maps.FourierCalc(shape[-2:], wcs)

modlmap = enmap.modlmap(shape, wcs)
lmax = 5000
ells = modlmap[modlmap < lmax].reshape(-1)  # unraveled disk
nells = ells.size

Scov = np.zeros((narrays, narrays, nells))
Ncov = np.zeros((narrays, narrays, nells))

for aindex1 in range(narrays):
    for aindex2 in range(aindex1, narrays):

        print("Noise calc...")
        scov, ncov, autos = ncalc(
            aindex1, aindex2
out_dir = args.output_dir
mask = enmap.read_map(out_dir + args.field.upper() + "_mask_2arc.hdf")

# What is the geometry of this field?
shape, wcs = mask.shape, mask.wcs
shape = (3, ) + shape

# Set up a GRF generator
mg = maps.MapGen(shape, wcs, ps)
# Get wavenumbers
modlmap = enmap.modlmap(shape, wcs)
print("Lmax: ", modlmap.max())
print("Unmasked area sq.deg.: ", mask.area() * (180. / np.pi)**2.)

# Set up a power-spectrum-doer
fc = maps.FourierCalc(shape, wcs, iau=iau)

# And a binner
bin_edges = np.arange(40, 3000, 100)
binner = stats.bin2D(modlmap, bin_edges)
binit = lambda x: binner.bin(x)[1]
cents = binner.centers
#ells_coupled = cents

# === ENMAP TO NAMASTER ===
# get the extent and shape of our geometry
Ly, Lx = enmap.extent(shape, wcs)
Ny, Nx = shape[-2:]

if not (do_mask):
    mask = mask * 0. + 1.
示例#7
0
                                             get_dimensionless=False)

ls, nls = np.loadtxt("nlkk.dat", usecols=[0, 1], unpack=True)
clkk = theory.gCl('kk', ls)
ellrange = np.arange(0, 6000, 1)
totcls = interp1d(ls, clkk + nls, bounds_error=False,
                  fill_value="extrapolate")(ellrange)
ps = totcls.reshape((1, 1, ellrange.size))
bshape, bwcs = maps.rect_geometry(width_deg=80.,
                                  px_res_arcmin=2.0,
                                  height_deg=15.)
tap_per = 1. / 40. * 100.
pad_per = 1. / 40. * 100.

mg = maps.MapGen(bshape, bwcs, ps)
fc = maps.FourierCalc(bshape, bwcs)

taper, w2 = maps.get_taper(bshape,
                           taper_percent=tap_per,
                           pad_percent=pad_per,
                           weight=None)

bmap = mg.get_map()

#io.plot_img(bmap*taper,"map.png",high_res=True)

# bin_edges = np.arange(100,5000,100)
# binner = stats.bin2D(enmap.modlmap(bshape,bwcs),bin_edges)
# cents, bp1d = binner.bin(fc.power2d(bmap*taper)[0]/w2)

# pl = io.Plotter(yscale='log')
示例#8
0
def test_shear():
    from orphics import lensing, io, cosmology, maps

    deg = 20.
    px = 2.0
    tellmin = 30
    tellmax = 3500
    kellmin = 10
    kellmax = 3000
    bin_width = 20
    beam_arcmin = 1.4
    noise_uk_arcmin = 7.0

    theory = cosmology.default_theory(lpad=30000)
    shape, wcs = s.rect_geometry(width_deg=deg, px_res_arcmin=px)
    flsims = lensing.FlatLensingSims(shape, wcs, theory, beam_arcmin,
                                     noise_uk_arcmin)
    kbeam = flsims.kbeam
    modlmap = enmap.modlmap(shape, wcs)
    fc = maps.FourierCalc(shape, wcs)
    n2d = (noise_uk_arcmin * np.pi / 180. / 60.)**2. / flsims.kbeam**2.
    tmask = s.mask_kspace(shape, wcs, lmin=tellmin, lmax=tellmax)
    kmask = s.mask_kspace(shape, wcs, lmin=kellmin, lmax=kellmax)
    bin_edges = np.arange(kellmin, kellmax, bin_width)
    binner = s.bin2D(modlmap, bin_edges)
    i = 0
    unlensed, kappa, lensed, beamed, noise_map, observed = flsims.get_sim(
        seed_cmb=(i, 1),
        seed_kappa=(i, 2),
        seed_noise=(i, 3),
        lens_order=5,
        return_intermediate=True)
    _, kmap, _ = fc.power2d(observed)
    pii2d, kinput, _ = fc.power2d(kappa)

    feed_dict = {}
    cltt = theory.lCl('TT', modlmap)
    feed_dict['uC_T_T'] = theory.lCl('TT', modlmap)
    feed_dict['tC_T_T'] = (cltt + n2d)
    feed_dict['X'] = kmap / kbeam
    feed_dict['Y'] = kmap / kbeam

    ells = np.arange(0, 10000, 1)
    ucltt = theory.lCl('TT', ells)
    feed_dict['duC_T_T'] = s.interp(ells,
                                    np.gradient(np.log(ucltt),
                                                np.log(ells)))(modlmap)
    sAl = s.A_l(shape, wcs, feed_dict, "shear", "TT", xmask=tmask, ymask=tmask)
    sNl = s.N_l(shape,
                wcs,
                feed_dict,
                "shear",
                "TT",
                xmask=tmask,
                ymask=tmask,
                Al=sAl)
    sukappa = s.unnormalized_quadratic_estimator(shape,
                                                 wcs,
                                                 feed_dict,
                                                 "shear",
                                                 "TT",
                                                 xmask=tmask,
                                                 ymask=tmask)
    snkappa = sAl * sukappa

    pir2d3 = fc.f2power(snkappa, kinput)
    cents, pir1d3 = binner.bin(pir2d3)
    cents, pii1d = binner.bin(pii2d)
    cents, prr1d = binner.bin(fc.f2power(snkappa, snkappa))

    cents, Nlkk3 = binner.bin(sNl)

    pl = io.Plotter(xyscale='loglog')
    pl.add(ells, theory.gCl('kk', ells))
    pl.add(cents, pii1d, color='k', lw=3)
    pl.add(cents, pir1d3, label='shear')
    pl.add(cents, prr1d)
    pl.add(cents, Nlkk3, ls=":")
    pl._ax.set_xlim(10, 3500)
    pl.done("ncomp.png")
示例#9
0
def test_lens_recon():
    from orphics import lensing, io, cosmology, maps
    from enlib import bench

    deg = 10.
    px = 2.0
    tellmin = 100
    tellmax = 3000
    kellmin = 40
    kellmax = 3000
    grad_cut = None
    bin_width = 80
    beam_arcmin = 0.01
    noise_uk_arcmin = 0.01

    theory = cosmology.default_theory(lpad=30000)
    shape, wcs = s.rect_geometry(width_deg=deg, px_res_arcmin=px)
    flsims = lensing.FlatLensingSims(shape, wcs, theory, beam_arcmin,
                                     noise_uk_arcmin)
    kbeam = flsims.kbeam
    modlmap = enmap.modlmap(shape, wcs)
    fc = maps.FourierCalc(shape, wcs)
    n2d = (noise_uk_arcmin * np.pi / 180. / 60.)**2. / flsims.kbeam**2.
    tmask = s.mask_kspace(shape, wcs, lmin=tellmin, lmax=tellmax)
    kmask = s.mask_kspace(shape, wcs, lmin=kellmin, lmax=kellmax)
    with bench.show("orphics init"):
        qest = lensing.qest(shape,
                            wcs,
                            theory,
                            noise2d=n2d,
                            kmask=tmask,
                            kmask_K=kmask,
                            pol=False,
                            grad_cut=grad_cut,
                            unlensed_equals_lensed=True,
                            bigell=30000)
    bin_edges = np.arange(kellmin, kellmax, bin_width)
    binner = s.bin2D(modlmap, bin_edges)
    i = 0
    unlensed, kappa, lensed, beamed, noise_map, observed = flsims.get_sim(
        seed_cmb=(i, 1),
        seed_kappa=(i, 2),
        seed_noise=(i, 3),
        lens_order=5,
        return_intermediate=True)

    kmap = enmap.fft(observed, normalize="phys")
    # _,kmap,_ = fc.power2d(observed)
    with bench.show("orphics"):
        kkappa = qest.kappa_from_map("TT",
                                     kmap / kbeam,
                                     alreadyFTed=True,
                                     returnFt=True)
    pir2d, kinput = fc.f1power(kappa, kkappa)
    pii2d = fc.f2power(kinput, kinput)
    prr2d = fc.f2power(kkappa, kkappa)
    cents, pir1d = binner.bin(pir2d)
    cents, pii1d = binner.bin(pii2d)
    cents, prr1d = binner.bin(prr2d)

    feed_dict = {}
    cltt = theory.lCl('TT', modlmap)
    feed_dict['uC_T_T'] = theory.lCl('TT', modlmap)
    feed_dict['tC_T_T'] = cltt + n2d
    feed_dict['X'] = kmap / kbeam
    feed_dict['Y'] = kmap / kbeam

    with bench.show("symlens init"):
        Al = s.A_l(shape,
                   wcs,
                   feed_dict,
                   "hdv",
                   "TT",
                   xmask=tmask,
                   ymask=tmask)
    Nl = s.N_l_from_A_l_optimal(shape, wcs, Al)
    with bench.show("symlens"):
        ukappa = s.unnormalized_quadratic_estimator(shape,
                                                    wcs,
                                                    feed_dict,
                                                    "hdv",
                                                    "TT",
                                                    xmask=tmask,
                                                    ymask=tmask)
    nkappa = Al * ukappa

    pir2d2 = fc.f2power(nkappa, kinput)
    cents, pir1d2 = binner.bin(pir2d2)

    cents, Nlkk = binner.bin(qest.N.Nlkk['TT'])
    cents, Nlkk2 = binner.bin(Nl)

    pl = io.Plotter(xyscale='linlog')
    pl.add(cents, pii1d, color='k', lw=3)
    pl.add(cents, pir1d, label='orphics')
    pl.add(cents, pir1d2, label='hdv symlens')
    pl.add(cents, Nlkk, ls="--", label='orphics')
    pl.add(cents, Nlkk2, ls="-.", label='symlens')
    pl.done("ncomp.png")
示例#10
0
    def make_sim(self, seed):

        with bench.show(
                "Lensing operation...") if self.rank == 0 else ignore():
            full, kappa = lensing.rand_map(
                self.fshape,
                self.fwcs,
                self.ps,
                lmax=self.lmax,
                maplmax=self.lmax,
                seed=seed,
                verbose=True if self.rank == 0 else False,
                dtype=self.dtype,
                output="lk")
            alms = curvedsky.map2alm(full, lmax=self.lmax)
            ps_data = hp.alm2cl(alms.astype(np.complex128))
            del alms
            self.mpibox.add_to_stats("fullsky_ps", ps_data)
            south = full.submap(self.pos_south)
            equator = full.submap(self.pos_eq)
            ksouth = kappa.submap(self.pos_south)
            kequator = kappa.submap(self.pos_eq)
            del full
            del kappa

        if self.count == 0:
            self.shape['s'], self.wcs['s'] = south.shape, south.wcs
            self.shape['e'], self.wcs['e'] = equator.shape, equator.wcs

            for m in ['s', 'e']:
                self.taper[m], self.w2[m] = fmaps.get_taper(self.shape[m],
                                                            taper_percent=18.0,
                                                            pad_percent=4.0,
                                                            weight=None)
                self.w4[m] = np.mean(self.taper[m]**4.)
                self.w3[m] = np.mean(self.taper[m]**3.)

            self.rotator = fmaps.MapRotatorEquator(
                self.shape['s'],
                self.wcs['s'],
                self.wdeg,
                self.hdeg,
                width_multiplier=0.6,
                height_multiplier=1.2,
                downsample=True,
                verbose=True if self.rank == 0 else False,
                pix_target_override_arcmin=self.pix_intermediate)

            self.taper['r'] = self.rotator.rotate(self.taper['s'])
            self.w2['r'] = np.mean(self.taper['r']**2.)
            self.w4['r'] = np.mean(self.taper['r']**4.)
            self.w3['r'] = np.mean(self.taper['r']**3.)

            self.shape['r'], self.wcs[
                'r'] = self.rotator.shape_final, self.rotator.wcs_final

            self.fc = {}
            self.binner = {}
            self.modlmap = {}
            for m in ['s', 'e', 'r']:
                self.fc[m] = fmaps.FourierCalc(self.shape[m], self.wcs[m])
                self.modlmap[m] = enmap.modlmap(self.shape[m], self.wcs[m])
                self.binner[m] = bin2D(self.modlmap[m], self.bin_edges)
            self.cents = self.binner['s'].centers
            self._init_qests()

        self.count += 1

        south *= self.taper['s']
        equator *= self.taper['e']
        ksouth *= self.taper['s']
        kequator *= self.taper['e']

        return south, equator, ksouth, kequator
                           nsplits.astype(np.int),
                           lknees,
                           alphas,
                           ps,
                           nu0,
                           lmins=lmins,
                           lmaxs=lmaxs,
                           atmosphere=atmosphere,
                           lensing=lensing,
                           dust=dust,
                           do_fgs=fgs,
                           lpass=lpass,
                           aseed=aseed)

modlmap = tsim.modlmap
fc = maps.FourierCalc(tsim.shape, tsim.wcs)
narrays = len(tsim.arrays)
iells = modlmap[modlmap < lmax1].reshape(-1)  # unraveled disk
nells = iells.size
Ny, Nx = shape[-2:]
tcmb = 2.726e6
yresponses = tfg.get_mix(tsim.freqs, "tSZ")
cresponses = tfg.get_mix(tsim.freqs, "CMB")

minell = maps.minimum_ell(tsim.shape, tsim.wcs)
bin_edges = np.arange(np.min(lmins), lmax - 50, 8 * minell)
binner = stats.bin2D(modlmap, bin_edges)
cents = binner.centers

# Only do hybrid treatment for arrays with more than 2 splits (ACT) -- now doing for Planck as well
anisotropic_pairs = []