Skip to content

Commit 45f3d88

Browse files
authored
Merge pull request #210 from DiamondLightSource/recon_name_change
Reconstruction methods renaming
2 parents 4ca1050 + 2583efe commit 45f3d88

File tree

4 files changed

+58
-53
lines changed

4 files changed

+58
-53
lines changed

httomolibgpu/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,12 @@
1111
remove_all_stripe,
1212
)
1313

14-
from httomolibgpu.recon.algorithm import FBP2d_astra, FBP, LPRec, SIRT, CGLS
14+
from httomolibgpu.recon.algorithm import (
15+
FBP2d_astra,
16+
FBP3d_tomobar,
17+
LPRec3d_tomobar,
18+
SIRT3d_tomobar,
19+
CGLS3d_tomobar,
20+
)
21+
1522
from httomolibgpu.recon.rotation import find_center_vo, find_center_360, find_center_pc

httomolibgpu/recon/algorithm.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343

4444
__all__ = [
4545
"FBP2d_astra",
46-
"FBP",
47-
"SIRT",
48-
"CGLS",
49-
"LPRec",
46+
"FBP3d_tomobar",
47+
"LPRec3d_tomobar",
48+
"SIRT3d_tomobar",
49+
"CGLS3d_tomobar",
5050
]
5151

5252
input_data_axis_labels = ["angles", "detY", "detX"] # set the labels of the input data
@@ -132,13 +132,13 @@ def FBP2d_astra(
132132

133133

134134
## %%%%%%%%%%%%%%%%%%%%%%% FBP reconstruction %%%%%%%%%%%%%%%%%%%%%%%%%%%% ##
135-
def FBP(
135+
def FBP3d_tomobar(
136136
data: cp.ndarray,
137137
angles: np.ndarray,
138138
center: Optional[float] = None,
139139
filter_freq_cutoff: float = 0.35,
140140
recon_size: Optional[int] = None,
141-
recon_mask_radius: float = 0.95,
141+
recon_mask_radius: Optional[float] = 0.95,
142142
neglog: bool = False,
143143
gpu_id: int = 0,
144144
) -> cp.ndarray:
@@ -160,7 +160,7 @@ def FBP(
160160
recon_size : int, optional
161161
The [recon_size, recon_size] shape of the reconstructed slice in pixels.
162162
By default (None), the reconstructed size will be the dimension of the horizontal detector.
163-
recon_mask_radius: float
163+
recon_mask_radius: float, optional
164164
The radius of the circular mask that applies to the reconstructed slice in order to crop
165165
out some undesirable artifacts. The values outside the given diameter will be set to zero.
166166
It is recommended to keep the value in the range [0.7-1.0].
@@ -173,7 +173,7 @@ def FBP(
173173
Returns
174174
-------
175175
cp.ndarray
176-
The FBP reconstructed volume as a CuPy array.
176+
FBP reconstructed volume as a CuPy array.
177177
"""
178178
RecToolsCP = _instantiate_direct_recon_class(
179179
data, angles, center, recon_size, gpu_id
@@ -190,7 +190,7 @@ def FBP(
190190

191191

192192
## %%%%%%%%%%%%%%%%%%%%%%% LPRec %%%%%%%%%%%%%%%%%%%%%%%%%%%% ##
193-
def LPRec(
193+
def LPRec3d_tomobar(
194194
data: cp.ndarray,
195195
angles: np.ndarray,
196196
center: Optional[float] = None,
@@ -214,7 +214,7 @@ def LPRec(
214214
recon_size : int, optional
215215
The [recon_size, recon_size] shape of the reconstructed slice in pixels.
216216
By default (None), the reconstructed size will be the dimension of the horizontal detector.
217-
recon_mask_radius: float
217+
recon_mask_radius: float, optional
218218
The radius of the circular mask that applies to the reconstructed slice in order to crop
219219
out some undesirable artifacts. The values outside the given diameter will be set to zero.
220220
It is recommended to keep the value in the range [0.7-1.0].
@@ -239,7 +239,7 @@ def LPRec(
239239

240240

241241
## %%%%%%%%%%%%%%%%%%%%%%% SIRT reconstruction %%%%%%%%%%%%%%%%%%%%%%%%%%%% ##
242-
def SIRT(
242+
def SIRT3d_tomobar(
243243
data: cp.ndarray,
244244
angles: np.ndarray,
245245
center: Optional[float] = None,
@@ -304,7 +304,7 @@ def SIRT(
304304

305305

306306
## %%%%%%%%%%%%%%%%%%%%%%% CGLS reconstruction %%%%%%%%%%%%%%%%%%%%%%%%%%%% ##
307-
def CGLS(
307+
def CGLS3d_tomobar(
308308
data: cp.ndarray,
309309
angles: np.ndarray,
310310
center: Optional[float] = None,

tests/test_recon/test_algorithm.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from httomolibgpu.prep.normalize import normalize as normalize_cupy
44
from httomolibgpu.recon.algorithm import (
55
FBP2d_astra,
6-
FBP,
7-
LPRec,
8-
SIRT,
9-
CGLS,
6+
FBP3d_tomobar,
7+
LPRec3d_tomobar,
8+
SIRT3d_tomobar,
9+
CGLS3d_tomobar,
1010
)
1111
from numpy.testing import assert_allclose
1212
import time
@@ -34,9 +34,8 @@ def test_reconstruct_FBP_2d_astra(data, flats, darks, ensure_clean_memory):
3434
assert recon_data.dtype == np.float32
3535
assert recon_data.shape == (recon_size, 128, recon_size)
3636

37-
38-
def test_reconstruct_FBP_1(data, flats, darks, ensure_clean_memory):
39-
recon_data = FBP(
37+
def test_reconstruct_FBP3d_tomobar_1(data, flats, darks, ensure_clean_memory):
38+
recon_data = FBP3d_tomobar(
4039
normalize_cupy(data, flats, darks, cutoff=10, minus_log=True),
4140
np.linspace(0.0 * np.pi / 180.0, 180.0 * np.pi / 180.0, data.shape[0]),
4241
79.5,
@@ -53,8 +52,8 @@ def test_reconstruct_FBP_1(data, flats, darks, ensure_clean_memory):
5352
assert recon_data.shape == (160, 128, 160)
5453

5554

56-
def test_reconstruct_FBP_1_neglog(data, flats, darks, ensure_clean_memory):
57-
recon_data = FBP(
55+
def test_reconstruct_FBP3d_tomobar_1_neglog(data, flats, darks, ensure_clean_memory):
56+
recon_data = FBP3d_tomobar(
5857
normalize_cupy(data, flats, darks, cutoff=10, minus_log=False),
5958
np.linspace(0.0 * np.pi / 180.0, 180.0 * np.pi / 180.0, data.shape[0]),
6059
79.5,
@@ -72,8 +71,8 @@ def test_reconstruct_FBP_1_neglog(data, flats, darks, ensure_clean_memory):
7271
assert recon_data.shape == (160, 128, 160)
7372

7473

75-
def test_reconstruct_FBP_2(data, flats, darks, ensure_clean_memory):
76-
recon_data = FBP(
74+
def test_reconstruct_FBP3d_tomobar_2(data, flats, darks, ensure_clean_memory):
75+
recon_data = FBP3d_tomobar(
7776
normalize_cupy(data, flats, darks, cutoff=20.5, minus_log=False),
7877
np.linspace(5.0 * np.pi / 360.0, 180.0 * np.pi / 360.0, data.shape[0]),
7978
15.5,
@@ -90,8 +89,8 @@ def test_reconstruct_FBP_2(data, flats, darks, ensure_clean_memory):
9089
assert recon_data.dtype == np.float32
9190

9291

93-
def test_reconstruct_FBP_3(data, flats, darks, ensure_clean_memory):
94-
recon_data = FBP(
92+
def test_reconstruct_FBP3d_tomobar_3(data, flats, darks, ensure_clean_memory):
93+
recon_data = FBP3d_tomobar(
9594
normalize_cupy(data, flats, darks, cutoff=20.5, minus_log=False),
9695
np.linspace(5.0 * np.pi / 360.0, 180.0 * np.pi / 360.0, data.shape[0]),
9796
79, # center
@@ -109,8 +108,8 @@ def test_reconstruct_FBP_3(data, flats, darks, ensure_clean_memory):
109108
assert recon_data.shape == (210, 128, 210)
110109

111110

112-
def test_reconstruct_LPREC_1(data, flats, darks, ensure_clean_memory):
113-
recon_data = LPRec(
111+
def test_reconstruct_LPRec3d_tomobar_1(data, flats, darks, ensure_clean_memory):
112+
recon_data = LPRec3d_tomobar(
114113
data=normalize_cupy(data, flats, darks, cutoff=10, minus_log=True),
115114
angles=np.linspace(0.0 * np.pi / 180.0, 180.0 * np.pi / 180.0, data.shape[0]),
116115
center=79.5,
@@ -124,9 +123,9 @@ def test_reconstruct_LPREC_1(data, flats, darks, ensure_clean_memory):
124123
assert recon_data.shape == (130, 128, 130)
125124

126125

127-
def test_reconstruct_SIRT(data, flats, darks, ensure_clean_memory):
126+
def test_reconstruct_SIRT3d_tomobar(data, flats, darks, ensure_clean_memory):
128127
objrecon_size = data.shape[2]
129-
recon_data = SIRT(
128+
recon_data = SIRT3d_tomobar(
130129
normalize_cupy(data, flats, darks, cutoff=10, minus_log=True),
131130
np.linspace(0.0 * np.pi / 180.0, 180.0 * np.pi / 180.0, data.shape[0]),
132131
79.5,
@@ -141,9 +140,9 @@ def test_reconstruct_SIRT(data, flats, darks, ensure_clean_memory):
141140
assert recon_data.dtype == np.float32
142141

143142

144-
def test_reconstruct_CGLS(data, flats, darks, ensure_clean_memory):
143+
def test_reconstruct_CGLS3d_tomobar(data, flats, darks, ensure_clean_memory):
145144
objrecon_size = data.shape[2]
146-
recon_data = CGLS(
145+
recon_data = CGLS3d_tomobar(
147146
normalize_cupy(data, flats, darks, cutoff=10, minus_log=True),
148147
np.linspace(0.0 * np.pi / 180.0, 180.0 * np.pi / 180.0, data.shape[0]),
149148
79.5,
@@ -159,7 +158,7 @@ def test_reconstruct_CGLS(data, flats, darks, ensure_clean_memory):
159158

160159

161160
@pytest.mark.perf
162-
def test_FBP_performance(ensure_clean_memory):
161+
def test_FBP3d_tomobar_performance(ensure_clean_memory):
163162
dev = cp.cuda.Device()
164163
data_host = np.random.random_sample(size=(1801, 5, 2560)).astype(np.float32) * 2.0
165164
data = cp.asarray(data_host, dtype=np.float32)
@@ -168,13 +167,13 @@ def test_FBP_performance(ensure_clean_memory):
168167
filter_freq_cutoff = 1.1
169168

170169
# cold run first
171-
FBP(data, angles, cor, filter_freq_cutoff)
170+
FBP3d_tomobar(data, angles, cor, filter_freq_cutoff)
172171
dev.synchronize()
173172

174173
start = time.perf_counter_ns()
175174
nvtx.RangePush("Core")
176175
for _ in range(10):
177-
FBP(data, angles, cor)
176+
FBP3d_tomobar(data, angles, cor)
178177
nvtx.RangePop()
179178
dev.synchronize()
180179
duration_ms = float(time.perf_counter_ns() - start) * 1e-6 / 10

zenodo-tests/test_recon/test_algorithm.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from httomolibgpu.prep.normalize import normalize
99
from httomolibgpu.recon.algorithm import (
1010
FBP2d_astra,
11-
FBP,
12-
LPRec,
11+
FBP3d_tomobar,
12+
LPRec3d_tomobar,
1313
)
1414
from httomolibgpu.misc.morph import sino_360_to_180
1515
from numpy.testing import assert_allclose
@@ -18,7 +18,6 @@
1818
from cupy.cuda import nvtx
1919
from conftest import force_clean_gpu_memory
2020

21-
2221
def test_reconstruct_FBP2d_astra_i12_dataset1(i12_dataset1):
2322
force_clean_gpu_memory()
2423
projdata = i12_dataset1[0]
@@ -44,9 +43,9 @@ def test_reconstruct_FBP2d_astra_i12_dataset1(i12_dataset1):
4443
assert_allclose(np.sum(recon_data), 84672.84, atol=1e-2)
4544
assert recon_data.dtype == np.float32
4645
assert recon_data.shape == (2560, 50, 2560)
46+
4747

48-
49-
def test_reconstruct_FBP_i12_dataset1(i12_dataset1):
48+
def test_reconstruct_FBP3d_tomobar_i12_dataset1(i12_dataset1):
5049
force_clean_gpu_memory()
5150
projdata = i12_dataset1[0]
5251
angles = i12_dataset1[1]
@@ -58,7 +57,7 @@ def test_reconstruct_FBP_i12_dataset1(i12_dataset1):
5857
del flats, darks, projdata
5958
force_clean_gpu_memory()
6059

61-
recon_data = FBP(
60+
recon_data = FBP3d_tomobar(
6261
data_normalised,
6362
np.deg2rad(angles),
6463
center=1253.75,
@@ -92,13 +91,13 @@ def test_reconstruct_LP_REC_i13_dataset1(i13_dataset1):
9291
# GPU archetictures older than 5.3 wont accept the data larger than
9392
# (4096, 4096, 4096), while the newer ones can accept (16384 x 16384 x 16384)
9493

95-
# recon_data = FBP(
94+
# recon_data = FBP3d_tomobar(
9695
# stiched_data_180degrees,
9796
# np.deg2rad(angles[0:3000]),
9897
# center=2322,
9998
# filter_freq_cutoff=0.35,
10099
# )
101-
recon_data = LPRec(
100+
recon_data = LPRec3d_tomobar(
102101
data=stiched_data_180degrees,
103102
angles=np.deg2rad(angles[0:3000]),
104103
center=2322.08,
@@ -112,7 +111,7 @@ def test_reconstruct_LP_REC_i13_dataset1(i13_dataset1):
112111

113112

114113
@pytest.mark.perf
115-
def test_FBP_performance_i13_dataset2(i13_dataset2):
114+
def test_FBP3d_tomobar_performance_i13_dataset2(i13_dataset2):
116115
force_clean_gpu_memory()
117116
dev = cp.cuda.Device()
118117
projdata = i13_dataset2[0]
@@ -126,7 +125,7 @@ def test_FBP_performance_i13_dataset2(i13_dataset2):
126125
force_clean_gpu_memory()
127126

128127
# cold run first
129-
FBP(
128+
FBP3d_tomobar(
130129
data_normalised,
131130
np.deg2rad(angles),
132131
center=1253.75,
@@ -137,7 +136,7 @@ def test_FBP_performance_i13_dataset2(i13_dataset2):
137136
start = time.perf_counter_ns()
138137
nvtx.RangePush("Core")
139138
for _ in range(10):
140-
FBP(
139+
FBP3d_tomobar(
141140
data_normalised,
142141
np.deg2rad(angles),
143142
center=1286.25,
@@ -150,7 +149,7 @@ def test_FBP_performance_i13_dataset2(i13_dataset2):
150149
assert "performance in ms" == duration_ms
151150

152151

153-
def test_reconstruct_LPREC_i13_dataset2(i13_dataset2):
152+
def test_reconstruct_LPRec3d_tomobar_i13_dataset2(i13_dataset2):
154153
force_clean_gpu_memory()
155154
projdata = i13_dataset2[0]
156155
angles = i13_dataset2[1]
@@ -162,7 +161,7 @@ def test_reconstruct_LPREC_i13_dataset2(i13_dataset2):
162161
del flats, darks, projdata
163162
force_clean_gpu_memory()
164163

165-
recon_data = LPRec(
164+
recon_data = LPRec3d_tomobar(
166165
data=data_normalised,
167166
angles=np.deg2rad(angles),
168167
center=1286.25,
@@ -176,7 +175,7 @@ def test_reconstruct_LPREC_i13_dataset2(i13_dataset2):
176175

177176

178177
@pytest.mark.perf
179-
def test_LPREC_performance_i13_dataset2(i13_dataset2):
178+
def test_LPRec3d_tomobar_performance_i13_dataset2(i13_dataset2):
180179
dev = cp.cuda.Device()
181180
projdata = i13_dataset2[0]
182181
angles = i13_dataset2[1]
@@ -189,7 +188,7 @@ def test_LPREC_performance_i13_dataset2(i13_dataset2):
189188
force_clean_gpu_memory()
190189

191190
# cold run first
192-
LPRec(
191+
LPRec3d_tomobar(
193192
data=data_normalised,
194193
angles=np.deg2rad(angles),
195194
center=1286.25,
@@ -199,7 +198,7 @@ def test_LPREC_performance_i13_dataset2(i13_dataset2):
199198
start = time.perf_counter_ns()
200199
nvtx.RangePush("Core")
201200
for _ in range(10):
202-
LPRec(
201+
LPRec3d_tomobar(
203202
data=data_normalised,
204203
angles=np.deg2rad(angles),
205204
center=1286.25,
@@ -211,7 +210,7 @@ def test_LPREC_performance_i13_dataset2(i13_dataset2):
211210
assert "performance in ms" == duration_ms
212211

213212

214-
def test_reconstruct_FBP_i13_dataset3(i13_dataset3):
213+
def test_reconstruct_FBP3d_tomobar_i13_dataset3(i13_dataset3):
215214
force_clean_gpu_memory()
216215
projdata = i13_dataset3[0]
217216
angles = i13_dataset3[1]
@@ -231,7 +230,7 @@ def test_reconstruct_FBP_i13_dataset3(i13_dataset3):
231230
# GPU archetictures older than 5.3 wont accept the data larger than
232231
# (4096, 4096, 4096), while the newer ones can accept (16384 x 16384 x 16384)
233232

234-
recon_data = FBP(
233+
recon_data = FBP3d_tomobar(
235234
stiched_data_180degrees,
236235
np.deg2rad(angles[0:3000]),
237236
center=2341,

0 commit comments

Comments
 (0)