Beispiel #1
0
def get_patch(coords, sim_idx, map_type, cmb_type, pixel_fac = 2):
    shape,wcs = enmap.fullsky_geometry(res=1.0*np.pi/180./60.)

    def _process_coords(coords):
        coords = np.array(coords)
        if coords[1,1] > 180. : coords[1,1] -= 360.
        if coords[0,1] > 180. : coords[0,1] -= 360.

        coords *= np.pi/180.
        return coords

    zpsim_idx = '%05d' %sim_idx
    coords = _process_coords(coords)

    file_name = sim_file_temp.format(zpsim_idx, map_type, cmb_type, zpsim_idx)
    emap = enmap.read_fits(file_name, box=coords, wcs_override=wcs)

    nshape = tuple(np.array([i for i in emap.shape])*2)
    data   = simTools.resample_fft_withbeam(emap, nshape, doBeam=False, beamData=None)
    oshape, owcs = enmap.scale_geometry(emap.shape, emap.wcs, pixel_fac)

    assert(oshape == nshape)
    pmap   = enmap.enmap(data, owcs)

    return emap.to_flipper()
Beispiel #2
0
    def __init__(self,full_sky_pix,wdeg,hdeg,yoffset,mpi_comm=None,nsims=1,lmax=7000,pix_intermediate=None,bin_lmax=3000):
        self.dtype = np.float32
        self.bin_edges = np.arange(80,bin_lmax,100)
        self.fshape, self.fwcs = enmap.fullsky_geometry(res=full_sky_pix*np.pi/180./60., proj="car")
        self.fshape = self.fshape[-2:]
        self.shape = {}
        self.wcs = {}
        self.taper = {}
        self.w2 = {}
        self.w3 = {}
        self.w4 = {}

        self.pix_intermediate = full_sky_pix if (pix_intermediate is None) else pix_intermediate
        self.wdeg = wdeg
        self.hdeg = hdeg

	degree =  u.degree
        vwidth = hdeg/2.
        hwidth = wdeg/2.
	self.pos_south=np.array([[-vwidth+yoffset,-hwidth],[vwidth+yoffset,hwidth]])*degree
	self.pos_eq=np.array([[-vwidth,-hwidth],[vwidth,hwidth]])*degree


        # Get MPI comm
        self.comm = mpi_comm
        try:
            self.rank = mpi_comm.Get_rank()
            self.numcores = mpi_comm.Get_size()
        except:
            self.rank = 0
            self.numcores = 1

        if self.rank==0: 
            self.logger = io.get_logger("rotrecon")

        num_each,each_tasks = mpi_distribute(nsims,self.numcores)
        self.mpibox = MPIStats(self.comm,num_each,tag_start=333)
        if self.rank==0: self.logger.info( "At most "+ str(max(num_each)) + " tasks...")
        self.tasks = each_tasks[self.rank]

        theory_file_root = "data/Aug6_highAcc_CDM"
        powspec_file = "data/Aug6_highAcc_CDM_lenspotentialCls.dat"
        
        self.ps = powspec.read_camb_full_lens(powspec_file).astype(self.dtype)
        self.theory = cmb.loadTheorySpectraFromCAMB(theory_file_root,unlensedEqualsLensed=False,
                                                    useTotal=False,TCMB = 2.7255e6,lpad=9000,get_dimensionless=False)
        self.lmax = lmax
        self.count = 0
Beispiel #3
0
# MPI
comm = mpi.MPI.COMM_WORLD
rank = comm.Get_rank()
numcores = comm.Get_size()
Nsims = args.nsims
Njobs = Nsims
num_each,each_tasks = mpi.mpi_distribute(Njobs,numcores)
if rank==0: print ("At most ", max(num_each) , " tasks...")
my_tasks = each_tasks[rank]

# Theory
theory = cosmology.loadTheorySpectraFromCAMB(args.TheoryRoot,
                                             unlensedEqualsLensed=False,useTotal=False,TCMB = 2.7255e6,lpad=9000,get_dimensionless=False)

# Geometry
fshape,fwcs = enmap.fullsky_geometry(res=args.res*np.pi/180./60.)
box = np.array([[-args.wy/2.,-args.wx/2.],[args.wy/2.,args.wx/2.]])*np.pi/180.

# Stats
st = stats.Stats(comm)

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)
Beispiel #4
0
                                       TCMB=2.7255e6,
                                       lpad=9000,
                                       get_dimensionless=False)
ells = np.arange(0, 7000, 1)
#pfunc = lambda x: theory.lCl('TT',x)
#pfunc = lambda x: x*0.+1.
pfunc = lambda x: x * 0. + (10. * np.pi / 180. / 60.)**2.  #theory.gCl('kk',x)
ps = pfunc(ells).reshape((1, 1, 7000))

wdeg = 40.
hdeg = 15.
yoffset = 60.
pix = 0.5
lmax = 7000

fshape, fwcs = enmap.fullsky_geometry(res=pix * np.pi / 180. / 60., proj="car")

shape, wcs = enmap.rect_geometry(width_arcmin=wdeg * 60.,
                                 px_res_arcmin=pix,
                                 height_arcmin=hdeg * 60.,
                                 yoffset_degree=yoffset)

with bench.show("taper"):
    #mg = enmap.MapGen(shape,wcs,ps)
    taper, sw2 = fmaps.get_taper(shape,
                                 taper_percent=18.0,
                                 pad_percent=4.0,
                                 weight=None)

pxover = 0.5
maplmax = args.maplmax if args.maplmax is not None else lmax
io.dout_dir = args.path

Nsims = args.nsim

comm = MPI.COMM_WORLD
rank = comm.Get_rank()
numcores = comm.Get_size()
Ntot = Nsims
num_each, each_tasks = mpi_distribute(Ntot, numcores)
mpibox = Stats(comm, tag_start=333)
if rank == 0: print("At most ", max(num_each), " tasks...")
my_tasks = each_tasks[rank]

ps = powspec.read_camb_full_lens(args.theory + "_lenspotentialCls.dat")
shape, wcs = enmap.fullsky_geometry(res=args.res * np.pi / 180. / 60.,
                                    proj="car")
shape = (args.ncomp, ) + shape


def save(suffix, imap, index):
    enmap.write_fits(
        args.path + "_" + suffix + "_" +
        str(index).zfill(int(np.log10(args.nsim)) + 1) + ".fits", imap)


def load(suffix, index):
    return enmap.read_fits(args.path + "_" + suffix + "_" +
                           str(index).zfill(int(np.log10(args.nsim)) + 1) +
                           ".fits")

Beispiel #6
0
# We assume that site and pointing offsets are the same for all tods,
# so get them based on the first one
entry = filedb.data[ids[0]]
site  = actdata.read(entry, ["site"]).site

# Determine the bounding box of our selected data
bounds    = db.data["bounds"].reshape(2,-1).copy()
bounds[0] = utils.rewind(bounds[0], bounds[0,0], 360)
box = utils.widen_box(utils.bounding_box(bounds.T), 4*args.rad, relative=False)
waz, wel = box[1]-box[0]
# Use fullsky horizontally if we wrap too far
if waz <= 180:
	shape, wcs = enmap.geometry(pos=box[:,::-1]*utils.degree, res=args.res*utils.degree, proj="car", ref=(0,0))
else:
	shape, wcs = enmap.fullsky_geometry(res=args.res*utils.degree)
	y1, y2 = np.sort(enmap.sky2pix(shape, wcs, [box[:,1]*utils.degree,[0,0]])[0].astype(int))
	shape, wcs = enmap.slice_geometry(shape, wcs, (slice(y1,y2),slice(None)))

sys.stderr.write("using %s workspace with resolution %.2f deg" % (str(shape), args.res) + "\n")

# Get the hitmap for each block
hits = enmap.zeros((nblock,narray)+shape, wcs)
ndig = calc_ndig(nblock)
sys.stderr.write("estimating hitmap for block %*d/%d" % (ndig,0,nblock))
for bi in range(nblock):
	for ai in range(narray):
		block_db = db.select(block_inds[bi,ai])
		hits[bi,ai] = fastweight.fastweight(shape, wcs, block_db, array_rad=args.rad*utils.degree, site=site, weight=args.weight)
	sys.stderr.write("%s%*d/%d" % ("\b"*(1+2*ndig),ndig,bi+1,nblock))
sys.stderr.write("\n")
Beispiel #7
0
# We assume that site and pointing offsets are the same for all tods,
# so get them based on the first one
entry = filedb.data[ids[0]]
site  = actdata.read(entry, ["site"]).site

# Determine the bounding box of our selected data
bounds    = db.data["bounds"].reshape(2,-1).copy()
bounds[0] = utils.rewind(bounds[0], bounds[0,0], 360)
box = utils.widen_box(utils.bounding_box(bounds.T), 4*args.rad, relative=False)
waz, wel = box[1]-box[0]
# Use fullsky horizontally if we wrap too far
if waz <= 180:
	shape, wcs = enmap.geometry(pos=box[:,::-1]*utils.degree, res=args.res*utils.degree, proj="car", ref=(0,0))
else:
	shape, wcs = enmap.fullsky_geometry(res=args.res*utils.degree)
	y1, y2 = np.sort(enmap.sky2pix(shape, wcs, [box[:,1]*utils.degree,[0,0]])[0].astype(int))
	shape, wcs = enmap.slice_geometry(shape, wcs, (slice(y1,y2),slice(None)))

sys.stderr.write("using %s workspace with resolution %.2f deg" % (str(shape), args.res) + "\n")

# Get the hitmap for each block
hits = enmap.zeros((nblock,narray)+shape, wcs)
ndig = calc_ndig(nblock)
sys.stderr.write("estimating hitmap for block %*d/%d" % (ndig,0,nblock))
for bi in range(nblock):
	for ai in range(narray):
		block_db = db.select(block_inds[bi,ai])
		hits[bi,ai] = fastweight.fastweight(shape, wcs, block_db, array_rad=args.rad*utils.degree, site=site, weight=args.weight)
	sys.stderr.write("%s%*d/%d" % ("\b"*(1+2*ndig),ndig,bi+1,nblock))
sys.stderr.write("\n")
Beispiel #8
0
from enlib import lensing, powspec, utils, enmap, bench
import numpy as np, sys

powspec_file = "data/Aug6_highAcc_CDM_lenspotentialCls.dat"
ps = powspec.read_camb_full_lens(powspec_file).astype(np.float64)
geom = lambda x: enmap.fullsky_geometry(res=x * np.pi / 180. / 60., proj="car")

shape, wcs = geom(4.0)

#obs = enmap.posmap(shape,wcs)

#sys.exit()

with bench.show("2arc"):
    full, = lensing.rand_map(shape,
                             wcs,
                             ps,
                             lmax=4000,
                             maplmax=4000,
                             verbose=False,
                             delta_theta=2. * np.pi / 180.,
                             seed=1)

with bench.show("2arc"):
    full2, = lensing.rand_map(shape,
                              wcs,
                              ps,
                              lmax=4000,
                              maplmax=4000,
                              verbose=True,
                              seed=1)