예제 #1
0
 def solve(self, maxiter=100, cg_tol=1e-7, verbose=False, dump_dir=None):
     if np.sum(self.highres_mask) == 0: return None
     solver = cg.CG(self.A, self.rhs.reshape(-1), M=self.M)
     for i in range(maxiter):
         t1 = time.time()
         solver.step()
         t2 = time.time()
         if verbose:
             print "%5d %15.7e %5.2f" % (solver.i, solver.err, t2 - t1)
         if dump_dir is not None and solver.i in [1, 2, 5, 10, 20, 50
                                                  ] + range(
                                                      100, 10000, 100):
             m = enmap.ndmap(solver.x.reshape(self.shape), self.wcs)
             enmap.write_map(dump_dir + "/step%04d.fits" % solver.i, m)
         if solver.err < cg_tol:
             if dump_dir is not None:
                 m = enmap.ndmap(solver.x.reshape(self.shape), self.wcs)
                 enmap.write_map(dump_dir + "/step_final.fits", m)
             break
     tot_map = self.highres_mask * solver.x.reshape(self.shape)
     tot_div = self.highres_mask * self.tot_div
     # Get rid of the fourier padding
     ny, nx = tot_map.shape[-2:]
     tot_map = tot_map[..., :ny - self.ffpad[0], :nx - self.ffpad[1]]
     tot_div = tot_div[..., :ny - self.ffpad[0], :nx - self.ffpad[1]]
     return bunch.Bunch(map=tot_map, div=tot_div)
예제 #2
0
def read_sdata(ifile):
    # Output thumb for this tod
    with h5py.File(ifile, "r") as hfile:
        sdata = [None for key in hfile]
        for key in hfile:
            ind = int(key)
            g = hfile[key]
            sdat = bunch.Bunch()
            # First parse the wcs
            hwcs = g["wcs"]
            header = astropy.io.fits.Header()
            for key in hwcs:
                header[key] = hwcs[key].value
            wcs = wcsutils.WCS(header).sub(2)
            # Then get the site
            sdat.site = bunch.Bunch(
                **{key: g["site/" + key].value
                   for key in g["site"]})
            # And the rest
            for key in [
                    "map", "div", "srcpos", "sid", "vel", "fknee", "alpha",
                    "id", "ctime", "dur", "el", "az", "off"
            ]:
                sdat[key] = g[key].value
            sdat.map = enmap.ndmap(fixorder(sdat.map), wcs)
            sdat.div = enmap.ndmap(fixorder(sdat.div), wcs)
            sdata[ind] = sdat
    return sdata
예제 #3
0
def l(cseed,kseed,returnk=False,index=None):
    cname = fout_dir+"lensed_covseed_"+str(args.covseed).zfill(3)+"_cmbseed_"+str(cseed).zfill(5)+"_kseed_"+str(kseed).zfill(5)+".hdf"
    if unlensed:
        seedroot = (covseed)*Nsets*Nsims
        lensedt = parray_dat.get_unlensed_cmb(seed=seedroot+cseed,scalar=False)
    else:
        lensedt = enmap.read_map(cname)[0] if polsims else enmap.read_map(cname)
    # -- add beam and noise if you want --
    if "noiseless" not in expf_name:
        assert index is not None
        if rank==0: print("Adding beam...")
        flensed = fftfast.fft(lensedt,axes=[-2,-1])
        flensed *= parray_dat.lbeam
        lensedt = fftfast.ifft(flensed,axes=[-2,-1],normalize=True).real
        if rank==0: print("Adding noise...")
        seedroot = (covseed+1)*Nsets*Nsims # WARNING: noise sims will be correlated with CMB from the next covseed
        nseed = seedroot+index
        noise = parray_dat.get_noise_sim(seed=nseed)
        if paper:
            cents, noise1d = lbinner.bin(power(noise)[0])
            mpibox.add_to_stats('noisett',noise1d)        
        lensedt += noise
        
    lensedt = enmap.ndmap(lensedt,wcs_dat)
    
    if returnk:
        kname = fout_dir+"kappa_covseed_"+str(args.covseed).zfill(3)+"_kseed_"+str(kseed).zfill(5)+".hdf"
        return lensedt,enmap.read_map(kname)
    else:
        return lensedt
예제 #4
0
 def get_map(self,weights=None):
     if self.verbose: print("Calculating histogram...")
     if self.curved:
         return np.histogram(self.pixs,bins=self.shape,weights=weights,range=[0,self.shape])[0].astype(np.float32)
     else:
         Ny,Nx = self.shape
         return enmap.ndmap(np.histogram2d(self.pixs[0,:],self.pixs[1,:],bins=self.shape,weights=weights,range=[[0,Ny],[0,Nx]])[0],self.wcs)
예제 #5
0
파일: aberration.py 프로젝트: Nium14/enlib
def aberrate(imap,
             dir,
             beta,
             mode="wrap",
             order=3,
             recenter=False,
             modulation=True):
    pol = imap.ndim > 2
    pos = imap.posmap()
    # The ::-1 stuff switches between dec,ra and ra,dec ordering.
    # It is a bit confusing to have different conventions in enmap
    # and coordinates.
    pos = remap(pos[::-1],
                dir,
                beta,
                pol=pol,
                recenter=recenter,
                modulation=modulation)
    pos[:2] = pos[1::-1]
    pix = imap.sky2pix(pos[:2], corner=True)  # interpol needs corners
    omap = en.ndmap(utils.interpol(imap, pix, mode=mode, order=order),
                    imap.wcs)
    if pol:
        c, s = np.cos(2 * pos[2]), np.sin(2 * pos[2])
        omap[1] = c * omap[1] + s * omap[2]
        omap[2] = -s * omap[1] + c * omap[2]
    if modulation:
        omap *= pos[2 + pol]
    return omap
예제 #6
0
 def get_map(self, weights=None):
     Ny, Nx = self.shape
     print("Calculating histogram...")
     return enmap.ndmap(
         np.histogram2d(self.pixs[0, :],
                        self.pixs[1, :],
                        bins=self.shape,
                        weights=weights,
                        range=[[0, Ny], [0, Nx]])[0], self.wcs)
예제 #7
0
    def rotate(self, imap, **kwargs):
        rotated = MapRotator.rotate(self, imap, **kwargs)

        if self.downsample:
            from enlib import resample
            return enmap.ndmap(
                resample.resample_fft(rotated, self.shape_final),
                self.wcs_final)
        else:
            return rotated
예제 #8
0
 def update_kappa(self, kappa):
     # Converts kappa map to pixel displacements
     import alhazen.lensTools as lt
     fphi = lt.kappa_to_fphi(kappa, self.modlmap)
     grad_phi = enmap.gradf(enmap.ndmap(fphi, self.wcs))
     pos = self.posmap + grad_phi
     self._displace_pix = enmap.sky2pix(self.shape,
                                        self.wcs,
                                        pos,
                                        safe=False)
예제 #9
0
def sim(cseed, kseed, skip_kappa_verif=False):

    if not (vonly):
        unlensed = parray_sim.get_unlensed_cmb(seed=seedroot + cseed,
                                               scalar=False)
        kappa = aio.kappa_from_config(Config,
                                      kappa_section,
                                      parray_sim,
                                      seed=seedroot + kseed)
        lensed = parray_sim.get_lensed(unlensed,
                                       order=lens_order,
                                       mode="spline",
                                       border="cyclic")

        luteb, dummy = sverif_cmb.add_power("unlensed", unlensed)
        llteb, dummy = sverif_cmb.add_power("lensed", lensed)
        if not (skip_kappa_verif):
            lk, dummy = sverif_kappa.add_power("kappa", kappa)

    cname = fout_dir + "lensed_covseed_" + str(
        args.covseed).zfill(3) + "_cmbseed_" + str(cseed).zfill(
            5) + "_kseed_" + str(kseed).zfill(5) + ".hdf"
    kname = fout_dir + "kappa_covseed_" + str(
        args.covseed).zfill(3) + "_kseed_" + str(kseed).zfill(5) + ".hdf"

    if vonly:
        dlensed = enmap.read_map(cname)
        dkappa = enmap.read_map(kname)
    else:
        dlensed = lensed if abs(pixratio - 1.) < 1.e-3 else enmap.ndmap(
            resample.resample_fft(lensed, shape_dat), wcs_dat)
        dkappa = kappa if abs(pixratio - 1.) < 1.e-3 else enmap.ndmap(
            resample.resample_fft(kappa, shape_dat[-2:]), wcs_dat)
        dlensed.write(cname)
        dkappa.write(kname)

    dllteb, dummy = sverif_dcmb.add_power("dlensed", dlensed)
    if not (skip_kappa_verif):
        dlk, dummy = sverif_dkappa.add_power("dkappa", dkappa)
예제 #10
0
def read_maps(fmt, n, ntot=4):
    try:
        maps = en.read_map(fmt)
        if maps.ndim == ntot - 1: maps = en.enmap([maps] * n, maps.wcs)
        if maps.ndim != ntot:
            raise ValueError("Map %s must have %d dimensions" % (fmt, ntot))
        return maps
    except (IOError, OSError):
        maps = [en.read_map(fmt % i) for i in range(n)]
        maps = en.ndmap(maps, maps[0].wcs)
        if maps.ndim != ntot:
            maps = maps.reshape(maps.shape[:-2] + (1, ) * (maps.ndim - ntot) +
                                maps.shape[-2:])
        return maps
예제 #11
0
def read_thumb_data(fname):
	res    = bunch.Bunch()
	hdus   = astropy.io.fits.open(fname)
	header = hdus[0].header
	with warnings.catch_warnings():
		wcs = wcsutils.WCS(header).sub(2)
	res.rhs, res.div, res.corr = enmap.fix_endian(enmap.ndmap(hdus[0].data, wcs))
	res.srcinfo = hdus[1].data
	res.detinfo = hdus[2].data
	res.id  = header["id"]
	res.off = np.array([float(header["off_x"]),float(header["off_y"])])*utils.arcmin
	for key in ["bore_az1","bore_az2","bore_el"]:
		res[key] = float(header[key])*utils.degree
	res.ctime = float(header["ctime"])
	return res
예제 #12
0
def read_sdata(ifile):
	# Output thumb for this tod
	with h5py.File(ifile, "r") as hfile:
		sdata = [None for key in hfile]
		for key in hfile:
			ind  = int(key)
			g    = hfile[key]
			sdat = bunch.Bunch()
			# First parse the wcs
			hwcs = g["wcs"]
			header = astropy.io.fits.Header()
			for key in hwcs:
				header[key] = hwcs[key].value
			wcs = wcsutils.WCS(header).sub(2)
			# Then get the site
			sdat.site= bunch.Bunch(**{key:g["site/"+key].value for key in g["site"]})
			# And the rest
			for key in ["map","div","srcpos","sid","vel","fknee","alpha",
					"id", "ctime", "dur", "el", "az", "off"]:
				sdat[key] = g[key].value
			sdat.map = enmap.ndmap(fixorder(sdat.map),wcs)
			sdat.div = enmap.ndmap(fixorder(sdat.div),wcs)
			sdata[ind] = sdat
	return sdata
예제 #13
0
def read_thumb_data(fname):
	res    = bunch.Bunch()
	hdus   = astropy.io.fits.open(fname)
	header = hdus[0].header
	with warnings.catch_warnings():
		wcs = wcsutils.WCS(header).sub(2)
	res.rhs, res.div, res.corr = enmap.fix_endian(enmap.ndmap(hdus[0].data, wcs))
	res.srcinfo = hdus[1].data
	res.detinfo = hdus[2].data
	res.id  = header["id"]
	res.off = np.array([float(header["off_x"]),float(header["off_y"])])*utils.arcmin
	for key in ["bore_az1","bore_az2","bore_el"]:
		res[key] = float(header[key])*utils.degree
	res.ctime = float(header["ctime"])
	return res
예제 #14
0
 def calc_precon(self):
     datasets = self.datasets
     # Build the preconditioner
     self.tot_div = enmap.ndmap(
         np.sum([
             split.data.div for dataset in datasets
             for split in dataset.splits
         ], 0), self.wcs)
     self.tot_idiv = self.tot_div.copy()
     self.tot_idiv[self.tot_idiv > 0] **= -1
     # Find the part of the sky hit by high-res data
     self.highres_mask = enmap.zeros(self.shape[-2:], self.wcs, np.bool)
     for dataset in datasets:
         if dataset.lowres: continue
         for split in dataset.splits:
             if split.data.empty or not split.active: continue
             self.highres_mask |= split.data.div > 0
예제 #15
0
    def project(self, hp_map, interpolate=True):
        """
	hp_map -- array-like healpix map
	interpolate -- boolean
	"""

        import healpy as hp
        imap = enmap.zeros(self.shape, self.wcs)

        # Not as slow as you'd expect
        if interpolate:
            imap[self.y, self.x] = hp.get_interp_val(hp_map, self.thOut,
                                                     self.phOut)
        else:
            ind = hp.ang2pix(hp.get_nside(hp_map), self.thOut, self.phOut)
            imap[:] = 0.
            imap[[self.y, self.x]] = hp_map[ind]

        return enmap.ndmap(imap, self.wcs)
예제 #16
0
    kappa = enmap.read_map(sigurd_kappa_file(index)) * taper
    cmb = enmap.read_map(sigurd_cmb_file(index))[0]  #/2.7255e6
    ltt2d = fmaps.get_simple_power_enmap(cmb * taper)

    ccents, ltt = lbinner_dat.bin(ltt2d) / w2
    mpibox.add_to_stats("lcl", ltt)

    if rank == 0: print("Reconstructing...")
    measured = cmb * taper
    fkmaps = fftfast.fft(measured, axes=[-2, -1])
    qest.updateTEB_X(fkmaps, alreadyFTed=True)
    qest.updateTEB_Y()
    with io.nostdout():
        rawkappa = qest.getKappa("TT").real

    kappa_recon = enmap.ndmap(rawkappa, wcs_dat) - mf
    if save_meanfield: mpibox.add_to_stack("meanfield", kappa_recon)
    #if save is not None: enmap.write_fits(save_func(index),kappa_recon)

    if rank == 0: print("Calculating kappa powers and binning...")

    apower = fmaps.get_simple_power_enmap(enmap1=kappa_recon) / w4

    data_power_2d_TT = fmaps.get_simple_power_enmap(measured)
    sd = qest.N.super_dumb_N0_TTTT(data_power_2d_TT) / w2**2.
    lcents, sdp = lbinner_dat.bin(sd)
    #np.savetxt(save_func(index,"superdumbn0"),np.vstack((lcents,sdp)).T)

    mpibox.add_to_stats("superdumbs", sdp)
    n0subbed = apower - sd
    lcents, rclkk = lbinner_dat.bin(n0subbed)
예제 #17
0
        from alhazen.halos import nfw_kappa
        kappa = nfw_kappa(cluster_mass,parray_sim.modrmap,cc)
        #kappa = parray_sim.get_grf_kappa(seed=1)
        phi, fphi = lt.kappa_to_phi(kappa,parray_sim.modlmap,return_fphi=True)
        grad_phi = enmap.grad(phi)
            

    if rank==0: print(("Generating unlensed CMB for ", k, "..."))
    unlensed = parray_sim.get_unlensed_cmb(seed=index)
    if rank==0: print("Lensing...")
    lensed = unlensed if nolens else lensing.lens_map(unlensed.copy(), grad_phi, order=lens_order, mode="spline", border="cyclic", trans=False, deriv=False, h=1e-7)
    #lensed = lensing.lens_map_flat(unlensed.copy(), phi, order=lens_order)
    if rank==0: print("Downsampling...")
    cmb = lensed if abs(pixratio-1.)<1.e-3 else resample.resample_fft(lensed,shape_dat)
    cmb = enmap.ndmap(cmb,wcs_dat)
    if rank==0: print("Adding noise...")
    flensed = fftfast.fft(cmb,axes=[-2,-1])
    flensed *= parray_dat.lbeam
    lensedt = fftfast.ifft(flensed,axes=[-2,-1],normalize=True).real
    noise = parray_dat.get_noise_sim(seed=index+10000000)
    lensedt += noise
    cmb = lensedt
        

    
    if rank==0: print("Filtering and binning input kappa...")
    dkappa = enmap.ndmap(fmaps.filter_map(kappa,kappa*0.+1.,parray_sim.modlmap,lowPass=kellmax,highPass=kellmin),wcs_sim)
    dkappa = dkappa if abs(pixratio-1.)<1.e-3 else enmap.ndmap(resample.resample_fft(dkappa,shape_dat),wcs_dat)
    cents,kappa1d = binner_dat.bin(dkappa)
    mpibox.add_to_stats("input_kappa1d",kappa1d)
예제 #18
0
    # === ADD NOISE BEFORE DOWNSAMPLE
    # if rank==0: print "Beam convolving..."
    # olensed = enmap.ndmap(lensed.copy() if abs(pixratio-1.)<1.e-3 else resample.resample_fft(lensed.copy(),shape_dat),wcs_dat)
    # flensed = fftfast.fft(lensed,axes=[-2,-1])
    # flensed *= parray_sim.lbeam
    # lensed = fftfast.ifft(flensed,axes=[-2,-1],normalize=True).real
    # if rank==0: print "Adding noise..."
    # noise = parray_sim.get_noise_sim(seed=index+20000)
    # lensed += noise
    # if rank==0: print "Downsampling..."
    # cmb = lensed if abs(pixratio-1.)<1.e-3 else resample.resample_fft(lensed,shape_dat)

    # === ADD NOISE AFTER DOWNSAMPLE
    if rank == 0: print "Beam convolving..."
    olensed = enmap.ndmap(
        lensed.copy() if abs(pixratio - 1.) < 1.e-3 else resample.resample_fft(
            lensed.copy(), shape_dat), wcs_dat)
    flensed = fftfast.fft(olensed, axes=[-2, -1])
    flensed *= parray_dat.lbeam
    lensed = fftfast.ifft(flensed, axes=[-2, -1], normalize=True).real
    if rank == 0: print "Adding noise..."
    noise = parray_dat.get_noise_sim(seed=index + 20000)

    lcents, noise1d = lbinner_dat.bin(fmaps.get_simple_power_enmap(noise))
    mpibox.add_to_stats('noisett', noise1d)

    lensed += noise
    if rank == 0: print "Downsampling..."
    cmb = lensed

    cmb = enmap.ndmap(cmb, wcs_dat)
예제 #19
0
        hits = hfile["hits"].value
        srate = hfile["srate"].value
        speed = hfile["speed"].value * utils.degree
        inspec = hfile["inspec"].value
        offsets = hfile["offsets"].value * utils.degree
        site = bunch.Bunch(
            **{k: hfile["site"][k].value
               for k in hfile["site"]})
        pattern = hfile["pattern"].value * utils.degree
        hwcs = hfile["wcs"]
        header = astropy.io.fits.Header()
        for key in hwcs:
            header[key] = hwcs[key].value
        wcs = wcsutils.WCS(header).sub(2)
    # Set up our maps
    rhs = enmap.ndmap(rhs, wcs)
    hits = enmap.ndmap(hits, wcs)
    rhs = prepare(rhs)
    hits = prepare(hits, hitmap=True)

    # Turn offsets into an average array offset and detector offsets relative to that,
    # and use the array offset to set up the Unskew matrix.
    offset_array = np.mean(offsets, 0)
    offset_det = offsets - offset_array
    ndet = len(offsets)
    if args.unskew == "curved":
        U = UnskewCurved(rhs.shape,
                         rhs.wcs,
                         pattern,
                         offset_array,
                         site,
예제 #20
0
	with h5py.File(infofile, "r") as hfile:
		rhs     = hfile["rhs"].value
		hits    = hfile["hits"].value
		srate   = hfile["srate"].value
		speed   = hfile["speed"].value   * utils.degree
		inspec  = hfile["inspec"].value
		offsets = hfile["offsets"].value * utils.degree
		site    = bunch.Bunch(**{k:hfile["site"][k].value for k in hfile["site"]})
		pattern = hfile["pattern"].value * utils.degree
		hwcs    = hfile["wcs"]
		header = astropy.io.fits.Header()
		for key in hwcs:
			header[key] = hwcs[key].value
		wcs = wcsutils.WCS(header).sub(2)
	# Set up our maps
	rhs  = enmap.ndmap(rhs,  wcs)
	hits = enmap.ndmap(hits, wcs)
	rhs  = prepare(rhs)
	hits = prepare(hits, hitmap=True)

	# Turn offsets into an average array offset and detector offsets relative to that,
	# and use the array offset to set up the Unskew matrix.
	offset_array = np.mean(offsets,0)
	offset_det   = offsets - offset_array
	ndet         = len(offsets)
	if args.unskew == "curved":
		U = UnskewCurved(rhs.shape, rhs.wcs, pattern, offset_array, site, order=args.order)
	elif args.unskew == "shift":
		U = UnskewShift(rhs.shape, rhs.wcs, pattern, offset_array, site)
	else: raise ValueError(args.unskew)
	scale = calc_scale(inspec.size, srate, speed, enmap.pixshape(U.ushape, U.uwcs)[0])
예제 #21
0
if args.template:
	templ = enmap.read_map(args.template)
	shape, wcs = templ.shape, templ.wcs
else:
	shape, wcs = pixie.fullsky_geometry(res=config.patch_res*utils.degree)

if args.apply_beam:
	print "Applying beam"
	for i, field in enumerate(fields):
		print field.name
		fields[i] = field.to_beam(beam)
	print "Beam done"

posmap = enmap.posmap(shape, wcs)
maps = [[field.at(freq, posmap) for freq in freqs] for field in fields]
maps.insert(0, np.sum(maps,0))
maps = enmap.ndmap(np.array(maps), wcs)

# We now have [comp,freq,stokes,y,x]

if args.unit:
	if args.unit == "cmb":
		# CMB uK equivalent
		scale = pixie.blackbody(freqs, pixie.Tcmb)
		maps *= pixie.Tcmb * 1e6 / scale[:,None,None,None]
	else:
		raise ValueError("Unknown unit '%s'" % args.unit)

# And write our results
enmap.write_map(args.omap, maps)
예제 #22
0
    assert kappa_file[-9:] == cmb_file[-9:]

    k += 1
    if rank == 0: print(("Rank ", rank, " doing cutout ", index))
    if not (simulated_kappa):
        if liu:
            kappa = liucon.get_kappa(index + 1)
        elif sigurd:
            kappa = enmap.read_map(sigurd_kappa_file(index)) * taper
            #phi = enmap.read_map(sigurd_phi_file(index))
            #fkphi = fftfast.fft(phi*taper,axes=[-2,-1])
            #lmap = parray_sim.modlmap
            #fkkappa = fkphi * lmap * (lmap+1.)/2.
            #kappa = fftfast.ifft(fkkappa,axes=[-2,-1],normalize=True)
        else:
            hikappa = enmap.ndmap(np.load(kappa_file), wcs_dat)
            kappa = enmap.upgrade(
                hikappa, pixratio) if abs(pixratio - 1.) > 1.e-3 else hikappa
        # phi, fphi = lt.kappa_to_phi(kappa,parray_sim.modlmap,return_fphi=True)
        # alpha_pix = enmap.grad_pixf(fphi)
    else:
        if k == 0:

            if cluster:
                from alhazen.halos import NFWkappa

                massOverh = 2.e14
                zL = 0.7
                overdensity = 180.
                critical = False
                atClusterZ = False
예제 #23
0
    def __init__(self,
                 splits=None,
                 wmap=None,
                 mask=None,
                 kmask=None,
                 directory=None,
                 spec_smooth_width=2.,
                 skip_beam=True,
                 skip_mask=True,
                 skip_kmask=True,
                 skip_cross=True,
                 iau_convention=False):
        """
        shape, wcs for geometry
        unmasked splits
        hit counts wmap
        real-space mask that must include a taper. Can be 3-dimensional if Q/U different from I.
        k-space kmask
        """

        if directory is not None:
            self._load(directory, skip_beam, skip_mask, skip_kmask, skip_cross)
        else:

            shape = splits[0].shape
            wcs = splits[0].wcs

            if wmap is None: wmap = enmap.ones(shape[-2:], wcs)
            if mask is None: mask = np.ones(shape[-2:])
            if kmask is None: kmask = np.ones(shape[-2:])

            wmap = enmap.ndmap(wmap, wcs)

            osplits = [split * mask for split in splits]
            fc = enmap.FourierCalc(shape, wcs, iau_convention)
            n2d, p2d = noise_from_splits(osplits, fc)
            w2 = np.mean(mask**2.)
            n2d *= (1. / w2)
            p2d *= (1. / w2)

            n2d = enmap.smooth_spectrum(n2d,
                                        kernel="gauss",
                                        weight="mode",
                                        width=spec_smooth_width)
            self.spec_smooth_width = spec_smooth_width
            ncomp = shape[0] if len(shape) > 2 else 1

            self.cross2d = p2d
            self.cross2d *= kmask
            n2d *= kmask
            self.noise2d = n2d.reshape((ncomp, ncomp, shape[-2], shape[-1]))
            self.mask = mask
            self.kmask = kmask
            self.wmap = wmap
            self.shape = shape
            self.wcs = wcs
        self.ngen = enmap.MapGen(self.shape, self.wcs, self.noise2d)
        #self.noise_modulation = 1./np.sqrt(self.wmap)/np.sqrt(np.mean((1./self.wmap)))
        wt = 1. / np.sqrt(self.wmap)
        wtw2 = np.mean(1. / wt**2.)
        self.noise_modulation = wt * np.sqrt(wtw2)
예제 #24
0
    if rank == 0:
        print(
            ("Rank ", rank, " doing job ", k + 1, " / ", len(my_tasks), "..."))
    unlensed = parray_sim.get_unlensed_cmb(seed=index, scalar=False)
    luteb, dummy = sverif_cmb.add_power("unlensed", unlensed)

    lensed = lensing.lens_map(unlensed.copy(), grad_phi, order=lens_order)
    lensed += parray_dat.get_noise_sim(seed=index + 100000)
    llteb, dummy = sverif_cmb.add_power("lensed", lensed)

    qest.updateTEB_X(llteb, alreadyFTed=True)
    qest.updateTEB_Y(alreadyFTed=True)
    with io.nostdout():
        rawkappa = qest.getKappa("TT").real

    kappa_recon = enmap.ndmap(rawkappa, wcs_dat)
    mpibox.add_to_stack("kapparecon", kappa_recon)

    if rank == 0 and k == 0:
        io.quickPlot2d(kappa, out_dir + "kappa.png")
        #io.quickPlot2d(kappa_model,out_dir+"kappamodel.png")
        io.quickPlot2d(unlensed, out_dir + "unlensed.png")
        io.quickPlot2d(lensed - unlensed, out_dir + "difflensed.png")
        # io.quickPlot2d(pdelensed-unlensed,out_dir+"diffpdelensed.png")
        io.quickPlot2d(kappa_recon, out_dir + "rtt.png")

    lrtt, likk = sverif_kappa.add_power("rttXikk", kappa_recon, imap2=kappa)

    clkk2d = theory.gCl('kk', modlmap_dat)
    nlkk2d = qest.N.Nlkk['TT']
    wiener2d = clkk2d / (clkk2d + nlkk2d)
예제 #25
0
    if rank == 0:
        print(
            ("Rank ", rank, " doing job ", k + 1, " / ", len(my_tasks), "..."))
    unlensed = parray_sim.get_unlensed_cmb(seed=index, scalar=False)
    luteb, dummy = sverif_cmb.add_power("unlensed", unlensed)

    lensed = lensing.lens_map(unlensed.copy(), grad_phi, order=lens_order)
    lensed += parray_dat.get_noise_sim(seed=index + 100000)
    llteb, dummy = sverif_cmb.add_power("lensed", lensed)

    qest.updateTEB_X(llteb, alreadyFTed=True)
    qest.updateTEB_Y(alreadyFTed=True)
    with io.nostdout():
        rawkappa = qest.getKappa("TT").real

    kappa_recon = enmap.ndmap(rawkappa, wcs_dat)
    rcents, recon1d = binner_dat.bin(kappa_recon)
    mpibox.add_to_stats("kapparecon1d", recon1d)
    mpibox.add_to_stack("kapparecon", kappa_recon)

    if rank == 0 and k == 0:
        io.quickPlot2d(kappa, out_dir + "kappa.png")
        io.quickPlot2d(kappa_model, out_dir + "kappamodel.png")
        io.quickPlot2d(unlensed, out_dir + "unlensed.png")
        io.quickPlot2d(lensed - unlensed, out_dir + "difflensed.png")
        # io.quickPlot2d(pdelensed-unlensed,out_dir+"diffpdelensed.png")
        io.quickPlot2d(kappa_recon, out_dir + "rtt.png")

    lrtt, likk = sverif_kappa.add_power("rttXikk", kappa_recon, imap2=kappa)

    # BEGIN ITERATIVE DELENSING
예제 #26
0
파일: simtod.py 프로젝트: amaurea/tenki
def get_model(s, area):
	pos = area.posmap().reshape(2,-1)[::-1].T
	model = np.rollaxis(s.get_model(pos),-1).reshape(-1,area.shape[1],area.shape[2])
	return enmap.ndmap(model, area.wcs)[:area.shape[0]]
예제 #27
0
if args.template:
    templ = enmap.read_map(args.template)
    shape, wcs = templ.shape, templ.wcs
else:
    shape, wcs = pixie.fullsky_geometry(res=config.patch_res * utils.degree)

if args.apply_beam:
    print "Applying beam"
    for i, field in enumerate(fields):
        print field.name
        fields[i] = field.to_beam(beam)
    print "Beam done"

posmap = enmap.posmap(shape, wcs)
maps = [[field.at(freq, posmap) for freq in freqs] for field in fields]
maps.insert(0, np.sum(maps, 0))
maps = enmap.ndmap(np.array(maps), wcs)

# We now have [comp,freq,stokes,y,x]

if args.unit:
    if args.unit == "cmb":
        # CMB uK equivalent
        scale = pixie.blackbody(freqs, pixie.Tcmb)
        maps *= pixie.Tcmb * 1e6 / scale[:, None, None, None]
    else:
        raise ValueError("Unknown unit '%s'" % args.unit)

# And write our results
enmap.write_map(args.omap, maps)
예제 #28
0
    lensed = lensing.lens_map(unlensed.copy(), grad_phi, order=lens_order)
    llteb, dummy = sverif_cmb.add_power("lensed", lensed)

    pdelensed = lensing.delens_map(lensed,
                                   grad_phi,
                                   nstep=delens_steps,
                                   order=lens_order)
    lpteb, dummy = sverif_cmb.add_power("pdelensed", pdelensed)

    qest.updateTEB_X(llteb[0], llteb[1], llteb[2], alreadyFTed=True)
    qest.updateTEB_Y(alreadyFTed=True)
    with io.nostdout():
        rawkappa_TT = qest.getKappa("TT").real
        rawkappa_EB = qest.getKappa("EB").real

    kappa_recon_TT = enmap.ndmap(rawkappa_TT, wcs_dat)
    kappa_recon_EB = enmap.ndmap(rawkappa_EB, wcs_dat)

    if rank == 0 and k == 0:
        io.quickPlot2d(kappa_recon_TT, out_dir + "rtt.png")
        io.quickPlot2d(kappa_recon_EB, out_dir + "reb.png")

    # rphitt, rfphitt = lt.kappa_to_phi(kappa_recon_TT,parray_dat.modlmap,return_fphi=True)
    # rgrad_phitt = enmap.grad(rphitt)

    # rphieb, rfphieb = lt.kappa_to_phi(kappa_recon_EB,parray_dat.modlmap,return_fphi=True)
    # rgrad_phieb = enmap.grad(rphieb)

    lrtt, lreb = sverif_kappa.add_power("rttXreb",
                                        kappa_recon_TT,
                                        imap2=kappa_recon_EB)
예제 #29
0
px_dat = analysis_resolution
del fMask
del fMaskCMB_T
del fMaskCMB_P
del nT
del nP

k = -1
for index in my_tasks:

    k += 1
    if rank == 0: print(("Rank ", rank, " doing cutout ", index))
    kappa = enmap.read_map(alex_kappa_file(index))

    ucmb = enmap.ndmap(
        enmap.read_map(alex_ucmb_file(index)) / 2.7255e6, wcs_dat)
    utt2d = fmaps.get_simple_power_enmap(ucmb)
    ccents, utt = lbinner_dat.bin(utt2d)
    mpibox.add_to_stats("ucl", utt)
    del ucmb
    del utt2d

    cmb = enmap.ndmap(enmap.read_map(alex_cmb_file(index)) / 2.7255e6, wcs_dat)
    ltt2d = fmaps.get_simple_power_enmap(cmb)
    ccents, ltt = lbinner_dat.bin(ltt2d)
    mpibox.add_to_stats("lcl", ltt)
    del ltt2d

    if rank == 0: print("Reconstructing...")
    measured = cmb
    fkmaps = fftfast.fft(measured, axes=[-2, -1])
예제 #30
0
    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)
# Initialize a container for stats and stacks
mpibox = MPIStats(comm,num_each,tag_start=333)
if rank==0: print(("At most ", max(num_each) , " tasks..."))
# What am I doing?
my_tasks = each_tasks[rank]
예제 #31
0
파일: simtod.py 프로젝트: guanyilun/tenki
def get_model(s, area):
	pos = area.posmap().reshape(2,-1)[::-1].T
	model = np.rollaxis(s.get_model(pos),-1).reshape(-1,area.shape[1],area.shape[2])
	return enmap.ndmap(model, area.wcs)[:area.shape[0]]