def build_phase(az, smooth=3): """"Phase" is an angle that increases with az while az increases, but continues to increase as az falls.""" mi, ma = utils.minmax(az) phase = (az - mi) / (ma - mi) falling = phase[1:] - phase[:-1] < 0 falling = np.concatenate([falling[:1], falling]) phase[falling] = 2 - phase[falling] if smooth: phase = signal.medfilt(phase, 2 * smooth + 1) return phase
area = enmap.read_map(args.area) area = enmap.zeros((ncomp, ) + area.shape[-2:], area.wcs, dtype) # First loop through all the tods and find out which are in which scanning # pattern. L.info("Scanning tods") mypatids = {} ids = filedb.scans[args.sel] myinds = range(comm.rank, len(ids), comm.size) ndet_array = 0 for ind, d in scanutils.scan_iterator(ids, myinds, actscan.ACTScan, filedb.data): id = ids[ind] # Determine which scanning pattern we have el = np.mean(d.boresight[:, 2]) az1, az2 = utils.minmax(d.boresight[:, 1]) pat = np.array([el, az1, az2]) / utils.degree pat = tuple(np.round(pat / args.bsize) * args.bsize) ndet_array = d.layout.ndet # And record it if pat not in mypatids: mypatids[pat] = [] mypatids[pat].append(id) ndet_array = comm.allreduce(ndet_array, mpi.MAX) # Get list of all patterns L.info("Gathering pattern lists") mypats = mypatids.keys() if len(mypats) == 0: mypats = np.zeros([0, 3]) pats = utils.allgatherv(mypats, comm) pats = list(set(sorted([tuple(pat) for pat in pats])))
abscal /= d.mce_gain elif d.gain_mode == 'mce_compat': abscal /= d.mce_gain * 1217.8583043 else: raise ValueError('gain_mode {} not understood'.format(d.gain_mode)) with bench.show("calibrate"): d = actdata.calibrate(d, exclude=["autocut"]) rel_gain = d.gain_raw.copy() # To store later on. if d.ndet == 0 or d.nsamp < 2: raise errors.DataMissing("no data in tod") # Select detectors if needed. if dbox is not None: mid = np.mean(utils.minmax(d.point_template, 0), 0) off = d.point_template - mid good = np.all((off > dbox[0]) & (off < dbox[1]), -1) d = d.restrict(dets=d.dets[good]) except errors.DataMissing as e: print("Skipping %s (%s)" % (id, e.message)) continue print("Processing %s" % id, d.ndet, d.nsamp) # Very simple white noise model. with bench.show("ivar"): tod = d.tod del d.tod tod -= np.mean(tod, 1)[:, None] tod = tod.astype(dtype)
t0 = args.t # In mjd ibox = np.array([ [0, wt], [args.az - args.waz / 2., args.az + args.waz / 2.], [args.el - args.wel / 2., args.el + args.wel / 2.], ]).T + det_box / utils.degree # units ibox[:, 1:] *= utils.degree wibox = ibox.copy() wibox[:, :] = utils.widen_box(ibox[:, :]) srate = nsamp / wt # output box icorners = utils.box2corners(ibox) ocorners = hor2cel(icorners.T, t0) obox = utils.minmax(ocorners, -1)[:, :2] wobox = utils.widen_box(obox) # define a pixelization shape, wcs = enmap.geometry(pos=wobox[:, ::-1], res=args.res * utils.arcmin, proj="cea") nphi = int(2 * np.pi / (args.res * utils.arcmin)) map_orig = enmap.rand_gauss((ncomp, ) + shape, wcs).astype(dtype) print "map shape %s" % str(map_orig.shape) pbox = np.array([[0, 0], shape], dtype=int) # define a test tod bore = np.zeros([nsamp, 3], dtype=ptype) bore[:, 0] = (wt * np.linspace(0, 1, nsamp, endpoint=False)) bore[:, 1] = (args.az + args.waz / 2 * utils.triangle_wave(
if not args.transpose: imapfiles = args.ifiles[:nfile] ilayfiles = args.ifiles[nfile:] else: imapfiles = args.ifiles[0::2] ilayfiles = args.ifiles[1::2] # Read in our focalplane layouts so we can define our output map bounds dets, offs, boxes, imaps = [], [], [], [] for i in range(nfile): det, off = files.read_point_template(ilayfiles[i]) imap = enmap.read_map(imapfiles[i]) if args.slice: imap = eval("imap" + args.slice) # We want y,x-ordering off = off[:, ::-1] box = utils.minmax(off, 0) dets.append(det) offs.append(off) boxes.append(box) imaps.append(imap) box = utils.bounding_box(boxes) box = utils.widen_box(box, rad * 5, relative=False) # We assume that the two maps have the same pixelization imaps = enmap.samewcs(np.array(imaps), imaps[0]) # Downsample by averaging imaps = enmap.downgrade(imaps, (1, args.step)) naz = imaps.shape[-1] # Ok, build our output geometry shape, wcs = enmap.geometry(pos=box,
if not args.transpose: imapfiles = args.ifiles[:nfile] ilayfiles = args.ifiles[nfile:] else: imapfiles = args.ifiles[0::2] ilayfiles = args.ifiles[1::2] # Read in our focalplane layouts so we can define our output map bounds dets, offs, boxes, imaps = [], [], [], [] for i in range(nfile): det, off = files.read_point_template(ilayfiles[i]) imap = enmap.read_map(imapfiles[i]) if args.slice: imap = eval("imap"+args.slice) # We want y,x-ordering off = off[:,::-1] box = utils.minmax(off,0) dets.append(det) offs.append(off) boxes.append(box) imaps.append(imap) box = utils.bounding_box(boxes) box = utils.widen_box(box, rad*5, relative=False) # We assume that the two maps have the same pixelization imaps = enmap.samewcs(np.array(imaps), imaps[0]) # Downsample by averaging imaps = enmap.downgrade(imaps, (1,args.step)) naz = imaps.shape[-1] # Ok, build our output geometry shape, wcs = enmap.geometry(pos=box, res=args.res*utils.arcmin, proj="car", pre=(naz,))
try: if not args.sim: with bench.show("read"): d = actdata.read(entry) else: sim_id = sim_ids[ind] sim_entry = filedb.data[sim_id] with bench.show("read"): d = actdata.read(entry, ["boresight"]) d += actdata.read(sim_entry, exclude=["boresight"]) with bench.show("calibrate"): d = actdata.calibrate(d, exclude=["autocut"]) if d.ndet == 0 or d.nsamp < 2: raise errors.DataMissing("no data in tod") # Select detectors if needed if dbox is not None: mid = np.mean(utils.minmax(d.point_template, 0), 0) off = d.point_template-mid good = np.all((off > dbox[0])&(off < dbox[1]),-1) d = d.restrict(dets=d.dets[good]) except errors.DataMissing as e: print "Skipping %s (%s)" % (id, e.message) continue print "Processing %s" % id, d.ndet, d.nsamp #broaden_beam_hor(d.tod, d, 1.35*utils.arcmin*utils.fwhm, 1.57*utils.arcmin*utils.fwhm) # Very simple white noise model. This breaks if the beam has been tod-smoothed by this point. with bench.show("ivar"): tod = d.tod del d.tod tod -= np.mean(tod,1)[:,None] tod = tod.astype(dtype) diff = tod[:,1:]-tod[:,:-1]
t0 = args.t # In mjd ibox = np.array([ [0, wt], [args.az-args.waz/2., args.az+args.waz/2.], [args.el-args.wel/2., args.el+args.wel/2.], ]).T + det_box/utils.degree # units ibox[:,1:] *= utils.degree wibox = ibox.copy() wibox[:,:] = utils.widen_box(ibox[:,:]) srate = nsamp/wt # output box icorners = utils.box2corners(ibox) ocorners = hor2cel(icorners.T, t0) obox = utils.minmax(ocorners, -1)[:,:2] wobox = utils.widen_box(obox) # define a pixelization shape, wcs = enmap.geometry(pos=wobox[:,::-1], res=args.res*utils.arcmin, proj="cea") nphi = int(2*np.pi/(args.res*utils.arcmin)) map_orig = enmap.rand_gauss((ncomp,)+shape, wcs).astype(dtype) print "map shape %s" % str(map_orig.shape) pbox = np.array([[0,0],shape],dtype=int) # define a test tod bore = np.zeros([nsamp,3],dtype=ptype) bore[:,0] = (wt*np.linspace(0,1,nsamp,endpoint=False)) bore[:,1] = (args.az + args.waz/2*utils.triangle_wave(np.linspace(0,1,nsamp,endpoint=False)*20))*utils.degree bore[:,2] = (args.el + args.wel/2*utils.triangle_wave(np.linspace(0,1,nsamp,endpoint=False)))*utils.degree #bore = (ibox[None,0] + np.random.uniform(0,1,size=(nsamp,3))*(ibox[1]-ibox[0])[None,:]).astype(ptype)