def read_helper(fname, shape=None, wcs=None): if shape is None: return enmap.read_map(fname) mshape, mwcs = enmap.read_map_geometry(fname) pixbox = enmap.pixbox_of(mwcs, shape, wcs) return enmap.read_map(fname, pixbox=pixbox)
map_keys = ["map","snmap","model","resid","resid_snmap"] utils.mkdir(args.odir) # Mpi-parallelization over regions is simple, but a bit lazy. It means that there will be # no speedup for single-region maps for ri in range(comm.rank, len(regions), comm.size): reg_fid = regions[ri] reg_pad = dory.pad_region(reg_fid, args.pad) print "%3d region %3d/%d %5d %5d %6d %6d" % (comm.rank, ri+1, len(regions), reg_fid[0,0], reg_fid[1,0], reg_fid[0,1], reg_fid[1,1]) try: # We only use T to find sources in find mode for now. P usually has much lower S/N and # doesn't help much. Should add it later, though. imap = enmap.read_map(args.imap, pixbox=reg_pad).preflat[0] idiv = enmap.read_map(args.idiv, pixbox=reg_pad).preflat[0] if args.mask: mshape, mwcs = enmap.read_map_geometry(args.mask) mbox = enmap.pixbox_of(mwcs, imap.shape, imap.wcs) idiv *= (1-enmap.read_map(args.mask, pixbox=mbox).preflat[0]) if "debug" in args.output: dump_prefix = args.odir + "/region_%02d_" % ri else: dump_prefix = None result = dory.find_srcs(imap, idiv, beam, freq=args.freq, apod=args.apod, apod_margin=args.apod_margin, snmin=args.nsigma, verbose=args.verbose, dump=dump_prefix) # FIXME: artifacts are act-specific result = dory.prune_artifacts(result) except Exception as e: print "Exception for task %d region %d: %s" % (comm.rank, ri, e.message) raise # Write region output if "reg" in args.output: prefix = args.odir + "/region_%02d_" % ri dory.write_catalog_fits(prefix + "cat.fits" , result.cat) dory.write_catalog_txt(prefix + "cat.txt" , result.cat)
utils.mkdir(args.odir) write_args(args.odir + "/args.txt") # Mpi-parallelization over regions is simple, but a bit lazy. It means that there will be # no speedup for single-region maps for ri in range(comm.rank, len(regions), comm.size): reg_fid = regions[ri] reg_pad = dory.pad_region(reg_fid, args.pad) print("%3d region %3d/%d %5d %5d %6d %6d" % (comm.rank, ri+1, len(regions), reg_fid[0,0], reg_fid[1,0], reg_fid[0,1], reg_fid[1,1])) try: # We only use T to find sources in find mode for now. P usually has much lower S/N and # doesn't help much. Should add it later, though. imap = enmap.read_map(args.imap, pixbox=reg_pad).preflat[0] idiv = enmap.read_map(args.idiv, pixbox=reg_pad).preflat[0] if args.mask: mshape, mwcs = enmap.read_map_geometry(args.mask) mbox = enmap.pixbox_of(mwcs, imap.shape, imap.wcs) mask = enmap.read_map(args.mask, pixbox=mbox).preflat[0] > 0 idiv *= 1-mask # Inpaint masked area, in case it contains fourier-unfriendly values imap = enmap.inpaint(imap, mask) del mask if "debug" in args.output: dump_prefix = args.odir + "/region_%02d_" % ri else: dump_prefix = None nsigma = args.nsigma if args.nsigma is not None else 3.5 result = dory.find_srcs(imap, idiv, beam, freq=args.freq, apod=args.apod, apod_margin=args.apod_margin, snmin=nsigma, verbose=args.verbose, dump=dump_prefix) # FIXME: artifacts are act-specific if args.prune: result = dory.prune_artifacts(result) except Exception as e: print("Exception for task %d region %d: %s" % (comm.rank, ri, str(e)))
dtype=dtype, bbox=mybbox, comm=comm) area = dmap.zeros(geo) # Set up our signal. We do this instead of building the pmat manually # to make it easy to support both maps and dmaps if not use_dmap: signal = mapmaking.SignalMap(myscans, area, comm) else: signal = mapmaking.SignalDmap(myscans, mysubs, area, comm) # Get the input sky map that we will subtract. We do this because the CMB+CIB # are the same from tod to tod, but we can't support intra-tod correlated noise, # so we have to get rid of it. This is not optimal, but it shouldn't be far off. if args.mapsub: sshape, swcs = enmap.read_map_geometry(args.mapsub) pixbox = enmap.pixbox_of(swcs, shape, wcs) if not use_dmap: refmap = enmap.read_map(args.mapsub, pixbox=pixbox).astype(dtype) else: refmap = dmap.read_map(args.mapsub, pixbox=pixbox, bbox=mybbox, comm=comm).astype(dtype) refmap = signal.prepare(refmap) # Get the frequency and beam for this chunk. We assume that # this is the same for every member of the chunk, so we only need # to do this for one scan scan = actscan.ACTScan(filedb.data[chunk_ids[inds[0]]]) _, dets = actdata.split_detname(scan.dets)