Skip to content

Commit 4d7ad21

Browse files
authored
Merge pull request #206 from DiamondLightSource/logpolar
Log-polar method zenodo tests
2 parents 2b32ba7 + c1718e4 commit 4d7ad21

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

httomolibgpu/recon/algorithm.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ def LPRec3d_tomobar(
194194
data: cp.ndarray,
195195
angles: np.ndarray,
196196
center: Optional[float] = None,
197+
filter_type: str = "shepp",
198+
filter_freq_cutoff: float = 1.0,
197199
recon_size: Optional[int] = None,
198200
recon_mask_radius: Optional[float] = 0.95,
199201
neglog: bool = False,
@@ -211,6 +213,10 @@ def LPRec3d_tomobar(
211213
An array of angles given in radians.
212214
center : float, optional
213215
The center of rotation (CoR).
216+
filter_type : str
217+
Filter type, the accepted strings are: none, ramp, shepp, cosine, cosine2, hamming, hann, parzen.
218+
filter_freq_cutoff : float
219+
Cutoff frequency parameter for a filter. The higher values increase the resolution but also amplify the noise.
214220
recon_size : int, optional
215221
The [recon_size, recon_size] shape of the reconstructed slice in pixels.
216222
By default (None), the reconstructed size will be the dimension of the horizontal detector.
@@ -233,6 +239,8 @@ def LPRec3d_tomobar(
233239
_take_neg_log(data) if neglog else data,
234240
recon_mask_radius=recon_mask_radius,
235241
data_axes_labels_order=input_data_axis_labels,
242+
filter_type=filter_type,
243+
cutoff_freq=filter_freq_cutoff,
236244
)
237245
cp._default_memory_pool.free_all_blocks()
238246
return cp.require(cp.swapaxes(reconstruction, 0, 1), requirements="C")

zenodo-tests/test_recon/test_algorithm.py

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import cupy as cp
23
import numpy as np
34
import pytest
@@ -70,7 +71,36 @@ def test_reconstruct_FBP3d_tomobar_i12_dataset1(i12_dataset1):
7071
assert recon_data.shape == (2560, 50, 2560)
7172

7273

73-
def test_reconstruct_LP_REC_i13_dataset1(i13_dataset1):
74+
def test_reconstruct_LPRec3d_tomobar_i12_dataset1(i12_dataset1):
75+
force_clean_gpu_memory()
76+
projdata = i12_dataset1[0]
77+
angles = i12_dataset1[1]
78+
flats = i12_dataset1[2]
79+
darks = i12_dataset1[3]
80+
del i12_dataset1
81+
82+
data_normalised = normalize(projdata, flats, darks, minus_log=True)
83+
data_normalised_cut = data_normalised[:, 5:8, :]
84+
del flats, darks, projdata, data_normalised
85+
force_clean_gpu_memory()
86+
87+
recon_data = LPRec3d_tomobar(
88+
data_normalised_cut,
89+
np.deg2rad(angles),
90+
center=1253.75,
91+
filter_type="shepp",
92+
filter_freq_cutoff=1.0,
93+
)
94+
assert recon_data.flags.c_contiguous
95+
recon_data = recon_data.get()
96+
assert isclose(np.sum(recon_data), 8973.755, abs_tol=10**-3)
97+
assert pytest.approx(np.max(recon_data), rel=1e-3) == 0.00640
98+
assert pytest.approx(np.min(recon_data), rel=1e-3) == -0.00617
99+
assert recon_data.dtype == np.float32
100+
assert recon_data.shape == (2560, 3, 2560)
101+
102+
103+
def test_reconstruct_LPRec_tomobar_i13_dataset1(i13_dataset1):
74104
force_clean_gpu_memory()
75105
projdata = i13_dataset1[0]
76106
angles = i13_dataset1[1]
@@ -101,11 +131,15 @@ def test_reconstruct_LP_REC_i13_dataset1(i13_dataset1):
101131
data=stiched_data_180degrees,
102132
angles=np.deg2rad(angles[0:3000]),
103133
center=2322.08,
134+
filter_type="shepp",
135+
filter_freq_cutoff=1.0,
104136
)
105137

106138
assert recon_data.flags.c_contiguous
107139
recon_data = recon_data.get()
108-
assert isclose(np.sum(recon_data), 620.856, abs_tol=10**-3)
140+
assert isclose(np.sum(recon_data), 1241.859, abs_tol=10**-3)
141+
assert pytest.approx(np.max(recon_data), rel=1e-3) == 0.00823
142+
assert pytest.approx(np.min(recon_data), rel=1e-3) == -0.00656
109143
assert recon_data.dtype == np.float32
110144
assert recon_data.shape == (4646, 1, 4646)
111145

@@ -165,11 +199,15 @@ def test_reconstruct_LPRec3d_tomobar_i13_dataset2(i13_dataset2):
165199
data=data_normalised,
166200
angles=np.deg2rad(angles),
167201
center=1286.25,
202+
filter_type="shepp",
203+
filter_freq_cutoff=1.0,
168204
)
169205
assert recon_data.flags.c_contiguous
170206
recon_data = recon_data.get()
171207

172-
assert isclose(np.sum(recon_data), 2044.953, abs_tol=10**-3)
208+
assert isclose(np.sum(recon_data), 4095.6257, abs_tol=10**-3)
209+
assert pytest.approx(np.max(recon_data), rel=1e-3) == 0.0105672
210+
assert pytest.approx(np.min(recon_data), rel=1e-3) == -0.00839
173211
assert recon_data.dtype == np.float32
174212
assert recon_data.shape == (2560, 10, 2560)
175213

0 commit comments

Comments
 (0)