示例#1
0
def test_image_shape():
    obj = tomograpy.centered_cubic_map(3, cube_shape0)
    # projection
    pj_times = np.empty(len(image_shapes) + 1)
    pj_times[0] = time.time()
    for i, s in enumerate(image_shapes):
        data = tomograpy.centered_stack(tomograpy.fov(obj, d),
                                        s,
                                        n_images=n_images)
        tomograpy.projector(data, obj)
        pj_times[i + 1] = time.time()
    pj_times = pj_times[1:] - pj_times[:-1]
    # backprojection
    bpj_times = np.empty(len(image_shapes) + 1)
    bpj_times[0] = time.time()
    for i, s in enumerate(image_shapes):
        data = tomograpy.centered_stack(tomograpy.fov(obj, d),
                                        s,
                                        n_images=n_images)
        tomograpy.backprojector(data, obj)
        bpj_times[i + 1] = time.time()
    bpj_times = bpj_times[1:] - bpj_times[:-1]
    # pretty print
    text = ''
    text += 'Image shape'
    text += ''.join(
        [' & ' + str(s) + " $\\times$ " + str(s) for s in image_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
示例#2
0
def test_image_shape():
    obj = tomograpy.centered_cubic_map(3, cube_shape0)
    # projection
    pj_times = np.empty(len(image_shapes) + 1)
    pj_times[0] = time.time()
    for i, s in enumerate(image_shapes):
        data = tomograpy.centered_stack(tomograpy.fov(obj, d), s, n_images=n_images)
        tomograpy.projector(data, obj)
        pj_times[i + 1] = time.time()
    pj_times = pj_times[1:] - pj_times[:-1]
    # backprojection
    bpj_times = np.empty(len(image_shapes) + 1)
    bpj_times[0] = time.time()
    for i, s in enumerate(image_shapes):
        data = tomograpy.centered_stack(tomograpy.fov(obj, d), s, n_images=n_images)
        tomograpy.backprojector(data, obj)
        bpj_times[i + 1] = time.time()
    bpj_times = bpj_times[1:] - bpj_times[:-1]
    # pretty print
    text = ''
    text += 'Image shape'
    text += ''.join([' & ' + str(s) + " $\\times$ " + str(s)  for s in image_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
示例#3
0
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
示例#4
0
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
示例#5
0
#!/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)]
# 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.
示例#7
0
#!/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))
示例#8
0
#!/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))
示例#9
0
#!/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)
示例#10
0
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)):
    data.header[i]['DATE_OBS'] = dates[i]

data = tomograpy.solar.sort_data_array(data)