Example #1
0
    def __init__(self,
                 mpibox,
                 theory,
                 shape,
                 wcs,
                 lbinner=None,
                 bin_edges=None,
                 pol=False,
                 iau_convention=False):

        self.mpibox = mpibox
        self.theory = theory
        self.shape = shape
        self.pol = pol
        self.wcs = wcs
        self.modlmap = enmap.modlmap(shape, wcs)
        self.fcalc = enmap.FourierCalc(shape,
                                       wcs,
                                       iau_convention=iau_convention)
        if lbinner is None:
            assert bin_edges is not None
            import orphics.tools.stats as stats
            self.lbinner = stats.bin2D(self.modlmap, bin_edges)
        else:
            self.lbinner = lbinner
Example #2
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] = enmap.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
Example #3
0
def stat_analysis(cutouts, binsize, arcmax, cents, modRMaps):
    profiles = []
    for i in range(0, len(cutouts)):
        thetaRange = np.arange(0., arcmax, binsize)
        breali = bin2D(modRMaps[i] * 180. * 60. / np.pi, thetaRange)
        a = breali.bin(cutouts[i])[1]
        profiles.append(a)
    statistics = stats.getStats(profiles)
    mean = statistics['mean']
    error = statistics['errmean']
    covmat = statistics['cov']
    corrcoef = stats.cov2corr(covmat)
    io.quickPlot2d(corrcoef, 'corrcoef.png')
    pl = Plotter(labelX='Distance from Center (arcminutes)',
                 labelY='Temperature Fluctuation ($\mu K$)',
                 ftsize=10)
    pl.add(cents, mean)
    pl.addErr(cents, mean, yerr=error)
    pl._ax.axhline(y=0., ls="--", alpha=0.5)
    pl.done(out_dir + "error.png")
Example #4
0
 def __init__(self, modlmap, bin_edges):
     import orphics.tools.stats as stats
     self.binner = stats.bin2D(modlmap, bin_edges)
Example #5
0
lmap = lm.makeEmptyCEATemplate(raSizeDeg=20., decSizeDeg=20.)

ells = np.arange(2, 6000, 1)
Cell = cc.clttfunc(ells)  #cc.theory.lCl('TT',ells)

lmap.fillWithGaussianRandomField(ells, Cell, bufferFactor=1)

io.highResPlot2d(lmap.data, out_dir + "map.png")

p2d = fmaps.get_simple_power(lmap, lmap.data * 0. + 1.)
lxMap, lyMap, modLMap, thetaMap, lx, ly = fmaps.getFTAttributesFromLiteMap(
    lmap)

bin_edges = np.arange(20, 4000, 40)
b = stats.bin2D(modLMap, bin_edges)
cents, cdat = b.bin(p2d)

pl = io.Plotter(scaleX='log', scaleY='log')
pl.add(ells, Cell * ells**2.)
pl.add(cents, cdat * cents**2.)
# pl.done(out_dir+"cls.png")

lmap.fillWithGaussianRandomField(ells, Cell, bufferFactor=3)

p2d = fmaps.get_simple_power(lmap, lmap.data * 0. + 1.)

cents, cdat = b.bin(p2d)

pl.add(cents, cdat * cents**2., ls="--")
pl.done(out_dir + "cls.png")
Example #6
0
deg = 20.
px = 1.0
shape, wcs = maps.rect_geometry(width_deg=deg,px_res_arcmin=px,pol=True)
pa = fmaps.PatchArray(shape,wcs,cc=cc,orphics_is_dimensionless=False)
ulensed = pa.get_unlensed_cmb()
kappa = pa.get_grf_kappa()
cmb = pa.get_lensed(ulensed,order=5)

# io.highResPlot2d(cmb[0],out_dir+"t.png")
# io.highResPlot2d(cmb[1],out_dir+"q.png")
# io.highResPlot2d(cmb[2],out_dir+"u.png")

modlmap = enmap.modlmap(shape,wcs)
fc = maps.FourierCalc(shape,wcs)
lbin_edges = np.arange(200,6000,40)
lbinner = stats.bin2D(modlmap,lbin_edges)

def plot_powers(cmb,suffix,power=None,w2=1.):

    if power is None:
        power,lteb1,lteb2 = fc.power2d(cmb,pixel_units=False,skip_cross=True)
    power /= w2
    cents,dtt = lbinner.bin(power[0,0])
    cents,dee = lbinner.bin(power[1,1])
    cents,dbb = lbinner.bin(power[2,2])


    pl = io.Plotter(scaleY='log')
    ellrange = np.arange(200,6000,1)
    cltt = theory.lCl('TT',ellrange)
    clee = theory.lCl('EE',ellrange)
Example #7
0
# === COSMOLOGY ===
theory, cc, lmax = aio.theory_from_config(Config,
                                          cosmology_section,
                                          dimensionless=False)
parray_dat.add_theory(cc, theory, lmax, orphics_is_dimensionless=False)
parray_sim.add_theory(cc, theory, lmax, orphics_is_dimensionless=False)

lxmap_dat, lymap_dat, modlmap_dat, angmap_dat, lx_dat, ly_dat = fmaps.get_ft_attributes_enmap(
    shape_dat, wcs_dat)
lxmap_sim, lymap_sim, modlmap_sim, angmap_sim, lx_sim, ly_sim = fmaps.get_ft_attributes_enmap(
    shape_sim, wcs_sim)
kellmin = args.kellmin
kellmax = args.kellmax
lbin_edges = np.arange(kellmin, kellmax, 200)
lbinner_dat = stats.bin2D(modlmap_dat, lbin_edges)
lbinner_sim = stats.bin2D(modlmap_sim, lbin_edges)

sverif_cmb = SpectrumVerification(mpibox,
                                  theory,
                                  shape_sim,
                                  wcs_sim,
                                  lbinner=lbinner_sim,
                                  pol=pol)
sverif_dcmb = SpectrumVerification(mpibox,
                                   theory,
                                   shape_dat,
                                   wcs_dat,
                                   lbinner=lbinner_dat,
                                   pol=pol)
sverif_kappa = SpectrumVerification(mpibox,
Example #8
0
def debug():
    teb = enmap.ifft(enmap.map2harm(unlensed)).real
    lteb = enmap.ifft(klteb).real
    if pol:
        io.quickPlot2d(unlensed[0], out_dir + "tmap.png")
        io.quickPlot2d(unlensed[1], out_dir + "qmap.png")
        io.quickPlot2d(unlensed[2], out_dir + "umap.png")
        io.quickPlot2d(teb[1], out_dir + "emap.png")
        io.quickPlot2d(teb[2], out_dir + "bmap.png")
        io.quickPlot2d(lensed[0], out_dir + "ltmap.png")
        io.quickPlot2d(lensed[1], out_dir + "lqmap.png")
        io.quickPlot2d(lensed[2], out_dir + "lumap.png")
        io.quickPlot2d(lteb[1], out_dir + "lemap.png")
        io.quickPlot2d(lteb[2], out_dir + "lbmap.png")
    else:
        io.quickPlot2d(unlensed, out_dir + "tmap.png")
        io.quickPlot2d(lensed, out_dir + "ltmap.png")

    t = teb[0, :, :]
    e = teb[1, :, :]
    b = teb[2, :, :]
    nt = noise[0, :, :]
    ne = noise[1, :, :]
    nb = noise[2, :, :]
    ntt2d = np.nan_to_num(fmaps.get_simple_power_enmap(nt) / kbeam_sim**2.)
    nee2d = np.nan_to_num(fmaps.get_simple_power_enmap(ne) / kbeam_sim**2.)
    nbb2d = np.nan_to_num(fmaps.get_simple_power_enmap(nb) / kbeam_sim**2.)

    utt2d = fmaps.get_simple_power_enmap(t)
    uee2d = fmaps.get_simple_power_enmap(e)
    ute2d = fmaps.get_simple_power_enmap(enmap1=t, enmap2=e)
    ubb2d = fmaps.get_simple_power_enmap(b)
    debug_edges = np.arange(2, 12000, 80)
    dbinner = stats.bin2D(modlmap_sim, debug_edges)
    cents, utt = dbinner.bin(utt2d)
    cents, uee = dbinner.bin(uee2d)
    cents, ute = dbinner.bin(ute2d)
    cents, ntt = dbinner.bin(ntt2d)
    cents, nee = dbinner.bin(nee2d)
    cents, nbb = dbinner.bin(nbb2d)
    #cents, ubb = dbinner.bin(ubb2d)

    tl = lteb[0, :, :]
    el = lteb[1, :, :]
    bl = lteb[2, :, :]
    ltt2d = fmaps.get_simple_power_enmap(tl)
    lee2d = fmaps.get_simple_power_enmap(el)
    lte2d = fmaps.get_simple_power_enmap(enmap1=tl, enmap2=el)
    lbb2d = fmaps.get_simple_power_enmap(bl)
    cents, ltt = dbinner.bin(ltt2d)
    cents, lee = dbinner.bin(lee2d)
    cents, lte = dbinner.bin(lte2d)
    cents, lbb = dbinner.bin(lbb2d)

    lcltt, lclee, lclte, lclbb = (
        x for x in cmb.unpack_cmb_theory(theory, fine_ells, lensed=True))
    cltt, clee, clte, clbb = (
        x for x in cmb.unpack_cmb_theory(theory, fine_ells, lensed=False))

    pl = io.Plotter(scaleY='log', scaleX='log')
    pl.add(cents, utt * cents**2., color="C0", marker="o", ls="none")
    pl.add(cents, uee * cents**2., color="C1", marker="o", ls="none")
    #pl.add(cents,ubb*cents**2.,color="C2",ls="-")
    pl.add(fine_ells, cltt * fine_ells**2., color="C0", ls="--")
    pl.add(fine_ells, clee * fine_ells**2., color="C1", ls="--")
    #pl.add(fine_ells,clbb*fine_ells**2.,color="C2",ls="--")
    pl.done(out_dir + "ccomp.png")

    pl = io.Plotter(scaleX='log')
    pl.add(cents, ute * cents**2., color="C0", marker="o", ls="none")
    pl.add(fine_ells, clte * fine_ells**2., color="C0", ls="--")
    pl.done(out_dir + "ccompte.png")

    # sells,stt,see,sbb,ste = np.loadtxt("data/cl_lensed.dat",unpack=True)
    # stt *= 2.*np.pi/TCMB**2./sells/(sells+1.)
    # see *= 2.*np.pi/TCMB**2./sells/(sells+1.)
    # sbb *= 2.*np.pi/TCMB**2./sells/(sells+1.)

    pl = io.Plotter(scaleY='log')  #,scaleX='log')

    # pl.add(sells,stt*sells**2.,color="C0",ls="-")
    # pl.add(sells,see*sells**2.,color="C1",ls="-")
    # pl.add(sells,sbb*sells**2.,color="C2",ls="-")

    pl.add(cents, ltt * cents**2., color="C0", marker="o", ls="none")
    pl.add(cents, lee * cents**2., color="C1", marker="o", ls="none")
    pl.add(cents, lbb * cents**2., color="C2", marker="o", ls="none")
    pl.add(cents, ntt * cents**2., color="C0", ls="-.", alpha=0.4)
    pl.add(cents, nee * cents**2., color="C1", ls="-.", alpha=0.4)
    pl.add(cents, nbb * cents**2., color="C2", ls="-.", alpha=0.4)
    pl.add(fine_ells, lcltt * fine_ells**2., color="C0", ls="--")
    pl.add(fine_ells, lclee * fine_ells**2., color="C1", ls="--")
    pl.add(fine_ells, lclbb * fine_ells**2., color="C2", ls="--")
    pl.done(out_dir + "lccomp.png")

    pl = io.Plotter(scaleX='log')
    pl.add(cents, lte * cents**2., color="C0", ls="-")
    pl.add(fine_ells, lclte * fine_ells**2., color="C0", ls="--")
    pl.done(out_dir + "lccompte.png")
Example #9
0
# let's define the bin edges for this test
ellmin = 2
ellmax = 4000
bin_width = 200
bin_edges = np.arange(ellmin, ellmax, bin_width)

# a typical map might be 400sq.deg. with 0.5 arcmin pixels
shape, wcs = enmap.get_enmap_patch(width_arcmin=20 * 60., px_res_arcmin=0.5)

# let's get the "mod ell" or |ell| map, which tells us the magnitude of
# the angular wavenumbers in each fourier pixel
modlmap = enmap.modlmap(shape, wcs)

# this let's us create a 2D fourier space binner
binner2d = stats.bin2D(modlmap, bin_edges)

# the 1d binner just needs to know about the bin edges
binner1d = stats.bin1D(bin_edges)

# initialize a cosmology; make sure you have an "output" directory
# for pickling to work
cc = Cosmology(lmax=6000, pickling=True)
theory = cc.theory

# the fine ells we will use
fine1d_ells = np.arange(ellmin, ellmax, 1)

# let's test on TT and kk, lCl for TT and gCl for kk
for spec in ['TT', 'kk']:
    try:
Example #10
0
def stack_on_map(lite_map,
                 width_stamp_arcminute,
                 pix_scale,
                 ra_range,
                 dec_range,
                 catalog=None,
                 n_random_points=None):
    width_stamp_degrees = width_stamp_arcminute / 60.
    Np = np.int(width_stamp_arcminute / pix_scale + 0.5)
    pad = np.int(Np / 2 + 0.5)
    print("Expected width in pixels = ", Np)
    lmap = lite_map
    stack = 0
    N = 0

    if catalog is not None:
        looprange = range(0, len(catalog))
        assert n_random_points is None
        random = False
    else:
        assert n_random_points is not None
        assert len(ra_range) == 2
        assert len(dec_range) == 2
        looprange = range(0, n_random_points)
        random = True
    print(looprange)
    for i in looprange:
        banana = True
        mass = catalog[i][10]
        if random:
            ra = np.random.uniform(*ra_range)
            dec = np.random.uniform(*dec_range)
        if random == False:
            ra = catalog[i][1]  #1 for ACT catalog 2 for SDSS
            dec = catalog[i][2]  #2 for ACT catalog 3 for SDSS
        for j in range(0, 2130):
            distance = np.sqrt((ra - RAps[j])**2 + (dec - DECps[j])**2)
            crit = 0.25
            if distance < crit:
                banana = False
                print('too close')
        ix, iy = lmap.skyToPix(ra, dec)
        if ix >= pad and ix < lmap.Nx - pad and iy >= pad and iy < lmap.Ny - pad and banana == True and mass > 8:
            print(i)
            #print(ra,dec)
            smap = lmap.selectSubMap(ra - width_stamp_degrees / 2.,
                                     ra + width_stamp_degrees / 2.,
                                     dec - width_stamp_degrees / 2.,
                                     dec + width_stamp_degrees / 2.)
            #print (smap.data.shape)
            #cutout = zoom(smap.data.copy(),zoom=(float(Np)/smap.data.shape[0],float(Np)/smap.data.shape[1])
            cutout = resize(smap.data.copy(),
                            output_shape=(Np, Np)) - randomstack
            xMap, yMap, modRMap, xx, yy = fmaps.getRealAttributes(smap)
            dt = pix_scale
            arcmax = 20.
            thetaRange = np.arange(0., arcmax, dt)
            breali = bin2D(modRMap * 180. * 60. / np.pi, thetaRange)
            a = breali.bin(cutout)[1]
            profiles.append(a)
            io.quickPlot2d(cutout, str(i) + "cutout.png")
            #print (cutout.shape)
            stack = stack + cutout
            N = N + 1
        else:
            print("skip")
    stack = stack / N  #-randomstack
    #print(stack.shape())
    #print(smap.data.shape)
    # print(stack)
    print(N)
    statistics = stats.getStats(profiles)
    mean = statistics['mean']
    error = statistics['errmean']
    corrcoef = statistics['corr']
    covmat = statistics['covmat']
    print(mean / error)
    np.save('statistics', statistics)
    #np.save('newrandomstamp',stack)
    # io.quickPlot2d(stack,out_dir+"newACTstack.png")
    dt = pix_scale
    arcmax = 20.
    thetaRange = np.arange(0., arcmax, dt)
    breal = bin2D(modRMap * 180. * 60. / np.pi, thetaRange)
    cents, recons = breal.bin(stack)
    pl = Plotter(labelX='Distance from Center (arcminutes)',
                 labelY='Temperature Fluctuation ($\mu K$)',
                 ftsize=10)
    pl.add(cents, mean)
    pl.addErr(cents, mean, yerr=error)
    pl._ax.axhline(y=0., ls="--", alpha=0.5)
    pl.done(out_dir + "error.png")
    print(covmat)
    io.quickPlot2d(covmat, 'covmat.png')
    return (stack, cents, recons)
Example #11
0
            shape_dat, wcs_dat)

        taper_percent = 15.0
        Ny, Nx = shape_dat
        taper = fmaps.cosineWindow(Ny,
                                   Nx,
                                   lenApodY=taper_percent * min(Ny, Nx) / 100.,
                                   lenApodX=taper_percent * min(Ny, Nx) / 100.,
                                   padY=0,
                                   padX=0)
        tapered = measured * taper
        w2 = np.mean(taper**2.)
        w4 = np.mean(taper**4.)

        debug_edges = np.arange(400, 8000, 150)
        dbinner_dat = stats.bin2D(modlmap_dat, debug_edges)

        nT = parray_dat.nT
        nP = parray_dat.nP
        kbeam_dat = parray_dat.lbeam

        fMaskCMB_T = fmaps.fourierMask(lx_dat,
                                       ly_dat,
                                       modlmap_dat,
                                       lmin=tellmin,
                                       lmax=tellmax)
        fMaskCMB_P = fmaps.fourierMask(lx_dat,
                                       ly_dat,
                                       modlmap_dat,
                                       lmin=pellmin,
                                       lmax=pellmax)
parray_sim.add_theory(theory=theory, lmax=lmax, orphics_is_dimensionless=False)

lb = aio.ellbounds_from_config(Config, recon_section, min_ell)
tellmin = lb['tellminY']
tellmax = lb['tellmaxY']
pellmin = lb['pellminY']
pellmax = lb['pellmaxY']
kellmin = lb['kellmin']
kellmax = lb['kellmax']

lxmap_dat, lymap_dat, modlmap_dat, angmap_dat, lx_dat, ly_dat = fmaps.get_ft_attributes_enmap(
    shape_dat, wcs_dat)
lxmap_sim, lymap_sim, modlmap_sim, angmap_sim, lx_sim, ly_sim = fmaps.get_ft_attributes_enmap(
    shape_sim, wcs_sim)
lbin_edges = np.arange(kellmin, kellmax, 200)
lbinner_dat = stats.bin2D(modlmap_dat, lbin_edges)
lbinner_sim = stats.bin2D(modlmap_sim, lbin_edges)
bin_edges = np.arange(0., 20., analysis_resolution * 2.)
binner_dat = stats.bin2D(parray_dat.modrmap * 60. * 180. / np.pi, bin_edges)

sverif_cmb = SpectrumVerification(mpibox,
                                  theory,
                                  shape_sim,
                                  wcs_sim,
                                  lbinner=lbinner_sim,
                                  pol=pol)
sverif_kappa = SpectrumVerification(mpibox,
                                    theory,
                                    shape_dat,
                                    wcs_dat,
                                    lbinner=lbinner_dat,
Example #13
0
def stack_on_map(lite_map,
                 width_stamp_arcminute,
                 pix_scale,
                 ra_range,
                 dec_range,
                 catalog=None,
                 n_random_points=None):
    from skimage.transform import resize
    import orphics.tools.stats as stats

    width_stamp_degrees = width_stamp_arcminute / 60.
    Np = np.int(width_stamp_arcminute / pix_scale + 0.5)
    pad = np.int(Np / 2 + 0.5)
    print("Expected width in pixels = ", Np)

    lmap = lite_map
    stack = 0
    N = 0

    if catalog is not None:
        looprange = goodobjects
        print(looprange)
        assert n_random_points is None
        random = False
    else:
        assert n_random_points is not None
        assert len(ra_range) == 2
        assert len(dec_range) == 2
        looprange = range(0, n_random_points)
        random = True

    for i in looprange:
        if random:
            ra = np.random.uniform(*ra_range)
            dec = np.random.uniform(*dec_range)
        if random == False:
            ra = catalog[i][1]  #1 for ACT catalog 2 for SDSS and redmapper
            dec = catalog[i][2]  #2 for ACT catalog 3 for SDSS and redmapper
        ix, iy = lmap.skyToPix(ra, dec)
        if ix >= pad and ix < lmap.Nx - pad and iy >= pad and iy < lmap.Ny - pad:
            print(i)
            smap = lmap.selectSubMap(ra - width_stamp_degrees / 2.,
                                     ra + width_stamp_degrees / 2.,
                                     dec - width_stamp_degrees / 2.,
                                     dec + width_stamp_degrees / 2.)
            #cutout = zoom(smap.data.copy(),zoom=(float(Np)/smap.data.shape[0],float(Np)/smap.data.shape[1]))
            cutout = resize(smap.data.copy(), output_shape=(Np, Np))
            cutouts.append(cutout - randomstack)
            stack = stack + cutout
            xMap, yMap, modRMap, xx, yy = fmaps.getRealAttributes(smap)
            N = N + 1.
            ixs.append(ix)
            iys.append(iy)
            modRMaps.append(modRMap)
        else:
            print("skip")
    stack = stack / N - randomstack
    print(N)
    if catalog is not None:
        io.quickPlot2d(stack, out_dir + "stack.png")
    else:
        np.save('randomstamp', stack)

    dt = pix_scale
    arcmax = 20.
    thetaRange = np.arange(0., arcmax, dt)
    breal = stats.bin2D(modRMap * 180. * 60. / np.pi, thetaRange)
    cents, recons = breal.bin(stack)
    pl = Plotter(labelX='Distance from Center (arcminutes)',
                 labelY='Temperature Fluctuation ($\mu K$)',
                 ftsize=10)
    pl.add(cents, recons)
    pl._ax.axhline(y=0., ls="--", alpha=0.5)
    pl.done(out_dir + "profiles.png")
    return stack, cents, recons
Example #14
0
    def getKappa(self, XY, weightedFt=False):

        assert self._hasX and self._hasY
        assert XY in ['TT', 'TE', 'ET', 'EB', 'TB', 'EE']
        X, Y = XY

        WXY = self.N.WXY(XY)
        WY = self.N.WY(Y + Y)

        import orphics.tools.io as io
        io.quickPlot2d(np.fft.fftshift((WXY.real)), "wxy_" + XY + ".png")
        io.quickPlot2d(np.fft.fftshift((WY.real)), "wyy_" + Y + Y + ".png")
        io.quickPlot2d(np.fft.fftshift((self.N.Nlkk[XY])),
                       "nxy_" + XY + ".png")

        lx = self.N.lxMap
        ly = self.N.lyMap

        if Y in ['E', 'B']:
            phaseY = self.phaseY
        else:
            phaseY = 1.

        phaseB = (int(Y == 'B') * 1.j) + (int(Y != 'B'))

        fmask = self.N.modLMap * 0. + 1.
        #fmask[self.N.modLMap>6000]=0.

        HighMapStar = ifft(self.kHigh[Y] * WY * phaseY * phaseB * fmask,
                           axes=[-2, -1],
                           normalize=True).conjugate()
        kPx = fft(
            ifft(self.kGradx[X] * WXY * phaseY, axes=[-2, -1],
                 normalize=True) * HighMapStar,
            axes=[-2, -1]) * fmask
        kPy = fft(
            ifft(self.kGrady[X] * WXY * phaseY, axes=[-2, -1],
                 normalize=True) * HighMapStar,
            axes=[-2, -1]) * fmask
        rawKappa = ifft(1.j * lx * kPx + 1.j * ly * kPy,
                        axes=[-2, -1],
                        normalize=True).real

        AL = np.nan_to_num(self.AL[XY] * fmask)

        kappaft = -AL * fft(rawKappa, axes=[-2, -1]) * fmask
        self.kappa = ifft(kappaft, axes=[-2, -1], normalize=True).real
        try:
            #raise
            assert not (np.any(np.isnan(self.kappa)))
        except:
            import orphics.tools.io as io
            import orphics.tools.stats as stats
            io.quickPlot2d(self.kappa.real, "nankappa.png")
            debug_edges = np.arange(20, 20000, 100)
            dbinner = stats.bin2D(self.N.modLMap, debug_edges)
            cents, bclkk = dbinner.bin(self.N.clkk2d)
            cents, nlkktt = dbinner.bin(self.N.Nlkk['TT'])
            try:
                cents, nlkkeb = dbinner.bin(self.N.Nlkk['EB'])
            except:
                pass
            pl = io.Plotter(scaleY='log', scaleX='log')
            pl.add(cents, bclkk)
            pl.add(cents, nlkktt, label="TT")
            try:
                pl.add(cents, nlkkeb, label="EB")
            except:
                pass
            pl.legendOn()
            pl.done("clkk.png")

            sys.exit()

        # from orphics.tools.io import Plotter
        # pl = Plotter()
        # #pl.plot2d(np.nan_to_num(self.kappa))
        # pl.plot2d((self.kappa.real))
        # pl.done("output/nankappa.png")
        # sys.exit(0)
        # try:
        #     assert not(np.any(np.isnan(self.kappa)))
        # except:
        #     from orphics.tools.io import Plotter
        #     pl = Plotter()
        #     pl.plot2d(np.nan_to_num(self.kappa))
        #     pl.done("output/nankappa.png")
        #     sys.exit(0)

        if self.doCurl:
            OmAL = self.OmAL[XY]
            rawCurl = ifft(1.j * lx * kPy - 1.j * ly * kPx,
                           axes=[-2, -1],
                           normalize=True).real
            self.curl = -ifft(OmAL * fft(rawCurl, axes=[-2, -1]),
                              axes=[-2, -1],
                              normalize=True)
            return self.kappa, self.curl

        return self.kappa
Example #15
0
                                            modLMap,
                                            kellmax,
                                            ellMin=stepmin)
# filtSim = fmaps.stepFunctionFilterLiteMap(simKappa,modLMap,kellmax)

pl = Plotter()
pl.plot2d(filtInput)
pl.done(outDir + "filtinput.png")

# pl = Plotter()
# pl.plot2d(filtInput)
# pl.done(outDir+"filtsim.png")

dt = 0.2
thetaRange = np.arange(0., arcmax, dt)
breal = bin2D(thetaMapDown * 180. * 60. / np.pi, thetaRange)
#cents,inps = breal.bin(trueKappaStack)
cents, inpsFilt = breal.bin(filtInput)
cents, recons = breal.bin(kappaStack)
# cents,reconsfix = breal.bin(kappaFix)
# cents,simFilt = breal.bin(filtSim)

pl = Plotter()
#pl.add(cents,inps,ls="--")
pl.add(cents, inpsFilt)
# pl.add(cents,simFilt,ls="-.")
pl.add(cents, recons)
# pl.add(cents,reconsfix,ls="-.")
pl._ax.axhline(y=0., ls="--", alpha=0.5)
pl.done(outDir + "profiles.png")
Example #16
0
        hpmap, alm = hp.synfast(cls, nside, alm=True, pol=False)

    lmap.loadDataFromHealpixMap(hpmap, interpolate=False, hpCoords="J2000")
    del hpmap
    if k == 0:
        taper, w2 = fmaps.get_taper(lmap.data.shape,
                                    taper_percent=12.0,
                                    pad_percent=3.0,
                                    weight=None)

    lmap.data *= taper
    if rank == 0 and k == 0:
        io.quickPlot2d(lmap.data, io.dout_dir + "flipper_map.png")
    p = ft.powerFromLiteMap(lmap)
    if k == 0:
        binner = stats.bin2D(p.modLMap, bin_edges)

    #pwin = hp.pixwin(nside)
    #pells = np.arange(0,pwin.size)
    #from scipy.interpolate import interp1d
    pwin2d = 1.  #interp1d(pells,pwin,bounds_error=False,fill_value=0.)(p.modLMap)
    p2d = np.nan_to_num(p.powerMap / w2 / pwin2d**2.)

    cents, p1d = binner.bin(p2d)

    cls = hp.alm2cl(alm)

    mpibox.add_to_stack("full", cls)
    mpibox.add_to_stack("cut", p1d)

    if rank == 0: print((k + 1, " / ", len(my_tasks), " done."))
Example #17
0
def getDLnMCMB(ells,Nls,clusterCosmology,log10Moverh,z,concentration,arcStamp,pxStamp,arc_upto,bin_width,expectedSN,Nclusters=1000,numSims=30,saveId=None,numPoints=1000,nsigma=8.,overdensity=500.,critical=True,atClusterZ=True):

    import flipper.liteMap as lm
    if saveId is not None: from orphics.tools.output import Plotter

    M = 10.**log10Moverh

    cc = clusterCosmology

    stepfilter_ellmax = max(ells)
    

    lmap = lm.makeEmptyCEATemplate(raSizeDeg=arcStamp/60., decSizeDeg=arcStamp/60.,pixScaleXarcmin=pxStamp,pixScaleYarcmin=pxStamp)

    xMap,yMap,modRMap,xx,xy = fmaps.getRealAttributes(lmap)
    lxMap,lyMap,modLMap,thetaMap,lx,ly = fmaps.getFTAttributesFromLiteMap(lmap)

    kappaMap,retR500 = NFWkappa(cc,M,concentration,z,modRMap*180.*60./np.pi,winAtLens,overdensity,critical,atClusterZ)
    finetheta = np.arange(0.01,arc_upto,0.01)
    finekappa,retR500 = NFWkappa(cc,M,concentration,z,finetheta,winAtLens,overdensity,critical,atClusterZ)
    kappaMap = fmaps.stepFunctionFilterLiteMap(kappaMap,modLMap,stepfilter_ellmax)

    generator = fmaps.GRFGen(lmap,ells,Nls)
    
    bin_edges = np.arange(0.,arc_upto,bin_width)
    binner = bin2D(modRMap*180.*60./np.pi, bin_edges)
    centers, thprof = binner.bin(kappaMap)


    if saveId is not None:
        pl = Plotter()
        pl.plot2d(kappaMap)
        pl.done("output/"+saveId+"kappa.png")

    
    expectedSNGauss = expectedSN*np.sqrt(numSims)
    sigma = 1./expectedSNGauss
    amplitudeRange = np.linspace(1.-nsigma*sigma,1.+nsigma*sigma,numPoints)

    lnLikes = 0.
    bigStamp = 0.
    for i in range(numSims):
        profiles,totstamp = getProfiles(generator,stepfilter_ellmax,kappaMap,binner,Nclusters)
        bigStamp += totstamp
        stats = getStats(profiles)
        if i==0 and (saveId is not None):
            pl = Plotter()
            pl.add(centers,thprof,lw=2,color='black')
            pl.add(finetheta,finekappa,lw=2,color='black',ls="--")
            pl.addErr(centers,stats['mean'],yerr=stats['errmean'],lw=2)
            pl._ax.set_ylim(-0.01,0.3)
            pl.done("output/"+saveId+"profile.png")

            pl = Plotter()
            pl.plot2d(totstamp)
            pl.done("output/"+saveId+"totstamp.png")


        Likes = getAmplitudeLikelihood(stats['mean'],stats['covmean'],amplitudeRange,thprof)
        lnLikes += np.log(Likes)


    width = amplitudeRange[1]-amplitudeRange[0]

    Likes = np.exp(lnLikes)
    Likes = Likes / (Likes.sum()*width) #normalize
    ampBest,ampErr = cfit(norm.pdf,amplitudeRange,Likes,p0=[1.0,0.5])[0]

    sn = ampBest/ampErr/np.sqrt(numSims)
    snAll = ampBest/ampErr
    if snAll<5.: print "WARNING: ", saveId, " run with mass ", M , " and redshift ", z , " has overall S/N<5. \
    Consider re-running with a greater numSims, otherwise estimate of per Ncluster S/N will be noisy."

    if saveId is not None:
        Fit = np.array([np.exp(-0.5*(x-ampBest)**2./ampErr**2.) for x in amplitudeRange])
        Fit = Fit / (Fit.sum()*width) #normalize
        pl = Plotter()
        pl.add(amplitudeRange,Likes,label="like")
        pl.add(amplitudeRange,Fit,label="fit")
        pl.legendOn(loc = 'lower left')
        pl.done("output/"+saveId+"like.png")
        pl = Plotter()
        pl.plot2d(bigStamp/numSims)
        pl.done("output/"+saveId+"bigstamp.png")

        np.savetxt("data/"+saveId+"_m"+str(log10Moverh)+"_z"+str(z)+".txt",np.array([log10Moverh,z,1./sn]))
    
    return 1./sn
Example #18
0
                                        hdeg,
                                        width_multiplier=0.6,
                                        height_multiplier=1.2,
                                        downsample=True,
                                        pix_target_override_arcmin=pxover)

    rotmap = r.rotate(map_south)

    if k == 0:
        rottap = r.rotate(taper)
        #tmg = enmap.MapGen(r.shape_final,r.wcs_final,ps)
        w2 = np.mean(rottap**2.)
        fc = enmap.FourierCalc(r.shape_final, r.wcs_final)
        modlmap = enmap.modlmap(r.shape_final, r.wcs_final)
        bin_edges = np.arange(100, lmax, 40)
        binner = bin2D(modlmap, bin_edges)

    map_test = fullsky.submap(enmap.box(r.shape_final, r.wcs_final))
    del fullsky
    if k == 0:
        rect_taper, rw2 = fmaps.get_taper(map_test.shape,
                                          taper_percent=18.0,
                                          pad_percent=4.0,
                                          weight=None)
        rfc = enmap.FourierCalc(map_test.shape, map_test.wcs)
        rmodlmap = enmap.modlmap(map_test.shape, map_test.wcs)
        rbinner = bin2D(rmodlmap, bin_edges)

    map_test *= rect_taper
    #map_test = tmg.get_map(seed=index+int(1e6))*rottap
Example #19
0
                    wcs,
                    cov,
                    scalar=True,
                    seed=None,
                    power2d=False,
                    pixel_units=False)
modlmap = m1.modlmap()

io.quickPlot2d(m1[0], out_dir + "m1.png")
cltt = ps[0, 0]
ells = np.arange(0, cltt.size)
pl = io.Plotter(scaleY='log')
pl.add(ells, cltt * ells**2.)

debug_edges = np.arange(200, 2000, 80)
dbinner = stats.bin2D(modlmap, debug_edges)
powermap = fmaps.get_simple_power_enmap(m1[0])
cents, dcltt = dbinner.bin(powermap)

pl.add(cents, dcltt * cents**2., label="power of map")

pa = fmaps.PatchArray(shape, wcs, skip_real=True)
pa.add_noise_2d(powermap)
nT = pa.nT
cents, dcltt = dbinner.bin(nT)
pl.add(cents, dcltt * cents**2., label="binned 2d power from pa")

cov = np.zeros((3, 3, modlmap.shape[0], modlmap.shape[1]))
cov[0, 0] = nT
cov[1, 1] = nT
cov[2, 2] = nT
Example #20
0
                               zL,
                               modr_sim,
                               winAtLens,
                               overdensity=overdensity,
                               critical=critical,
                               atClusterZ=atClusterZ)
else:
    grad_cut = None

    clkk = theory.gCl("kk", fine_ells)
    clkk.resize((1, 1, clkk.size))
    kappa_map = enmap.rand_map(shape_sim[-2:], wcs_sim, cov=clkk, scalar=True)

    pkk = fmaps.get_simple_power_enmap(kappa_map)
    debug_edges = np.arange(2, 12000, 80)
    dbinner = stats.bin2D(modlmap_sim, debug_edges)
    cents, bclkk = dbinner.bin(pkk)
    clkk.resize((clkk.shape[-1]))
    pl = io.Plotter(scaleY='log', scaleX='log')
    pl.add(fine_ells, clkk)
    pl.add(cents, bclkk)
    pl.done(out_dir + "clkk.png")
phi, fphi = lt.kappa_to_phi(kappa_map, modlmap_sim, return_fphi=True)
io.quickPlot2d(kappa_map, out_dir + "kappa_map.png")
io.quickPlot2d(phi, out_dir + "phi.png")
alpha_pix = enmap.grad_pixf(fphi)

# === SIM AND RECON LOOP ===

kappa_stack = {}
if cluster:
Example #21
0
        i).zfill(2) + ".fits"
    lmap_file = "/gpfs01/astro/workarea/msyriac/data/sims/sigurd/cori/v61600/equator_curved_lensed_car_" + str(
        i).zfill(2) + ".fits"
    imap = enmap.read_map(map_file)[0]
    lmap = enmap.read_map(lmap_file)[0]
    smap = imap.submap(bbox)

    if k == 0:
        shape = smap.shape
        wcs = smap.wcs
        fc = enmap.FourierCalc(shape, wcs)
        taper, w2 = fmaps.get_taper(shape,
                                    taper_percent=12.0,
                                    pad_percent=3.0,
                                    weight=None)
        binner = stats.bin2D(enmap.modlmap(shape, wcs), bin_edges)

        shape2 = lmap.shape
        wcs2 = lmap.wcs
        fc2 = enmap.FourierCalc(shape2, wcs2)
        taper2, w22 = fmaps.get_taper(shape2,
                                      taper_percent=12.0,
                                      pad_percent=3.0,
                                      weight=None)
        binner2 = stats.bin2D(enmap.modlmap(shape2, wcs2), bin_edges)

        ells = np.arange(0, 5000, 1)
        ps = theory.lCl('TT', ells).reshape((1, 1, 5000))
        shapeN, wcsN = enmap.rect_geometry(1.2 * deg * 60., px, proj="car")
        mg = enmap.MapGen(shapeN, wcsN, ps)
Example #22
0
def stack_on_map(lite_map,
                 width_stamp_arcminute,
                 pix_scale,
                 ra_range,
                 dec_range,
                 catalog=None,
                 n_random_points=None):
    width_stamp_degrees = width_stamp_arcminute / 60.
    Np = np.int(width_stamp_arcminute / pix_scale + 0.5)
    pad = np.int(Np / 2 + 0.5)
    print("Expected width in pixels = ", Np)

    lmap = lite_map
    stack = 0
    N = 0

    if catalog is not None:
        looprange = range(0, len(catalog))
        assert n_random_points is None
        random = False
    else:
        assert n_random_points is not None
        assert len(ra_range) == 2
        assert len(dec_range) == 2
        looprange = range(0, n_random_points)
        random = True

    for i in looprange:
        if random:
            ra = np.random.uniform(*ra_range)
            dec = np.random.uniform(*dec_range)
        else:
            ra = catalog[i][1]
            dec = catalog[i][2]
        ix, iy = lmap.skyToPix(ra, dec)
        if ix >= pad and ix < lmap.Nx - pad and iy >= pad and iy < lmap.Ny - pad:
            print(i)
            #print(ra,dec)
            smap = lmap.selectSubMap(ra - width_stamp_degrees / 2.,
                                     ra + width_stamp_degrees / 2.,
                                     dec - width_stamp_degrees / 2.,
                                     dec + width_stamp_degrees / 2.)
            #print (smap.data.shape)
            #cutout = zoom(smap.data.copy(),zoom=(float(Np)/smap.data.shape[0],float(Np)/smap.data.shape[1]))
            cutout = resize(smap.data.copy(), output_shape=(Np, Np))
            #print (cutout.shape)
            stack = stack + cutout
            xMap, yMap, modRMap, xx, yy = fmaps.getRealAttributes(smap)
            N = N + 1.
        else:
            print("skip")
    stack = stack / N
    #print(stack.shape())
    #print(smap.data.shape)
    print(stack)
    print(N)
    io.quickPlot2d(stack, out_dir + "stackrandom.png")

    dt = pix_scale
    arcmax = 20.
    thetaRange = np.arange(0., arcmax, dt)
    breal = bin2D(modRMap * 180. * 60. / np.pi, thetaRange)
    cents, recons = breal.bin(stack)
    pl = Plotter(labelX='Distance from Center (arcminutes)',
                 labelY='Temperature Fluctuation ($\mu K$)',
                 ftsize=10)
    pl.add(cents, recons)
    pl._ax.axhline(y=0., ls="--", alpha=0.5)
    pl.done(out_dir + "randomprofiles.png")
    return stack, cents, recons
Example #23
0
Nlmvinv = 0.
pl = Plotter(scaleY='log')
for polComb in ['TT','TE','EE','EB']:
    kmax = getMax(polComb,tellmaxY,pellmaxY)
    bin_edges = np.arange(kmin,kmax,dell)+dell
    lmap = lm.makeEmptyCEATemplate(raSizeDeg=deg, decSizeDeg=deg,pixScaleXarcmin=px,pixScaleYarcmin=px)
    myNls = NlGenerator(lmap,theory,bin_edges,gradCut=gradCut)
    myNls.updateBins(bin_edges)

    nTX,nPX,nTY,nPY = myNls.updateNoise(beamX,noiseTX,noisePX,tellminX,tellmaxX, \
                      pellminX,pellmaxX,beamY=beamY,noiseTY=noiseTY, \
                      noisePY=noisePY,tellminY=tellminY,tellmaxY=tellmaxY, \
                      pellminY=pellminY,pellmaxY=pellmaxY,lkneesX=(lkneeTX,lkneePX),alphasX=(alphaTX,alphaPX), \
                                        lkneesY=(lkneeTY,lkneePY),alphasY=(alphaTY,alphaPY),lxcutTX=lxcutTX, \
                                        lxcutTY=lxcutTY,lycutTX=lycutTX,lycutTY=lycutTY, \
                                        lxcutPX=lxcutPX,lxcutPY=lxcutPY,lycutPX=lycutPX,lycutPY=lycutPY, \
                                        fgFileX=fgFileX,beamFileX=beamFileX,fgFileY=fgFileY,beamFileY=beamFileY )


    cbinner = bin2D(myNls.N.modLMap,cmb_bin_edges)
    ells, Nells = cbinner.bin(nTX)

    pl = Plotter(scaleY='log')
    pl.add(ells,Nells*ells**2.*TCMB**2.)
    pl.add(ells,Nells*ells**2.*TCMB**2.)
    tells,tnlstt = np.loadtxt('data/louisCls.dat',delimiter=',',unpack=True)
    pl.add(tells,tnlstt)
    pl.done("output/compnl.png")
    sys.exit()
           
Example #24
0
    comS = cc.results.comoving_radial_distance(cc.cmbZ)*cc.h
    comL = cc.results.comoving_radial_distance(zL)*cc.h
    winAtLens = (comS-comL)/comS
    kappa,r500 = NFWkappa(cc,massOverh,concentration,zL,modrmap* 180.*60./np.pi,winAtLens,
                              overdensity=overdensity,critical=critical,atClusterZ=atClusterZ)

    return kappa

cc = ClusterCosmology(lmax=8500,pickling=True)
widtharc = 50.
px = 0.5
shape,wcs = enmap.get_enmap_patch(widtharc,px)
modrmap = enmap.modrmap(shape,wcs)
modlmap = enmap.modlmap(shape,wcs)
rbins = np.arange(0.,10.,1.0)
rbinner = stats.bin2D(modrmap*60.*180./np.pi,rbins)
true_mass = 2.e14
true2d = get_nfw(true_mass)
kellmin = 200
kellmax = 8500
true2d = enmap.ndmap(fmaps.filter_map(true2d,true2d*0.+1.,modlmap,lowPass=kellmax,highPass=kellmin),wcs)


Nsims = 1000
cov = np.ones((1,1,8500))*0.00000001
ngen = enmap.MapGen(shape,wcs,cov)

out_dir = os.environ['WWW']+"plots/cgauss_"

# Efficiently distribute sims over MPI cores
num_each,each_tasks = mpi_distribute(Nsims,numcores)
Example #25
0
        for nstep in range(1, 8):
            iter_delensed = lensing.delens_map(lensed.copy(),
                                               grad_phi,
                                               nstep=nstep,
                                               order=lens_order,
                                               mode="spline",
                                               border="cyclic")
            # Check residual

            iter_residual = iter_delensed - unlensed
            iters.append(iter_residual)

            #io.quickPlot2d(iter_residual,out_dir+"iterres_"+str(nstep).zfill(2)+".png")

        bin_edges = np.arange(0., 20., 0.5)
        binner = stats.bin2D(modr_sim, bin_edges)

        cents, prof = binner.bin(lens_residual)
        pl.add(cents,
               np.abs(prof),
               ls="--",
               label=("no delensing" if k == 0 else None),
               alpha=alpha,
               color="C0")
        cents, prof = binner.bin(simple_residual)
        pl.add(cents,
               np.abs(prof),
               ls="--",
               label=("anti-lensing" if k == 0 else None),
               alpha=alpha,
               color="C1")
Example #26
0
if not (saveMf):
    try:
        mf = np.loadtxt("data/meanfield.dat")
        kappaStack -= mf
        print("subtracted meanfield")
    except:
        pass

stepmin = kellmin

kappaStack = fmaps.stepFunctionFilterLiteMap(kappaStack,
                                             modLMap,
                                             kellmax,
                                             ellMin=stepmin)

pl = Plotter()
pl.plot2d(kappaStack)
pl.done(outDir + "recon.png")

dt = pixScale
arcmax = 20.
thetaRange = np.arange(0., arcmax, dt)
breal = bin2D(modRMap * 180. * 60. / np.pi, thetaRange)
cents, recons = breal.bin(kappaStack)

pl = Plotter()
pl.add(cents, recons)
pl._ax.axhline(y=0., ls="--", alpha=0.5)
pl.done(outDir + "profiles.png")
Example #27
0
        template_dat = fmaps.simple_flipper_template_from_enmap(measured.shape,measured.wcs)
        lxmap_dat,lymap_dat,modlmap_dat,angmap_dat,lx_dat,ly_dat = fmaps.get_ft_attributes_enmap(shape_dat,wcs_dat)
        

        taper_percent = 15.0
        Ny,Nx = shape_dat
        taper = fmaps.cosineWindow(Ny,Nx,lenApodY=taper_percent*min(Ny,Nx)/100.,lenApodX=taper_percent*min(Ny,Nx)/100.,padY=0,padX=0)
        tapered = measured*taper
        # io.quickPlot2d(tapered,"map.png")
        w2 = np.mean(taper**2.)
        w4 = np.mean(taper**4.)

        
        debug_edges = np.arange(400,8000,150)
        dbinner_dat = stats.bin2D(modlmap_dat,debug_edges)


        # p2d = fmaps.get_simple_power_enmap(tapered)/w2
        # cents,dcltt = dbinner_dat.bin(p2d)
        # cltt = theory.lCl("TT",fine_ells)
        # ucltt = theory.uCl("TT",fine_ells)
        # pl = io.Plotter(scaleY='log')
        # pl.add(cents,dcltt*cents**2.)
        # pl.add(fine_ells,cltt*fine_ells**2.)
        # pl.add(fine_ells,ucltt*fine_ells**2.)
        # pl.done("cls.png")


        
        nT = modlmap_dat*0.