Skip to content

Commit 106f098

Browse files
committed
Update estimator to cover bigger angle ranges
With an extra 10% added to cover small inaccuracies
1 parent fe01120 commit 106f098

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

httomo_backends/methods_database/packages/backends/httomolibgpu/supporting_funcs/recon/algorithm.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def _calc_memory_bytes_LPRec3d_tomobar(
165165
dtype: np.dtype,
166166
**kwargs,
167167
) -> Tuple[int, int]:
168-
# Based on: https://github.com/neon60/ToMoBAR/commit/fe95670d2b02edb4036be0e10f38967976af94d5
168+
# Based on: https://github.com/dkazanc/ToMoBAR/pull/112/commits/4704ecdc6ded3dd5ec0583c2008aa104f30a8a39
169169

170170
angles_tot = non_slice_dims_shape[0]
171171
DetectorsLengthH = non_slice_dims_shape[1]
@@ -189,20 +189,25 @@ def _calc_memory_bytes_LPRec3d_tomobar(
189189
ne = oversampling_level * n
190190
padding_m = ne // 2 - n // 2
191191

192+
angles = kwargs["angles"]
193+
sorted_theta_cpu = np.sort(angles)
194+
theta_full_range = abs(sorted_theta_cpu[angles_tot-1] - sorted_theta_cpu[0])
195+
angle_range_pi_count = 1 + int(np.ceil(theta_full_range / math.pi))
196+
192197
output_dims = __calc_output_dim_recon(non_slice_dims_shape, **kwargs)
193198
if odd_horiz:
194199
output_dims = tuple(x + 1 for x in output_dims)
195200

196201
in_slice_size = np.prod(non_slice_dims_shape) * dtype.itemsize
197202
padded_in_slice_size = np.prod(non_slice_dims_shape) * np.float32().itemsize
198203
theta_size = angles_tot * np.float32().itemsize
199-
sorted_theta_indices_size = angles_tot * np.int32().itemsize
204+
sorted_theta_indices_size = angles_tot * np.int64().itemsize
200205
sorted_theta_size = angles_tot * np.float32().itemsize
201206
recon_output_size = (n + 1) * (n + 1) * np.float32().itemsize if odd_horiz else n * n * np.float32().itemsize # 264
202207
linspace_size = n * np.float32().itemsize
203208
meshgrid_size = 2 * n * n * np.float32().itemsize
204209
phi_size = 6 * n * n * np.float32().itemsize
205-
angle_range_size = center_size * center_size * 3 * np.int32().itemsize
210+
angle_range_size = center_size * center_size * 1 + angle_range_pi_count * 2 * np.int32().itemsize
206211
c1dfftshift_size = n * np.int8().itemsize
207212
c2dfftshift_slice_size = 4 * n * n * np.int8().itemsize
208213
filter_size = (n // 2 + 1) * np.float32().itemsize
@@ -253,7 +258,7 @@ def _calc_memory_bytes_LPRec3d_tomobar(
253258
)
254259
)
255260

256-
return (tot_memory_bytes, fixed_amount)
261+
return (tot_memory_bytes * 1.1, fixed_amount)
257262

258263

259264

tests/test_httomolibgpu.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,14 +576,24 @@ def test_recon_FBP3d_tomobar_memoryhook(
576576
@pytest.mark.cupy
577577
@pytest.mark.parametrize("projections", [1801, 2560, 3601])
578578
@pytest.mark.parametrize("slices", [3, 4, 5, 10, 15, 20])
579-
def test_recon_LPRec3d_tomobar_memoryhook(slices, projections, ensure_clean_memory):
579+
@pytest.mark.parametrize("projection_angle_range", [(0, np.pi)])
580+
def test_recon_LPRec3d_tomobar_memoryhook(slices, projections, projection_angle_range, ensure_clean_memory):
581+
__test_recon_LPRec3d_tomobar_memoryhook_common(slices, projections, projection_angle_range, ensure_clean_memory)
582+
583+
@pytest.mark.full
584+
@pytest.mark.cupy
585+
@pytest.mark.parametrize("projections", [1801, 2560, 3601])
586+
@pytest.mark.parametrize("slices", [3, 4, 5, 10, 15, 20])
587+
@pytest.mark.parametrize("projection_angle_range", [(0, np.pi), (0, 2 * np.pi), (-np.pi / 2, np.pi / 2)])
588+
def test_recon_LPRec3d_tomobar_memoryhook_full(slices, projections, projection_angle_range, ensure_clean_memory):
589+
__test_recon_LPRec3d_tomobar_memoryhook_common(slices, projections, projection_angle_range, ensure_clean_memory)
590+
591+
def __test_recon_LPRec3d_tomobar_memoryhook_common(slices, projections, projection_angle_range, ensure_clean_memory):
580592
angles_number = projections
581593
detX_size = 2560
582594
data = cp.random.random_sample((angles_number, slices, detX_size), dtype=np.float32)
583595
kwargs = {}
584-
kwargs["angles"] = np.linspace(
585-
0.0 * np.pi / 180.0, 180.0 * np.pi / 180.0, data.shape[0]
586-
)
596+
kwargs["angles"] = np.linspace(projection_angle_range[0], projection_angle_range[1], data.shape[0])
587597
kwargs["center"] = 1280
588598
kwargs["recon_size"] = detX_size
589599
kwargs["recon_mask_radius"] = 0.8

0 commit comments

Comments
 (0)