Example #1
0
    def test_b_sign(self):
        """
        We generate a random IQU map with geometry such that cdelt[0]<0
        We transform this to TEB with map2harm and map2alm followed by 
        scalar harm2map and alm2map and use these as reference T,E,B maps.
        We flip the original map along the RA direction.
        We transform this to TEB with map2harm and map2alm followed by 
        scalar harm2map and alm2map and use these as comparison T,E,B maps.
        We compare these maps.
        """
        ells,cltt,clee,clbb,clte = np.loadtxt(DATA_PREFIX+"cosmo2017_10K_acc3_lensedCls.dat",unpack=True)
        ps_cmb = np.zeros((3,3,ells.size))
        ps_cmb[0,0] = cltt
        ps_cmb[1,1] = clee
        ps_cmb[2,2] = clbb
        ps_cmb[1,0] = clte
        ps_cmb[0,1] = clte
        np.random.seed(100)

        # Curved-sky is fine
        lmax = 1000
        alm = curvedsky.rand_alm_healpy(ps_cmb,lmax=lmax)
        shape,iwcs = enmap.fullsky_geometry(res=np.deg2rad(10./60.))
        wcs = enmap.empty(shape,iwcs)[...,::-1].wcs
        shape = (3,) + shape
        imap = curvedsky.alm2map(alm,enmap.empty(shape,wcs))
        oalm = curvedsky.map2alm(imap.copy(),lmax=lmax)
        rmap = curvedsky.alm2map(oalm,enmap.empty(shape,wcs),spin=0)

        imap2 = imap.copy()[...,::-1]
        oalm = curvedsky.map2alm(imap2.copy(),lmax=lmax)
        rmap2 = curvedsky.alm2map(oalm,enmap.empty(shape,wcs),spin=0)

        assert np.all(np.isclose(rmap[0],rmap2[0]))
        assert np.all(np.isclose(rmap[1],rmap2[1]))
        assert np.all(np.isclose(rmap[2],rmap2[2]))
        

        # Flat-sky
        px = 2.0
        N = 300
        shape,iwcs = enmap.geometry(pos=(0,0),res=np.deg2rad(px/60.),shape=(300,300))
        shape = (3,) + shape
        a = enmap.zeros(shape,iwcs)
        a = a[...,::-1]
        wcs = a.wcs

        seed = 100
        imap = enmap.rand_map(shape,wcs,ps_cmb,seed=seed)
        kmap = enmap.map2harm(imap.copy())
        rmap = enmap.harm2map(kmap,spin=0) # reference map

        imap = imap[...,::-1]
        kmap = enmap.map2harm(imap.copy())
        rmap2 = enmap.harm2map(kmap,spin=0)[...,::-1] # comparison map
        
        assert np.all(np.isclose(rmap[0],rmap2[0]))
        assert np.all(np.isclose(rmap[1],rmap2[1],atol=1e0))
        assert np.all(np.isclose(rmap[2],rmap2[2],atol=1e0))
Example #2
0
def build_iN_constcorr(data,
                       maps,
                       smooth="angular",
                       brel=2,
                       lsigma=500,
                       lmin=100,
                       ivars=None,
                       constcov=False):
    if ivars is None: ivars = data.ivars
    #enmap.write_map("constcorr_imap1.fits", maps)
    if not constcov: maps = maps * ivars**0.5
    #enmap.write_map("constcorr_imap2.fits", maps)
    fhmap = enmap.map2harm(maps, spin=0,
                           normalize="phys") / maps.pixsize()**0.5
    del maps
    N = (fhmap[:, None] * np.conj(fhmap[None, :])).real
    N /= np.maximum(data.fapod, 1e-8)
    del fhmap
    # Smooth in piwwin-space, since things are expected to be more isotopic there
    N = N * data.wy[:, None]**2 * data.wx[None, :]**2
    if smooth == "angular":
        N = smooth_ps_angular(N, brel=brel)
    elif smooth == "gauss":
        N = smooth_ps_gauss(N, lsigma=lsigma)
    elif smooth == "mixed":
        N = smooth_ps_mixed(N, brel=brel, lsigma=lsigma)
    else:
        raise ValueError("Unrecognized smoothing '%s'" % str(smooth))
    #enmap.write_map("N.fits", N)
    iN = analysis.safe_pow(N, -1)
    #enmap.write_map("iN.fits", iN)
    iN = iN * data.wy[:, None]**2 * data.wx[None, :]**2
    iN[:, :, data.l < lmin] = 0
    return iN
Example #3
0
#		wmap = enmap.ifft(enmap.fft(wmap)*matched_filter).real**2
#		lim  = max(np.median(wmap)*tol1**2, np.max(wmap)*tol2**2)
#		mask |= wmap > lim
#	return mask

comm = mpi.COMM_WORLD
beam1d = get_beam(args.beam)
ifiles = sorted(sum([glob.glob(ifile) for ifile in args.ifiles], []))

for ind in range(comm.rank, len(ifiles), comm.size):
    ifile = ifiles[ind]
    if args.verbose: print(ifile)
    ofile = args.odir + "/" + ifile
    imap = enmap.read_map(ifile)
    if args.mask is not None: mask = imap == args.mask
    if args.apodize:
        imap = imap.apod(args.apodize)
    # We will apply a semi-matched-filter to T
    l = np.maximum(1, imap.modlmap())
    beam2d = enmap.samewcs(np.interp(l, np.arange(len(beam1d)), beam1d), imap)
    matched_filter = (1 + (l / args.lknee)**args.alpha)**-1 * beam2d
    fmap = enmap.map2harm(imap, iau=True)
    fmap[0] *= matched_filter
    omap = enmap.ifft(fmap).real
    if args.mask is not None:
        omap[mask] = 0
        del mask
    utils.mkdir(os.path.dirname(ofile))
    enmap.write_map(ofile, omap)
    del omap
Example #4
0
# Fourier magnitude map
modlmap = enmap.modlmap(shape, wcs)

# Unlensed CMB theory
theory = cosmology.default_theory()
cltt2d = theory.uCl('TT', modlmap)
clte2d = theory.uCl('TE', modlmap)
clee2d = theory.uCl('EE', modlmap)
power = np.zeros((3, 3, shape[0], shape[1]))
power[0, 0] = cltt2d
power[1, 1] = clee2d
power[1, 2] = clte2d
power[2, 1] = clte2d

# Unlensed CMB generator
mgen = maps.MapGen((3, ) + shape, wcs, power)

for j, task in enumerate(my_tasks):
    print(f'Rank {rank} performing task {task} as index {j}')
    cmb = mgen.get_map(
        seed=cutils.get_seed('lensed', task, False)
    )  # unlensed map ; you can save it if you want, before lensing it
    cmb = lens_map(cmb)  # do the lensing
    dcmb = cmb.resample(
        (3, dNpix, dNpix)
    )  # downsample the lensed CMB map (if saving unlensed, do the same to it)
    # For some reason, I was saving the Fourier transforms... probably since it is easier to apply a beam later
    kmap = enmap.map2harm(dcmb, iau=False)
    enmap.write_map(f'{savedir}lensed_kmap_real_{task:06d}.fits', kmap.real)
    enmap.write_map(f'{savedir}lensed_kmap_imag_{task:06d}.fits', kmap.imag)