コード例 #1
0
# data
tod = pacs.get_tod()
# remove bad pixels (by updating mask !)
#tod = remove_bad_pixels(tod)
# deglitching
projection = Projection(pacs,
                        header=header,
                        resolution=3.,
                        npixels_per_sample=6)
tod.mask = deglitch_l2mad(tod, projection)
# model
masking = Masking(tod.mask)
model = masking * projection
# remove drift
tod = filter_median(tod, length=49)
# first map
backmap = model.transpose(tod)
P = lo.aslinearoperator(model.aslinearoperator())
y = tod.flatten()
# define algo
# priors
Dx = lo.diff(backmap.shape, axis=0, dtype=np.float64)
Dy = lo.diff(backmap.shape, axis=1, dtype=np.float64)
# inversion
x, conv = lo.rls(P, (Dx, Dy), (1e2, 1e2), y)
sol = backmap.zeros(backmap.shape)
sol[:] = x.reshape(sol.shape)
# save
sol.writefits(
    os.path.join(os.getenv('HOME'), 'data', 'csh', 'output', 'abell2218.fits'))
コード例 #2
0
data = siddon.simu.circular_trajectory_data(**image_header)
data[:] = np.zeros(data.shape)
# projector
P = siddon.siddon_lo(data.header, obj.header)
# projection
t = time.time()
data = siddon.projector(data, obj)
print("projection time : " + str(time.time() - t))
# data
y = data.flatten()
# backprojection
t = time.time()
x0 = P.T * y
bpj = x0.reshape(obj.shape)
print("projection time : " + str(time.time() - t))
# coverage map
weights = (P.T * np.ones(y.size)).reshape(obj.shape)
# priors
Ds = [lo.diff(obj.shape, axis=i) for i in xrange(3)]
hypers = 1e-2 * np.ones(3)
#Ds, hypers = [], []
# inversion using scipy.sparse.linalg
t = time.time()
tol = 1e-5
sol, info = lo.rls(P, y, Ds, hypers,  maxiter=100, tol=tol)
sol = sol.reshape(bpj.shape)
if info != 0:
    print("Inversion algorithm did not converge to " + str(tol))

print("inversion time : " + str(time.time() - t))
コード例 #3
0
ファイル: test_tamasis_noise.py プロジェクト: pombredanne/csh
import lo
import csh.filter as filt
from time import time
import scipy.sparse.linalg as spl

# data
pacs = tm.PacsObservation(filename=tm.tamasis_dir+'tests/frames_blue.fits')
tod = pacs.get_tod()
# projector
model = tm.Projection(pacs, resolution=3.2, oversampling=False, npixels_per_sample=6)
# naive map
backmap = model.transpose(tod)
# transform to lo
P = lo.aslinearoperator(model.aslinearoperator())
# derive filter
kernel = filt.kernel_from_tod(tod, length=10)
#kern = np.mean(kernel, axis=0)
N = filt.kernels_convolve(tod.shape, 1 / np.sqrt(kernel))
# apply to data
yn = N * tod.flatten()
# apply to model
M = N * P
# priors
Ds = [lo.diff(backmap.shape, axis=axis) for axis in xrange(backmap.ndim)]
#Ds.append(lo.pywt_lo.wavelet2(backmap.shape, "haar"))
# inversion
#y = tod.flatten()
x, conv = lo.rls(M, Ds, (1e1, 1e1, 1e-1),  yn, spl.bicgstab)
sol = backmap.zeros(backmap.shape)
sol[:] = x.reshape(sol.shape)
コード例 #4
0
deglitch_l2mad(tod, projection)
# model
masking = Masking(tod.mask)
model = masking * projection
P = lo.aslinearoperator(model.aslinearoperator())
# derive filter
#tod = filter_median(tod, length=9999)
#kernel = filt.kernel_from_tod(tod, length=1000)
kernel =  (1 + (10. / np.arange(500)) ** .25)
kernel = np.concatenate((kernel[::-1], kernel))
#kern = np.mean(kernel, axis=0)
N = filt.kernels_convolve(tod.shape, 1 / np.sqrt(kernel))
# apply to data
yn = N * tod.flatten()
# apply to model
M = N * P
# first map
backmap = model.transpose(tod)
# define algo
# priors
Dx = lo.diff(backmap.shape, axis=0, dtype=np.float64)
Dy = lo.diff(backmap.shape, axis=1, dtype=np.float64)
#Dw = lo.pywt_lo.wavedec2(backmap.shape, "haar", level=3)
# inversion
x, conv = lo.rls(M, (Dx, Dy), (1e1, 1e1),  yn, tol=1e-10)
sol = backmap.zeros(backmap.shape)
sol[:] = x.reshape(sol.shape)
# save
sol.writefits(os.path.join(os.getenv('HOME'), 'data', 'csh', 'output',
                           'ngc6946__filter_rls.fits'))
コード例 #5
0
ファイル: test_tamasis.py プロジェクト: linkerlin/csh
#!/usr/bin/env python
import numpy as np
import tamasis as tm
import lo

# data
pacs = tm.PacsObservation(filename=tm.tamasis_dir+'tests/frames_blue.fits')
tod = pacs.get_tod()
# projector
model = tm.Projection(pacs, resolution=3.2, oversampling=False, npixels_per_sample=6)
# naive map
backmap = model.transpose(tod)
# transform to lo
P = lo.aslinearoperator(model.aslinearoperator())
# priors
Ds = [lo.diff(backmap.shape, axis=axis) for axis in xrange(backmap.ndim)]
Ds.append(lo.pywt_lo.wavelet2(backmap.shape, "haar"))
# inversion
y = tod.flatten()
x, conv = lo.rls(P, Ds, (1e1, 1e1, 1e-1),  y)
sol = backmap.zeros(backmap.shape)
sol[:] = x.reshape(sol.shape)
コード例 #6
0
          'CRPIX2':64.,
          'CRPIX3':64.,
          'CDELT1':0.0234375,
          'CDELT2':0.0234375,
          'CDELT3':0.0234375,
          'CRVAL1':0.,
          'CRVAL2':0.,
          'CRVAL3':0.,}
cube = tomograpy.fa.zeros(shape, header=header)
# model
kwargs = {'obj_rmin':1., 'obj_rmax':1.4, 'data_rmax':1.3,
          'mask_negative':True, 'dt_min':100}
P, D, obj_mask, data_mask = tomograpy.models.stsrt(data, cube, **kwargs)
# apply mask to data
data *= (1 - data_mask)
# hyperparameters
hypers = (1e-1, 1e-1, 1e-1, 1e6)
# test time for one projection
t = time.time()
u = P.T * data.ravel()
print("maximal time : %f" % ((time.time() - t) * 100))
# inversion
t = time.time()
b = data.ravel()
#sol = lo.acg(P, b, D, hypers, maxiter=100)
sol = lo.rls(P, b, D, hypers, maxiter=100)
# reshape result
fsol = tomograpy.fa.asfitsarray(sol.reshape(obj_mask.shape), header=header)
print(time.time() - t)
fsol.tofits('stsrt_test.fits')
コード例 #7
0
ファイル: ngc6946_cs.py プロジェクト: nbarbey/csh
# ctod = compression.direct(uctod)
# model
masking = tm.Masking(uctod.mask)
model = masking * projection
# remove drift
# ctod = tm.filter_median(ctod, length=3000 / 8.)
# first map
M = C * lo.aslinearoperator(model.aslinearoperator())
# P = lo.aslinearoperator(projection.aslinearoperator())
# C = csh.averaging(tod.shape, factor=8)
# I = lo.mask(uctod.mask)
# M = C * I.T * I * P
# M = C * P
backmap = (M.T * ctod.flatten()).reshape(projection.shapein)
# weights = (M.T * np.ones(ctod.size)).reshape(projection.shapein)
weights = projection.transpose(tod.ones(tod.shape))
MM = lo.mask(weights == 0)
M = M * MM.T
# define algo
# priors
Dx = lo.diff(backmap.shape, axis=0, dtype=np.float64) * MM.T
Dy = lo.diff(backmap.shape, axis=1, dtype=np.float64) * MM.T
# Dw = lo.pywt_lo.wavedec2(backmap.shape, "haar", level=3)
# inversion
x, conv = lo.rls(M, (Dx, Dy), (1e0, 1e0), ctod.flatten())
sol = tm.Map(np.zeros(backmap.shape))
sol[:] = (MM.T * x).reshape(sol.shape)
sol.header = header
# save
sol.writefits(os.path.join(os.getenv("HOME"), "data", "csh", "output", "ngc6946_cs_rls.fits"))
コード例 #8
0
ファイル: abell2218.py プロジェクト: linkerlin/csh
# get header from altieri maps
header = pyfits.fitsopen('/mnt/herschel1/mapmaking/nbarbey/Abell2218_altieri/' +
                         'a2218_red_Map.v2.2.sci.fits')[0].header
# data
tod = pacs.get_tod()
# remove bad pixels (by updating mask !)
#tod = remove_bad_pixels(tod)
# deglitching
projection = Projection(pacs, header=header, resolution=3., npixels_per_sample=6)
tod.mask = deglitch_l2mad(tod, projection)
# model
masking = Masking(tod.mask)
model = masking * projection
# remove drift
tod = filter_median(tod, length=49)
# first map
backmap = model.transpose(tod)
P = lo.aslinearoperator(model.aslinearoperator())
y = tod.flatten()
# define algo
# priors
Dx = lo.diff(backmap.shape, axis=0, dtype=np.float64)
Dy = lo.diff(backmap.shape, axis=1, dtype=np.float64)
# inversion
x, conv = lo.rls(P, (Dx, Dy), (1e2, 1e2),  y)
sol = backmap.zeros(backmap.shape)
sol[:] = x.reshape(sol.shape)
# save
sol.writefits(os.path.join(os.getenv('HOME'), 'data', 'csh', 'output',
                           'abell2218.fits'))
コード例 #9
0
ファイル: test_tamasis_ca.py プロジェクト: pombredanne/csh
                       keep_bad_detectors=False)
tod = pacs.get_tod()
# compression model
C = lo.binning(tod.shape, factor=8, axis=1, dtype=np.float64)
# compress data
ctod = C * tod.flatten()
# projector
projection = Projection(pacs, resolution=3.2, oversampling=False, npixels_per_sample=6)
model = 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)
# transform to lo
#P = lo.ndsubclass(backmap, tod, matvec=model.direct, rmatvec=model.transpose)
P = lo.aslinearoperator(model.aslinearoperator())
# full model
A = C * P * M.T
# priors
Dx = lo.diff(backmap.shape, axis=0, dtype=np.float64) * M.T
Dy = lo.diff(backmap.shape, axis=1, dtype=np.float64) * M.T
Dw = lo.pywt_lo.wavelet2(backmap.shape, "haar") * M.T
# inversion
y = ctod.flatten()
x, conv = lo.rls(A, (Dx, Dy, Dw), (1e1, 1e1, 1e1),  y)
sol = backmap.zeros(backmap.shape)
sol[mask == 0] = x
コード例 #10
0
# model
masking = Masking(tod.mask)
model = masking * projection
# remove drift
#tod = filter_median(tod, length=3000)
# first map
backmap = model.transpose(tod)
# coverage
weights = model.transpose(tod.ones(tod.shape))
P = lo.aslinearoperator(model.aslinearoperator())
# mask not seen part of the map
MM = lo.mask(weights == 0)
y = tod.flatten()
# define algo
# priors
Dx = lo.diff(backmap.shape, axis=0, dtype=np.float64)
Dy = lo.diff(backmap.shape, axis=1, dtype=np.float64)
#Dw = lo.pywt_lo.wavedec2(backmap.shape, "haar", level=3)
# inversion
x, conv = lo.rls(P * MM.T, (Dx * MM.T, Dy * MM.T), (1e1, 1e1), y)
sol = backmap.zeros(backmap.shape)
sol[:] = (MM.T * x).reshape(sol.shape)
# save
sol.header = header
sol.writefits(
    os.path.join(os.getenv('HOME'), 'data', 'csh', 'output',
                 'ngc6946_rls.fits'))
weights.writefits(
    os.path.join(os.getenv('HOME'), 'data', 'csh', 'output',
                 'ngc6946_rls_weights.fits'))
コード例 #11
0
# model
masking = tm.Masking(uctod.mask)
model = compression * masking * projection
# remove drift
#ctod = tm.filter_median(ctod, length=3000 / 8.)
# first map
M = lo.aslinearoperator(model.aslinearoperator())
#P = lo.aslinearoperator(projection.aslinearoperator())
#C = csh.averaging(tod.shape, factor=8)
#I = lo.mask(uctod.mask)
#M = C * I.T * I * P
#M = C * P
backmap = model.transpose(ctod)
weights = model.transpose(ctod.ones(ctod.shape))
MM = lo.mask(weights == 0)
M = M * MM.T
# define algo
# priors
Dx = lo.diff(backmap.shape, axis=0, dtype=np.float64) * MM.T
Dy = lo.diff(backmap.shape, axis=1, dtype=np.float64) * MM.T
#Dw = lo.pywt_lo.wavedec2(backmap.shape, "haar", level=3)
# inversion
x, conv = lo.rls(M, (Dx, Dy), (1e0, 1e0), ctod.flatten())
sol = backmap.zeros(backmap.shape)
sol[:] = (MM.T * x).reshape(sol.shape)
# save
sol.header = header
sol.writefits(
    os.path.join(os.getenv('HOME'), 'data', 'csh', 'output',
                 'ngc6946_ca_rls.fits'))
コード例 #12
0
#!/usr/bin/env python
import numpy as np
import tamasis as tm
import lo

# data
pacs = tm.PacsObservation(filename=tm.tamasis_dir + 'tests/frames_blue.fits')
tod = pacs.get_tod()
# projector
model = tm.Projection(pacs,
                      resolution=3.2,
                      oversampling=False,
                      npixels_per_sample=6)
# naive map
backmap = model.transpose(tod)
# transform to lo
P = lo.aslinearoperator(model.aslinearoperator())
# priors
Ds = [lo.diff(backmap.shape, axis=axis) for axis in xrange(backmap.ndim)]
Ds.append(lo.pywt_lo.wavelet2(backmap.shape, "haar"))
# inversion
y = tod.flatten()
x, conv = lo.rls(P, Ds, (1e1, 1e1, 1e-1), y)
sol = backmap.zeros(backmap.shape)
sol[:] = x.reshape(sol.shape)
コード例 #13
0
ファイル: ngc6946.py プロジェクト: linkerlin/csh
                        npixels_per_sample=5)
deglitch_l2mad(tod, projection)
# model
masking = Masking(tod.mask)
model = masking * projection
# remove drift
#tod = filter_median(tod, length=3000)
# first map
backmap = model.transpose(tod)
# coverage
weights = model.transpose(tod.ones(tod.shape))
P = lo.aslinearoperator(model.aslinearoperator())
# mask not seen part of the map
MM = lo.mask(weights ==0)
y = tod.flatten()
# define algo
# priors
Dx = lo.diff(backmap.shape, axis=0, dtype=np.float64)
Dy = lo.diff(backmap.shape, axis=1, dtype=np.float64)
#Dw = lo.pywt_lo.wavedec2(backmap.shape, "haar", level=3)
# inversion
x, conv = lo.rls(P * MM.T, (Dx * MM.T, Dy * MM.T), (1e1, 1e1),  y)
sol = backmap.zeros(backmap.shape)
sol[:] = (MM.T * x).reshape(sol.shape)
# save
sol.header = header
sol.writefits(os.path.join(os.getenv('HOME'), 'data', 'csh', 'output',
                           'ngc6946_rls.fits'))
weights.writefits(os.path.join(os.getenv('HOME'), 'data', 'csh', 'output',
                               'ngc6946_rls_weights.fits'))