import numpy as np import tomograpy import lo # object obj = tomograpy.centered_cubic_map(3, 32) obj[:] = tomograpy.phantom.shepp_logan(obj.shape) # data radius = 200. a = tomograpy.fov(obj.header, radius) data = tomograpy.centered_stack(a, 128, n_images=60, radius=radius, max_lon=np.pi) # projector P = tomograpy.lo(data.header, obj.header) # projection t = time.time() data = tomograpy.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)) # priors Ds = [lo.diff(obj.shape, axis=i) for i in xrange(3)] # inversion using scipy.sparse.linalg t = time.time()
# data path = os.path.join(os.getenv('HOME'), 'data', '171dec08') obsrvtry = 'STEREO_A' time_window = ['2008-12-01T00:00:00.000', '2008-12-03T00:00:00.000'] # one image every time_step seconds time_step = 4 * 3600. data = tomograpy.secchi.read_data(path, bin_factor=4, obsrvtry=obsrvtry, time_window=time_window, time_step=time_step) # cube shape = 3 * (128,) header = {'CRPIX1':64., 'CRPIX2':64., 'CRPIX3':64., 'CDELT1':0.0234375, 'CDELT2':0.0234375, 'CDELT3':0.0234375, 'CRVAL1':0., 'CRVAL2':0., 'CRVAL3':0.,} cube = fa.zeros(shape, header=header) # model P = tomograpy.lo(data.header, cube.header) D = [lo.diff(cube.shape, axis=i) for i in xrange(cube.ndim)] hypers = cube.ndim * (1e0, ) # inversion t = time.time() A = P.T * P + np.sum([h * d.T * d for h, d in zip(hypers, D)]) b = P.T * data.flatten() #callback = lo.iterative.CallbackFactory(verbose=True) #x, info = spl.bicgstab(A, b, maxiter=100, callback=callback) x, info = lo.acg(P, data.flatten(), D, hypers, maxiter=100,) sol = cube.copy() sol[:] = x.reshape(cube.shape) print(time.time() - t)
#!/usr/bin/env python """ Small projection test to compare with IDL tomograpy. """ import numpy as np import tomograpy im = tomograpy.centered_stack(0.0016, 32, n_images=1, radius=200., fill=0.) cube = tomograpy.centered_cubic_map(3, 256, fill=1.) P = tomograpy.lo(im.header, cube.header, obstacle="sun") im[:] = (P * cube.ravel()).reshape(im.shape)
#!/usr/bin/env python import time import numpy as np import tomograpy import lo # object obj = tomograpy.centered_cubic_map(3, 32) obj[:] = tomograpy.phantom.shepp_logan(obj.shape) # data radius = 200. a = tomograpy.fov(obj.header, radius) data = tomograpy.centered_stack(a, 128, n_images=60, radius=radius, max_lon=np.pi) # projector P = tomograpy.lo(data.header, obj.header) # projection t = time.time() data = tomograpy.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)) # priors Ds = [lo.diff(obj.shape, axis=i) for i in xrange(3)] # inversion using scipy.sparse.linalg t = time.time() sol = lo.acg(P, y, Ds, 1e-2 * np.ones(3), maxiter=100, tol=1e-20)