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
'2008-12-15T00:00:00.000'], time_step=8 * 3600. ) data = tomograpy.solar.sort_data_array(data) # scale A and B images # the ratio of sensitivity between EUVI A and B calibration_ba = {171:0.902023, 195:0.974536, 284:0.958269, 304:1.05954} for i in xrange(data.shape[-1]): if data.header[i]['OBSRVTRY'] == 'STEREO_B': data[..., i] /= calibration_ba[data.header[i]['WAVELNTH']] # make sure it is 64 bits data data.header[i]['BITPIX'] = -64 # cube cube = tomograpy.centered_cubic_map(3, 64, fill=0.) # model kwargs = {'obj_rmin':1., 'obj_rmax':1.5, 'data_rmin':1., 'data_rmax':1.3, 'mask_negative':False, 'mask_nan':True} P, D, obj_mask, data_mask = tomograpy.models.srt(data, cube, **kwargs) # apply mask to data data *= (1 - data_mask) data[np.isnan(data)] = 0. # hyperparameters hypers = cube.ndim * (1e0, ) # inversion # expected time b = data.ravel() b[np.isnan(b)] = 0. t = time.time() bpj = P.T * b
#!/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)]
#!/usr/bin/env python import time import numpy as np import tomograpy # object obj = tomograpy.centered_cubic_map(3, 128, fill=1.) # number of images n = 20 # reshape object for 4d model obj4 = obj.reshape(obj.shape + (1, )).repeat(n, axis=-1) obj4.header['NAXIS'] = 4 obj4.header['NAXIS4'] = obj4.shape[3] obj4.header['CRVAL4'] = 0. # data radius = 200 a = tomograpy.fov(obj.header, radius) data = tomograpy.centered_stack(a, 128, n_images=n, radius=radius, max_lon=np.pi) data[:] = np.zeros(data.shape) # projection t = time.time() data = tomograpy.projector4d(data, obj4) print("projection time : " + str(time.time() - t)) # backprojection x0 = obj4.copy() x0[:] = 0. t = time.time()
#!/usr/bin/env python import time import numpy as np import tomograpy import lo # object obj = tomograpy.centered_cubic_map(10, 64) obj[:] = tomograpy.phantom.shepp_logan(obj.shape) # data radius = 200 a = tomograpy.fov(obj, radius) data = tomograpy.centered_stack(a, 128, n_images=60, radius=radius, max_lon=np.pi) # model kwargs = {"pb":"pb", "obj_rmin":1.5, "data_rmin":1.5} P, D, obj_mask, data_mask = tomograpy.models.thomson(data, obj, u=.5, **kwargs) # projection t = time.time() data[:] = (P * obj.ravel()).reshape(data.shape) print("projection time : " + str(time.time() - t)) # data # backprojection t = time.time() x0 = P.T * data.ravel() bpj = x0.reshape(obj.shape) print("backprojection time : " + str(time.time() - t)) # inversion using scipy.sparse.linalg t = time.time() sol = lo.acg(P, data.ravel(), D, 1e-3 * np.ones(3), maxiter=100, tol=1e-8) sol = sol.reshape(obj.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 import lo # object obj = tomograpy.centered_cubic_map(10, 64) obj[:] = tomograpy.phantom.shepp_logan(obj.shape) # data radius = 200 a = tomograpy.fov(obj, radius) data = tomograpy.centered_stack(a, 128, n_images=60, radius=radius, max_lon=np.pi) # model kwargs = {"pb": "pb", "obj_rmin": 1.5, "data_rmin": 1.5} P, D, obj_mask, data_mask = tomograpy.models.thomson(data, obj, u=.5, **kwargs) # projection t = time.time() data[:] = (P * obj.ravel()).reshape(data.shape) print("projection time : " + str(time.time() - t)) # data # backprojection t = time.time() x0 = P.T * data.ravel() bpj = x0.reshape(obj.shape) print("backprojection time : " + str(time.time() - t)) # inversion using scipy.sparse.linalg t = time.time()
#!/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, 64, fill=1.) # number of images n = 64 # reshape object for 4d model obj4 = obj[..., np.newaxis].repeat(n, axis=-1) obj4.header['NAXIS'] = 4 obj4.header['NAXIS4'] = obj4.shape[3] obj4.header['CRVAL4'] = 0. # data radius = 200 a = tomograpy.fov(obj.header, radius) data1 = tomograpy.centered_stack(a, 64, n_images=n/2, radius=radius, max_lon=np.pi, fill=0.) data2 = tomograpy.centered_stack(a, 64, n_images=n/2, radius=radius, min_lon=np.pi / 2., max_lon=1.5 * np.pi, fill=0.) data = tomograpy.solar.concatenate((data1, data2)) # times DT = 1000. dt_min = 100. dates = np.arange(n / 2) * DT / 2. dates = np.concatenate(2 * (dates, )) dates = [time.strftime('%Y-%m-%dT%H:%M:%S', time.localtime((t))) for t in dates] for i in xrange(len(data.header)):
#!/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)