-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54e2b3c
commit 734badd
Showing
2 changed files
with
21 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters