Skip to content

Commit b96ed32

Browse files
authored
Merge pull request #233 from DiamondLightSource/autopad_fix
fixing autopadding and tests
2 parents 330fae8 + 0141e3b commit b96ed32

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

httomolibgpu/recon/algorithm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,4 +671,6 @@ def _take_neg_log_np(data: np.ndarray) -> np.ndarray:
671671

672672
def __estimate_detectorHoriz_padding(detX_size) -> int:
673673
det_half = detX_size // 2
674-
return int(np.sqrt(2 * (det_half**2)) // 2)
674+
padded_value_exact = int(np.sqrt(2 * (det_half**2))) - det_half
675+
padded_add_margin = int(0.1 * padded_value_exact)
676+
return padded_value_exact + padded_add_margin

tests/test_recon/test_algorithm.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ def test_reconstruct_FBP3d_tomobar_3_detpad_true(
168168
)
169169

170170
recon_data = recon_data.get()
171-
assert_allclose(np.mean(recon_data), -0.00044703347, atol=1e-6)
171+
assert_allclose(np.mean(recon_data), -0.00035695144, atol=1e-6)
172172
assert_allclose(
173-
np.mean(recon_data, axis=(0, 2)).sum(), -0.05722028, rtol=1e-06, atol=1e-5
173+
np.mean(recon_data, axis=(0, 2)).sum(), -0.045689818, rtol=1e-06, atol=1e-5
174174
)
175175
assert recon_data.dtype == np.float32
176176
assert recon_data.shape == (210, 128, 210)
@@ -257,8 +257,8 @@ def test_reconstruct_CGLS3d_tomobar_detpad_true(
257257
)
258258
assert recon_data.flags.c_contiguous
259259
recon_data = recon_data.get()
260-
assert_allclose(np.mean(recon_data), 0.0021116333, rtol=1e-07, atol=1e-6)
261-
assert_allclose(np.mean(recon_data, axis=(0, 2)).sum(), 0.27028912, rtol=1e-03)
260+
assert_allclose(np.mean(recon_data), 0.0021554278, rtol=1e-07, atol=1e-6)
261+
assert_allclose(np.mean(recon_data, axis=(0, 2)).sum(), 0.27589476, rtol=1e-03)
262262
assert recon_data.dtype == np.float32
263263

264264

@@ -306,8 +306,8 @@ def test_reconstruct_FISTA3d_tomobar_pd_tv_detpad_true(
306306
)
307307
assert recon_data.flags.c_contiguous
308308
recon_data = cp.asnumpy(recon_data)
309-
assert_allclose(np.mean(recon_data), 0.0018328167, rtol=1e-07, atol=1e-6)
310-
assert_allclose(np.mean(recon_data, axis=(0, 2)).sum(), 0.23460051, rtol=1e-04)
309+
assert_allclose(np.mean(recon_data), 0.0018338546, rtol=1e-07, atol=1e-6)
310+
assert_allclose(np.mean(recon_data, axis=(0, 2)).sum(), 0.23473345, rtol=1e-04)
311311
assert recon_data.dtype == np.float32
312312

313313

zenodo-tests/test_recon/test_algorithm.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def test_reconstruct_FBP3d_tomobar_i12_dataset1_autopad(i12_dataset1: tuple):
125125
)
126126
assert recon_data.flags.c_contiguous
127127
recon_data = recon_data.get()
128-
assert_allclose(np.sum(recon_data), 7422.912, rtol=1e-07, atol=1e-6)
128+
assert_allclose(np.sum(recon_data), 6669.1274, rtol=1e-07, atol=1e-6)
129129
assert recon_data.dtype == np.float32
130130
assert recon_data.shape == (2560, 5, 2560)
131131

@@ -154,9 +154,9 @@ def test_reconstruct_LPRec3d_tomobar_i12_dataset1(i12_dataset1: tuple):
154154
)
155155
assert recon_data.flags.c_contiguous
156156
recon_data = recon_data.get()
157-
assert isclose(np.sum(recon_data), 9085.442, abs_tol=10**-3)
158-
assert pytest.approx(np.max(recon_data), rel=1e-3) == 0.0063419784
159-
assert pytest.approx(np.min(recon_data), rel=1e-3) == -0.0062314235
157+
assert isclose(np.sum(recon_data), 9628.818, abs_tol=10**-3)
158+
assert pytest.approx(np.max(recon_data), rel=1e-3) == 0.006367563270032406
159+
assert pytest.approx(np.min(recon_data), rel=1e-3) == -0.0062076798
160160
assert recon_data.dtype == np.float32
161161
assert recon_data.shape == (2560, 3, 2560)
162162

@@ -185,9 +185,9 @@ def test_reconstruct_LPRec3d_tomobar_i12_dataset1_autopad(i12_dataset1: tuple):
185185
)
186186
assert recon_data.flags.c_contiguous
187187
recon_data = recon_data.get()
188-
assert int(np.sum(recon_data)) == 8590
189-
assert pytest.approx(np.max(recon_data), rel=1e-3) == 0.006351378
190-
assert pytest.approx(np.min(recon_data), rel=1e-3) == -0.00622256
188+
assert int(np.sum(recon_data)) == 9147
189+
assert pytest.approx(np.max(recon_data), rel=1e-3) == 0.0063818083
190+
assert pytest.approx(np.min(recon_data), rel=1e-3) == -0.006200762
191191
assert recon_data.dtype == np.float32
192192
assert recon_data.shape == (2560, 3, 2560)
193193

@@ -231,7 +231,7 @@ def test_reconstruct_LPRec_tomobar_i13_dataset1(i13_dataset1: tuple):
231231

232232
assert recon_data.flags.c_contiguous
233233
recon_data = recon_data.get()
234-
assert int(np.sum(recon_data)) == 1134
234+
assert int(np.sum(recon_data)) == 1149
235235
assert recon_data.dtype == np.float32
236236
assert recon_data.shape == (4646, 1, 4646)
237237

@@ -300,9 +300,9 @@ def test_reconstruct_LPRec3d_tomobar_i13_dataset2(i13_dataset2: tuple):
300300
)
301301
assert recon_data.flags.c_contiguous
302302
recon_data = recon_data.get()
303-
assert int(np.sum(recon_data)) == 3887
304-
assert pytest.approx(np.max(recon_data), rel=1e-3) == 0.0105562
305-
assert pytest.approx(np.min(recon_data), rel=1e-3) == -0.00835598
303+
assert int(np.sum(recon_data)) == 3448
304+
assert pytest.approx(np.max(recon_data), rel=1e-3) == 0.010543354
305+
assert pytest.approx(np.min(recon_data), rel=1e-3) == -0.008385599
306306
assert recon_data.dtype == np.float32
307307
assert recon_data.shape == (2560, 10, 2560)
308308

@@ -435,7 +435,7 @@ def test_reconstruct_LPRec3d_tomobar_k11_dataset2(k11_dataset2: tuple):
435435
)
436436
assert recon_data.flags.c_contiguous
437437
recon_data = recon_data.get()
438-
assert isclose(np.sum(recon_data), 7689.375, abs_tol=10**-3)
438+
assert isclose(np.sum(recon_data), 10865.34, abs_tol=10**-2)
439439
assert recon_data.dtype == np.float32
440440
assert recon_data.shape == (2560, 25, 2560)
441441

@@ -517,6 +517,6 @@ def test_reconstruct_FISTA3d_tomobar_autopad_k11_dataset2(k11_dataset2: tuple):
517517
)
518518
assert recon_data.flags.c_contiguous
519519
recon_data = recon_data.get()
520-
assert isclose(np.sum(recon_data), 1293.3489, abs_tol=10**-3)
520+
assert isclose(np.sum(recon_data), 1518.5251, abs_tol=10**-3)
521521
assert recon_data.dtype == np.float32
522522
assert recon_data.shape == (2560, 5, 2560)

0 commit comments

Comments
 (0)