def pb_thomson_lo(data, in_map, u, mask=None): """Defines thomson scattering linear operator""" # data coefs data_coefs = _pb_data_coef(data).flatten() O = lo.diag(data_coefs) # map coefs map_coefs = _pb_map_coef(in_map, u).flatten() M = lo.diag(map_coefs) # projection P = siddon_lo(data.header, in_map.header, obstacle="sun", mask=mask) # thomson lo T = O * P * M return T
def smoothness_prior(my_map, height_prior=False): """ Defines a smoothness prior. """ D = [lo.diff(my_map.shape, axis=i) for i in xrange(my_map.ndim)] if height_prior: r = _radius_map(my_map) R = lo.diag(r.ravel()) D = [Di * R for Di in D] return D
def irls(A0, x0, tol1=1e-5, maxiter1=10, p=1, optimizer=spl.cgs, **kargs): """ Iteratively Reweighted Least Square """ A0 = lo.aslinearoperator(A0) out = A0.T * x0 tol1 /= np.sum(np.abs(x0 - A0 * out) ** p) for i in xrange(maxiter1): print("\n outer loop " + str(i + 1) + "\n") w = np.abs(x0 - A0 * out) ** (p - 2) A = A0.T * lo.diag(w) * A0 x = A0.T * (w * x0) out, t = optimizer(A, x, **kargs) if np.sum(np.abs(x0 - A0 * out) ** p) < tol1: break return out
def rirls(M, y, Ds=[], tol1=1e-5, maxiter1=10, p=1, optimizer=spl.cgs, **kargs): """ Regularized Iteratively Reweighted Least Square """ M = lo.aslinearoperator(M) Ds = [lo.aslinearoperator(D) for D in Ds] x0 = M.T * y x = copy(x0) r = M * x - y tol1 /= np.sum(np.abs(r) ** p) for i in xrange(maxiter1): print("\n outer loop " + str(i + 1) + "\n") A = M.T * M for D in Ds: rd = D * x w = np.abs(rd) ** (p - 2) w[np.where(1 - np.isfinite(w))] = 0 # inf A += D.T * lo.diag(w) * D x, t = optimizer(A, x0, **kargs) if np.sum(np.abs(y - M * x) ** p) < tol1: break r = M * x - y return x
model = masking * projection # remove drift tod = tm.filter_median(tod, length=999) model = masking * projection # naive map backmap = model.transpose(tod) # coverage map weights = model.transpose(tod.ones(tod.shape)) # mask on map mask = weights == 0 M = lo.mask(mask) # preconditionner iweights = 1 / weights iweights[np.where(np.isfinite(iweights) == 0)] = 0. M0 = lo.diag(iweights.flatten()) # transform to lo P = lo.aslinearoperator(model.aslinearoperator()) # priors Dx = lo.diff(backmap.shape, axis=0) Dy = lo.diff(backmap.shape, axis=1) # inversion y = (masking.T * tod).flatten() # algos algos = [spl.cg, spl.cgs, spl.bicg, spl.bicgstab] models = [P.T * P, P.T * P + Dx.T * Dx + Dy.T * Dy,] n_iterations = [] resid = [] for algo in algos: for A in models: for is_masked in (False, True):
model = masking * projection # remove drift tod = tm.filter_median(tod, length=999) model = masking * projection # naive map backmap = model.transpose(tod) # coverage map weights = model.transpose(tod.ones(tod.shape)) # mask on map mask = weights == 0 M = lo.mask(mask) # preconditionner iweights = 1 / weights iweights[np.where(np.isfinite(iweights) == 0)] = 0. M0 = lo.diag(iweights.flatten()) # transform to lo P = lo.aslinearoperator(model.aslinearoperator()) # priors Dx = lo.diff(backmap.shape, axis=0) Dy = lo.diff(backmap.shape, axis=1) # inversion y = (masking.T * tod).flatten() # algos algos = [spl.cg, spl.cgs, spl.bicg, spl.bicgstab] models = [ P.T * P, P.T * P + Dx.T * Dx + Dy.T * Dy, ] n_iterations = [] resid = []