Example #1
0
def project_tod_on_workspace(scan, tod, wgeo):
    """Compute the tod onto a map using the pixelization defined
	in the workspace, and return it along with a [TQU,TQU] hitmap
	and a hits-by-detector-by-y array."""
    rhs = enmap.zeros(wgeo.shape, wgeo.lwcs, wgeo.dtype)
    hdiv = enmap.zeros((rhs.shape[:1] + rhs.shape), rhs.wcs, rhs.dtype)
    # Project it onto the workspace
    pcut = pmat.PmatCut(scan)
    pmap = PmatWorkspaceTOD(scan, wgeo)
    pix, phase = pmap.get_pix_phase()
    # Build rhs
    junk = np.zeros(pcut.njunk, dtype=rhs.dtype)
    pcut.backward(tod, junk)
    pmap.backward(tod, rhs, pix, phase)
    # Build div
    tmp = hdiv[0].copy()
    for i in range(ncomp):
        tmp[:] = np.eye(ncomp)[i, :, None, None]
        pmap.forward(tod, tmp, pix, phase)
        pcut.backward(tod, junk)
        pmap.backward(tod, hdiv[i], pix, phase)
    # Find each detector's hits by wy. Some detectors have
    # sufficient residual curvature that they hit every wy.
    yhits = np.zeros([scan.ndet, rhs.shape[-2]], dtype=np.int32)
    core = pmat.get_core(dtype)
    core.bincount_flat(yhits.T, pix.T, rhs.shape[-2:], 0)
    return rhs, hdiv, yhits
Example #2
0
 def __init__(self, data, srcpos, ndir=1, sys=sys):
     # Build source parameter struct for PmatPtsrc
     self.params = np.zeros([srcpos.shape[-1], ndir, 8], np.float)
     self.params[:, :, :2] = srcpos[::-1, None, :].T
     self.params[:, :, 5:7] = 1
     scan = actscan.ACTScan(data.entry, d=data)
     self.psrc = pmat.PmatPtsrc(scan, self.params, sys=sys)
     self.pcut = pmat.PmatCut(scan)
     # Extract basic offset
     self.off0 = data.point_correction
     self.off = self.off0 * 1
     self.el = np.mean(data.boresight[2, ::100])
     self.point_template = data.point_template
Example #3
0
 def __init__(self, scan, srcpos, ndir=1, perdet=False, sys="cel"):
     # Build source parameter struct for PmatPtsrc
     self.params = np.zeros([srcpos.shape[-1],ndir,scan.ndet if perdet else 1,8],np.float)
     self.params[:,:,:,:2] = srcpos[::-1,None,None,:].T
     self.params[:,:,:,5:7] = 1
     self.psrc = pmat.PmatPtsrc(scan, self.params, sys=sys)
     self.pcut = pmat.PmatCut(scan)
     # Extract basic offset. Warning: referring to scan.d is fragile, since
     # scan.d is not updated when scan is sliced
     self.off0 = scan.d.point_correction
     self.off  = self.off0*0
     self.el   = np.mean(scan.boresight[::100,2])
     self.point_template = scan.d.point_template
     self.cut = scan.cut
Example #4
0
 def __init__(self,
              scans,
              dtype,
              comm,
              name="cut",
              ofmt="{name}_{rank:02}",
              output=False,
              cut_type=None):
     Signal.__init__(self, name, ofmt, output, ext="hdf")
     self.data = {}
     self.dtype = dtype
     cutrange = [0, 0]
     for scan in scans:
         mat = pmat.PmatCut(scan, cut_type)
         cutrange = [cutrange[1], cutrange[1] + mat.njunk]
         self.data[scan] = [mat, cutrange]
     self.njunk = cutrange[1]
     self.dof = zipper.ArrayZipper(np.zeros(self.njunk, self.dtype),
                                   shared=False,
                                   comm=comm)
Example #5
0
 def __init__(self, scan, srcs, ndir=1, perdet=False, sys="cel"):
     # Build source parameter struct for PmatPtsrc
     # srcs: {dec, ra, T, Q, U, omg_c, phi_c, D} => [nsrc, 7]
     # nparams: dec, ra, T, Q, U, omg_c, phi_c, D, ibx, iby, ibxy
     self.params = np.zeros([srcs.shape[-1],ndir,scan.ndet if perdet else 1,11],np.float)
     # dec, ra, T, Q, U, omg, phi
     self.params[:,:,:,0]   = srcs[1,  None,None,:].T  # dec
     self.params[:,:,:,1]   = srcs[0,  None,None,:].T  # ra
     self.params[:,:,:,2:8] = srcs[2:8,None,None,:].T  # TQUOPD
     # T, Q, U: assume unpolarized: amp -> T
     # default to cmb unit, better to use flux unit later
     # self.params[:,:,:,2] = src[::-1,None,None,2]   # actually not needed in init
     # ibx, iby = 1: circular beam
     self.params[:,:,:,-3:-1] = 1
     self.psrc = PmatPtsrcVar(scan, self.params, sys=sys)
     self.pcut = pmat.PmatCut(scan)
     # Extract basic offset. Warning: referring to scan.d is fragile, since
     # scan.d is not updated when scan is sliced
     self.off0 = scan.d.point_correction
     self.off  = self.off0*0
     self.el   = np.mean(scan.boresight[::100,2])
     self.point_template = scan.d.point_template
     self.cut = scan.cut
Example #6
0
		freq = fft.rfftfreq(model.shape[-1])*d.srate
		flt  = 1/(1+(freq/model_fknee)**model_alpha)
		ft  *= flt
		fft.ifft(ft, model, normalize=True)
		del ft, flt, freq
	with bench.show("atm subtract"):
		tod -= model
		del model
		tod  = tod.astype(dtype, copy=False)
	# Should now be reasonably clean of correlated noise.
	# Proceed to make simple binned map
	with bench.show("actscan"):
		scan = actscan.ACTScan(entry, d=d)
	with bench.show("pmat"):
		pmap = pmat.PmatMap(scan, area, sys=sys)
		pcut = pmat.PmatCut(scan)
		rhs  = enmap.zeros((ncomp,)+shape, area.wcs, dtype)
		div  = enmap.zeros((ncomp,ncomp)+shape, area.wcs, dtype)
		junk = np.zeros(pcut.njunk, dtype)
	with bench.show("rhs"):
		tod *= ivar[:,None]
		pcut.backward(tod, junk)
		pmap.backward(tod, rhs)
	with bench.show("hits"):
		for i in range(ncomp):
			div[i,i] = 1
			pmap.forward(tod, div[i])
			tod *= ivar[:,None]
			pcut.backward(tod, junk)
			div[i] = 0
			pmap.backward(tod, div[i])
Example #7
0
 speed = 0
 site = {}
 inspec = np.zeros(nbin)
 offsets = np.zeros([ndet_array, 2])
 det_hit = np.zeros([ndet_array], dtype=int)
 for ind, d in scanutils.scan_iterator(pids,
                                       myinds,
                                       actscan.ACTScan,
                                       filedb.data,
                                       dets=args.dets,
                                       downsample=config.get("downsample")):
     id = pids[ind]
     with bench.mark("pbuild"):
         # Build pointing matrices
         pmap = pmat.PmatMap(d, area)
         pcut = pmat.PmatCut(d)
     with bench.mark("tod"):
         # Get tod
         tod = d.get_samples()
         tod -= np.mean(tod, 1)[:, None]
         tod = tod.astype(dtype)
         junk = np.zeros(pcut.njunk, dtype=dtype)
     with bench.mark("nmat"):
         # Build noise model
         ft = fft.rfft(tod) * tod.shape[1]**-0.5
         nmat = nmat_measure.detvecs_simple(ft, d.srate)
         del ft
     with bench.mark("rhs"):
         # Calc rhs, accumulating into pattern total
         nmat.apply(tod)
         pcut.backward(tod, junk)
Example #8
0
	def __init__(self, scan, area, sys=None):
		self.pmap  = pmat.PmatMap(scan, area, sys=sys)
		self.pcut  = pmat.PmatCut(scan)
		self.err   = self.pmap.err