Example #1
0
ng = maps.MapGen(shape,wcs,ps_noise)
kamp_true = args.Amp
kappa = lensing.nfw_kappa(kamp_true*1e15,modrmap,cc,overdensity=200.,critical=True,atClusterZ=True)
phi,_ = lensing.kappa_to_phi(kappa,modlmap,return_fphi=True)
grad_phi = enmap.grad(phi)
posmap = enmap.posmap(shape,wcs)
pos = posmap + grad_phi
alpha_pix = enmap.sky2pix(shape,wcs,pos, safe=False)
lens_order = 5


if rank==0: print("Starting sims...")
# Stats
Nsims = args.Nclusters
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]
mstats = stats.Stats(comm)
np.random.seed(rank)


# QE
tellmin = modlmap[modlmap>2].min(); tellmax = 8000; kellmin = tellmin ; kellmax = 8096
tmask = maps.mask_kspace(shape,wcs,lmin=tellmin,lmax=tellmax)
kmask = maps.mask_kspace(shape,wcs,lmin=kellmin,lmax=kellmax)
qest = lensing.qest(shape,wcs,theory,noise2d=kbeam*0.+(noise_uK_rad)**2.,beam2d=kbeam,kmask=tmask,kmask_K=kmask,pol=False,grad_cut=2000,unlensed_equals_lensed=False)

for i,task in enumerate(my_tasks):
    if (i+1)%10==0 and rank==0: print(i+1)
#parser.add_argument("-f", "--flag", action='store_true',help='A flag.')
args = parser.parse_args()

dtype = {32: np.float32, 64: np.float64}[args.bits]
seed = args.seed if args.seed is not None else np.random.randint(0, 100000000)
lmax = args.lmax or None
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)
Example #3
0
            for array1 in ['pa1_f150', 'pa2_f150', 'pa3_f090', 'pa3_f150']:
                try:
                    if (actseason0==actseason1) and (array0==array1): raise
                    if array0=='pa3_f150' and array1=='pa3_f090': raise
                    if array1=='pa3_f150' and array0=='pa3_f090': raise
                    actbeam0 = lambda x: dma.get_beam(x, actseason0, patch, array0)
                    actbeam1 = lambda x: dma.get_beam(x, actseason1, patch, array1)
                    actbeam0(100)
                    actbeam1(100)
                    print(actseason0,array0,actseason1,array1)
                    combs.append((actseason0,array0,actseason1,array1))
                except:
                    pass

Njobs = len(combs)
num_each,each_tasks = mpi.mpi_distribute(Njobs,numcores,allow_empty=True)
if rank==0: print ("At most ", max(num_each) , " tasks...")
my_tasks = each_tasks[rank]

for task in my_tasks:
    actseason0,array0,actseason1,array1 = combs[task]
    actbeam0 = lambda x: dma.get_beam(x, actseason0, patch, array0)
    actbeam1 = lambda x: dma.get_beam(x, actseason1, patch, array1)

    actmap0 = dma.get_coadd(actseason0, patch, array0, 
                            ncomp=1, srcfree=True)[0,:,:] # just want T
    actmap1 = dma.get_coadd(actseason1, patch, array1, 
                            ncomp=1, srcfree=True)[0,:,:] # just want T
    lb, Cb = compute_ps(actmap0, actmap1, actbeam0, actbeam1)

    io.save_cols("/scratch/r/rbond/msyriac/data/depot/actsims/spectra/spec%s_%s_%s_%s_%s_%s.txt" % (fftstr,patch, actseason0, array0, actseason1, array1),(lb,Cb))
Example #4
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)  # define power bin edges

        # Create a full sky geometry
        self.fshape, self.fwcs = enmap.fullsky_geometry(res=full_sky_pix *
                                                        np.pi / 180. / 60.,
                                                        proj="car")
        self.fshape = self.fshape[-2:]

        # Holders for geometries and window corrections for each of e,s,r
        self.shape = {}
        self.wcs = {}
        self.taper = {}
        self.w2 = {}
        self.w3 = {}
        self.w4 = {}

        # Intermediate pixelization for rotation
        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.

        # Box locations to slice from
        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")

        # Distribute MPI tasks
        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]

        # Initialize theory power spectra
        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 = cosmology.loadTheorySpectraFromCAMB(
            theory_file_root,
            unlensedEqualsLensed=False,
            useTotal=False,
            TCMB=2.7255e6,
            lpad=9000,
            get_dimensionless=False)
        self.lmax = lmax
        self.count = 0