示例#1
0
def calc_model_constrained(tod,
                           cut,
                           srate=400,
                           mask_scale=0.3,
                           lim=3e-4,
                           maxiter=50,
                           verbose=False):
    # First do some simple gapfilling to avoid messing up the noise model
    tod = sampcut.gapfill_linear(cut, tod, inplace=False)
    ft = fft.rfft(tod) * tod.shape[1]**-0.5
    iN = nmat_measure.detvecs_jon(ft, srate)
    del ft
    iV = iN.ivar * mask_scale

    def A(x):
        x = x.reshape(tod.shape)
        Ax = iN.apply(x.copy())
        Ax += sampcut.gapfill_const(cut, x * iV[:, None], 0, inplace=True)
        return Ax.reshape(-1)

    b = sampcut.gapfill_const(cut, tod * iV[:, None], 0,
                              inplace=True).reshape(-1)
    x0 = sampcut.gapfill_linear(cut, tod).reshape(-1)
    solver = cg.CG(A, b, x0)
    while solver.i < maxiter and solver.err > lim:
        solver.step()
        if verbose:
            print("%5d %15.7e" % (solver.i, solver.err))
    res = solver.x.reshape(tod.shape)
    res = smooth(res, srate)
    return res
示例#2
0
def map_cuts(entry,
             data,
             hitmap,
             cutmap,
             keep_buffer=False,
             nocommon_frac=None):
    '''
    Project hits and hits-cuts onto the sky.

    parameters
    ----------
    entry : filedb.data object
    data : actdata instance
    hitmap : (1, ny, nx) enmap
    cutmap : (1, ny, nx) enmap
    keep_buffer : bool, optional
        Do not remove the 200 sample buffers before and after cuts.
    common_frac : float, optional
        Do not consider cuts that are at least common to this
        fraction of detectors.
    '''

    scan = actscan.ACTScan(entry, d=data)
    pmap = pmat.PmatMap(scan, hitmap)
    cut = data.cut

    if nocommon_frac is not None:
        cut = remove_common(cut, frac=nocommon_frac)

    if keep_buffer is False:
        cut = remove_buffer(cut)

    tod = np.full([data.ndet, data.nsamp], 1.0, dtype)
    pmap.backward(tod, hitmap)
    sampcut.gapfill_const(cut, tod, 0.0, inplace=True)
    pmap.backward(tod, cutmap)
示例#3
0
def calc_model_constrained(tod, cut, srate=400, mask_scale=0.3, lim=3e-4, maxiter=50, verbose=False):
	# First do some simple gapfilling to avoid messing up the noise model
	tod = sampcut.gapfill_linear(cut, tod, inplace=False)
	ft = fft.rfft(tod) * tod.shape[1]**-0.5
	iN = nmat_measure.detvecs_jon(ft, srate)
	del ft
	iV = iN.ivar*mask_scale
	def A(x):
		x   = x.reshape(tod.shape)
		Ax  = iN.apply(x.copy())
		Ax += sampcut.gapfill_const(cut, x*iV[:,None], 0, inplace=True)
		return Ax.reshape(-1)
	b  = sampcut.gapfill_const(cut, tod*iV[:,None], 0, inplace=True).reshape(-1)
	x0 = sampcut.gapfill_linear(cut, tod).reshape(-1)
	solver = cg.CG(A, b, x0)
	while solver.i < maxiter and solver.err > lim:
		solver.step()
		if verbose:
			print "%5d %15.7e" % (solver.i, solver.err)
	return solver.x.reshape(tod.shape)
示例#4
0
]

# Process all our tods
L.info("Processing %d tods" % data.n)
for fi, scan in enumerate(data.scans):
    L.debug("Processing %4d/%d %s" %
            (data.rinds[fi] + 1, data.n, ids[data.inds[fi]]))
    tod = scan.get_samples().astype(dtype)
    # Apply our filters
    for f in filters:
        f(scan, tod)
    # Measure our noise properties and apply inverse variance weight
    ivar = 1 / np.var(tod, 1)
    tod *= ivar[:, None]
    # Apply our cuts and accumulate
    sampcut.gapfill_const(scan.cut, tod, 0, inplace=True)
    signal.backward(scan, tod, rhs_work)

    # Build our denominator too
    for ci in range(ncomp):
        div_tmp *= 0
        div_tmp[ci] = 1
        signal.forward(scan, tod, div_tmp, tmul=0)
        tod *= ivar[:, None]
        sampcut.gapfill_const(scan.cut, tod, 0, inplace=True)
        signal.backward(scan, tod, div_work[ci])

    # and hits
    tod[:] = 1
    sampcut.gapfill_const(scan.cut, tod, 0, inplace=True)
    signal.backward(scan, tod, hit_work)
示例#5
0
 def A(x):
     x = x.reshape(tod.shape)
     Ax = iN.apply(x.copy())
     Ax += sampcut.gapfill_const(cut, x * iV[:, None], 0, inplace=True)
     return Ax.reshape(-1)
示例#6
0
	def A(x):
		x   = x.reshape(tod.shape)
		Ax  = iN.apply(x.copy())
		Ax += sampcut.gapfill_const(cut, x*iV[:,None], 0, inplace=True)
		return Ax.reshape(-1)
示例#7
0
		src_cut *= scan.cut
		del src_mask
	with bench.show("atm model"):
		if   args.model == "joneig":
			model = calc_model_joneig(tod, src_cut, d.srate)
		elif args.model == "constrained":
			model = calc_model_constrained(tod, src_cut, d.srate, verbose=True)
	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 for each point source. We need a separate
	# pointing matrix for each because each has its own local coordinate system.
	tod *= ivar[:,None]
	sampcut.gapfill_const(scan.cut, tod, inplace=True)
	for sid in tod_srcs[id]:
		src  = srcs[sid]
		if   src.type == "fixed":  sys = "hor:%.6f_%.6f:cel/0_0:hor" % (src.ra/utils.degree, src.dec/utils.degree)
		elif src.type == "planet": sys = "hor:%s/0_0" % src.name
		else: raise ValueError("Invalid source type '%s'" % src.type)
		rhs  = enmap.zeros((ncomp,)+shape, area.wcs, dtype)
		div  = enmap.zeros((ncomp,ncomp)+shape, area.wcs, dtype)
		with bench.show("pmat %s" % sid):
			pmap = pmat.PmatMap(scan, area, sys=sys)
		with bench.show("rhs %s" % sid):
			pmap.backward(tod, rhs)
		with bench.show("hits"):
			for i in range(ncomp):
				div[i,i] = 1
				pmap.forward(tod, div[i])
示例#8
0
 def apply_cut(tod, inplace=True):
     return sampcut.gapfill_const(scan.cut, tod, inplace=inplace)
示例#9
0
def gapfill_constant(tod, cut, inplace=False, value=0.0, overlap=None):
    return sampcut.gapfill_const(cut, tod, value, inplace=inplace)