def test_map_shape(): obj = tomograpy.centered_cubic_map(3, cube_shape0) data = tomograpy.centered_stack(tomograpy.fov(obj, d), data_shape0, n_images=n_images) # projection pj_times = np.empty(len(cube_shapes) + 1) pj_times[0] = time.time() for i, s in enumerate(cube_shapes): obj = tomograpy.centered_cubic_map(3, s) tomograpy.projector(data, obj) pj_times[i + 1] = time.time() pj_times = pj_times[1:] - pj_times[:-1] # backprojection bpj_times = np.empty(len(cube_shapes) + 1) bpj_times[0] = time.time() for i, s in enumerate(cube_shapes): obj = tomograpy.centered_cubic_map(3, s) tomograpy.backprojector(data, obj) bpj_times[i + 1] = time.time() bpj_times = bpj_times[1:] - bpj_times[:-1] # pretty print text = '' text += 'Cube shape' text += ''.join([' & ' + str(s) + "$^3$" for s in cube_shapes]) text += ' \\\\ \n' + 'Projection (s)' text += ''.join([' & %2.2f' % pjt for pjt in pj_times]) text += ' \\\\ \n' + 'Backprojection (s)' text += ''.join([' & %2.2f' % bpjt for bpjt in bpj_times]) text += ' \\\\ \n' print text
def test_cores(): obj = tomograpy.centered_cubic_map(3, cube_shape0) data = tomograpy.centered_stack(tomograpy.fov(obj, d), data_shape0, n_images=n_images) # projection pj_times = np.empty(nthread_max + 1) pj_times[0] = time.time() for nt in xrange(nthread_max): tomograpy.projector(data, obj, nthread=nt + 1) pj_times[nt + 1] = time.time() pj_times = pj_times[1:] - pj_times[:-1] # backprojection bpj_times = np.empty(nthread_max + 1) bpj_times[0] = time.time() for nt in xrange(nthread_max): tomograpy.backprojector(data, obj, nthread=nt + 1) bpj_times[nt + 1] = time.time() bpj_times = bpj_times[1:] - bpj_times[:-1] # pretty print text = '' text += 'Cores' text += ''.join([' & ' + str(i + 1) for i in xrange(nthread_max)]) text += ' \\\\ \n' + 'Projection (s)' text += ''.join([' & %2.2f' % pjt for pjt in pj_times]) text += ' \\\\ \n' + 'Backprojection (s)' text += ''.join([' & %2.2f' % bpjt for bpjt in bpj_times]) text += ' \\\\ \n' print text
# 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) sol = sol.reshape(bpj.shape) print("inversion time : " + str(time.time() - t))
#!/usr/bin/env python import time import numpy as np import tomograpy # object obj = tomograpy.centered_cubic_map(3, 128, fill=1.) # data radius = 200. a = tomograpy.fov(obj.header, radius) data = tomograpy.centered_stack(a, 128, n_images=17, radius=200., max_lon=np.pi) # projection t = time.time() data = tomograpy.projector(data, obj, obstacle="sun") print("projection time : " + str(time.time() - t)) # backprojection obj0 = tomograpy.centered_cubic_map(3, 128, fill=0.) t = time.time() obj0 = tomograpy.backprojector(data, obj0, obstacle="sun") print("backprojection time : " + str(time.time() - t))
#!/usr/bin/env python import time import numpy as np import tomograpy # object object_header = tomograpy.centered_cubic_map_header(3, 128) obj = tomograpy.simu.object_from_header(object_header, fill=1.) # data radius = 200. a = tomograpy.fov(object_header, radius) data = tomograpy.centered_stack(a, 128, n_images=60, radius=200., max_lon=np.pi) # projection t = time.time() data = tomograpy.projector(data, obj) print("projection time : " + str(time.time() - t)) # backprojection t = time.time() data[:] = 1. obj0 = tomograpy.simu.object_from_header(object_header, fill=0.) obj0 = tomograpy.backprojector(data, obj0) print("backprojection time : " + str(time.time() - t)) obj1 = tomograpy.simu.object_from_header(object_header, fill=0.) obj1 = tomograpy.backprojector(data, obj1)