Skip to content

Commit

Permalink
ref: fix examples (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Apr 3, 2018
1 parent 54e2b3c commit 734badd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 30 deletions.
45 changes: 18 additions & 27 deletions examples/3D_example.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,31 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Example of handling 3D data.
"""Volumetric data reconstruction
Using the `*_3d` methods only speeds up calculations if your processor
has multiple cores.
"""
from __future__ import print_function, division
from multiprocessing import cpu_count
import numpy as np
from os.path import split, dirname, abspath
import time
import sys

sys.path = [split(dirname(abspath(__file__)))[0]] + sys.path
import numpy as np

import radontea as rt


if __name__ == "__main__":
A = 70 # number of angles
N = 128 # detector size x
M = 24 # detector size y (number of slices)
A = 70 # number of angles
N = 128 # detector size x
M = 24 # detector size y (number of slices)

# generate random data
sino0 = np.random.random((A, N)) # for 2d example
sino = np.random.random((A, M, N)) # for 3d example
sino[:, 0, :] = sino0
angles = np.linspace(0, np.pi, A) # for both
# generate random data
sino0 = np.random.random((A, N)) # for 2d example
sino = np.random.random((A, M, N)) # for 3d example
sino[:, 0, :] = sino0
angles = np.linspace(0, np.pi, A) # for both

a = time.time()
data0 = rt.backproject(sino0, angles)
print("time on 1 core: {} s".format((time.time() - a)*M))
a = time.time()
data1 = rt.backproject_3d(sino, angles, ncpus=1)
print("time on 1 core: {:.2f} s".format(time.time() - a))

a = time.time()
data = rt._Back_3D.backproject(sino, angles)
print("time on {} cores: {} s".format(cpu_count(), time.time() - a))
a = time.time()
data2 = rt.backproject_3d(sino, angles, ncpus=cpu_count())
print("time on {} cores: {:.2f} s".format(cpu_count(), time.time() - a))

assert np.sum(data0 == data[:, 0, :]
) == N**2, "2D and 3D results don't match"
assert np.all(data1 == data2), "2D and 3D results don't match"
6 changes: 3 additions & 3 deletions examples/comparison_parallel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Comparison of parallel-beam reconstruction methods
This example illustrates the performance of the
different reconstruction techniques for a parralel-beam
different reconstruction techniques for a parallel-beam
geometry. The left column shows the reconstruction of
the original image and the right column shows the reconstruction
of the corresponding binary images. Note that the
Expand All @@ -23,14 +23,14 @@
angles = np.linspace(0, np.pi, A)

im = get_original(N)
sino = radontea.radon(im, angles)
sino = radontea.radon_parallel(im, angles)
fbp = radontea.backproject(sino, angles)
fintp = radontea.fourier_map(sino, angles).real
sarta = radontea.sart(sino, angles, iterations=ITA)
sartb = radontea.sart(sino, angles, iterations=ITB)

im2 = (im >= (im.max() / 5)) * 255
sino2 = radontea.radon(im2, angles)
sino2 = radontea.radon_parallel(im2, angles)
fbp2 = radontea.backproject(sino2, angles)
fintp2 = radontea.fourier_map(sino2, angles).real
sarta2 = radontea.sart(sino2, angles, iterations=ITA)
Expand Down

0 comments on commit 734badd

Please sign in to comment.