Skip to content

Commit fede622

Browse files
committed
corrections to tests, new tests on zenodo
1 parent 2620c9a commit fede622

File tree

6 files changed

+310
-61
lines changed

6 files changed

+310
-61
lines changed

.scripts/download_zenodo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ def calculate_md5(filename):
1818

1919
def download_zenodo_files(output_dir: Path):
2020
"""
21-
Download all files from Zenodo record 14938787 and verify their checksums.
21+
Download all files from Zenodo record 17252190 and verify their checksums.
2222
2323
Args:
2424
output_dir: Directory where files should be downloaded
2525
"""
2626
try:
27-
print("Fetching files from Zenodo record 14938787...")
27+
print("Fetching files from Zenodo record 17252190...")
2828
with urllib.request.urlopen(
29-
"https://zenodo.org/api/records/14938787"
29+
"https://zenodo.org/api/records/17252190"
3030
) as response:
3131
data = json.loads(response.read())
3232

httomolibgpu/misc/supp_func.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def data_checker(
159159
data: cp.ndarray,
160160
verbosity: bool = True,
161161
method_name: Optional[str] = None,
162-
) -> bool:
162+
) -> cp.ndarray:
163163
"""
164164
Function that performs the variety of checks on input data, in some cases also correct the data and prints warnings.
165165
Currently it checks for: the presence of infs and nans in data.

httomolibgpu/recon/algorithm.py

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
RecToolsDIRCuPy = Mock()
3838
RecToolsIRCuPy = Mock()
3939

40-
from numpy import float32, complex64
41-
from typing import Optional, Type
40+
from numpy import float32
41+
from typing import Optional, Type, Union
4242

4343
from httomolibgpu.misc.supp_func import data_checker
4444

@@ -60,7 +60,7 @@ def FBP2d_astra(
6060
data: np.ndarray,
6161
angles: np.ndarray,
6262
center: Optional[float] = None,
63-
detector_pad: int = 0,
63+
detector_pad: Union[bool, int] = False,
6464
filter_type: str = "ram-lak",
6565
filter_parameter: Optional[float] = None,
6666
filter_d: Optional[float] = None,
@@ -82,8 +82,9 @@ def FBP2d_astra(
8282
An array of angles given in radians.
8383
center : float, optional
8484
The center of rotation (CoR).
85-
detector_pad : int
86-
Detector width padding with edge values to remove circle/arc type artifacts in the reconstruction.
85+
detector_pad : bool, int
86+
Detector width padding with edge values to remove circle/arc type artifacts in the reconstruction. Set to True to perform
87+
an automated padding or specify a certain value as an integer.
8788
filter_type: str
8889
Type of projection filter, see ASTRA's API for all available options for filters.
8990
filter_parameter: float, optional
@@ -120,7 +121,7 @@ def FBP2d_astra(
120121

121122
detY_size = data_shape[1]
122123
reconstruction = np.empty(
123-
(recon_size, detY_size, recon_size), dtype=np.float32(), order="C"
124+
(recon_size, detY_size, recon_size), dtype=float32, order="C"
124125
)
125126
_take_neg_log_np(data) if neglog else data
126127

@@ -143,7 +144,7 @@ def FBP3d_tomobar(
143144
data: cp.ndarray,
144145
angles: np.ndarray,
145146
center: Optional[float] = None,
146-
detector_pad: int = 0,
147+
detector_pad: Union[bool, int] = False,
147148
filter_freq_cutoff: float = 0.35,
148149
recon_size: Optional[int] = None,
149150
recon_mask_radius: Optional[float] = 0.95,
@@ -164,8 +165,9 @@ def FBP3d_tomobar(
164165
An array of angles given in radians.
165166
center : float, optional
166167
The center of rotation (CoR).
167-
detector_pad : int
168-
Detector width padding with edge values to remove circle/arc type artifacts in the reconstruction.
168+
detector_pad : bool, int
169+
Detector width padding with edge values to remove circle/arc type artifacts in the reconstruction. Set to True to perform
170+
an automated padding or specify a certain value as an integer.
169171
filter_freq_cutoff : float
170172
Cutoff frequency parameter for the SINC filter, the lower values may produce better contrast but noisy reconstruction. The filter change will also affect the dynamic range of the reconstructed image.
171173
recon_size : int, optional
@@ -207,7 +209,7 @@ def LPRec3d_tomobar(
207209
data: cp.ndarray,
208210
angles: np.ndarray,
209211
center: Optional[float] = None,
210-
detector_pad: int = 0,
212+
detector_pad: Union[bool, int] = False,
211213
filter_type: str = "shepp",
212214
filter_freq_cutoff: float = 1.0,
213215
recon_size: Optional[int] = None,
@@ -227,8 +229,9 @@ def LPRec3d_tomobar(
227229
An array of angles given in radians.
228230
center : float, optional
229231
The center of rotation (CoR).
230-
detector_pad : int
231-
Detector width padding with edge values to remove circle/arc type artifacts in the reconstruction.
232+
detector_pad : bool, int
233+
Detector width padding with edge values to remove circle/arc type artifacts in the reconstruction. Set to True to perform
234+
an automated padding or specify a certain value as an integer.
232235
filter_type : str
233236
Filter type, the accepted strings are: none, ramp, shepp, cosine, cosine2, hamming, hann, parzen.
234237
filter_freq_cutoff : float
@@ -272,7 +275,7 @@ def SIRT3d_tomobar(
272275
data: cp.ndarray,
273276
angles: np.ndarray,
274277
center: Optional[float] = None,
275-
detector_pad: int = 0,
278+
detector_pad: Union[bool, int] = False,
276279
recon_size: Optional[int] = None,
277280
recon_mask_radius: float = 0.95,
278281
iterations: int = 300,
@@ -294,8 +297,9 @@ def SIRT3d_tomobar(
294297
An array of angles given in radians.
295298
center : float, optional
296299
The center of rotation (CoR).
297-
detector_pad : int
298-
Detector width padding with edge values to remove circle/arc type artifacts in the reconstruction.
300+
detector_pad : bool, int
301+
Detector width padding with edge values to remove circle/arc type artifacts in the reconstruction. Set to True to perform
302+
an automated padding or specify a certain value as an integer.
299303
recon_size : int, optional
300304
The [recon_size, recon_size] shape of the reconstructed slice in pixels.
301305
By default (None), the reconstructed size will be the dimension of the horizontal detector.
@@ -349,7 +353,7 @@ def CGLS3d_tomobar(
349353
data: cp.ndarray,
350354
angles: np.ndarray,
351355
center: Optional[float] = None,
352-
detector_pad: int = 0,
356+
detector_pad: Union[bool, int] = False,
353357
recon_size: Optional[int] = None,
354358
recon_mask_radius: float = 0.95,
355359
iterations: int = 20,
@@ -371,8 +375,9 @@ def CGLS3d_tomobar(
371375
An array of angles given in radians.
372376
center : float, optional
373377
The center of rotation (CoR).
374-
detector_pad : int
375-
Detector width padding with edge values to remove circle/arc type artifacts in the reconstruction.
378+
detector_pad : bool, int
379+
Detector width padding with edge values to remove circle/arc type artifacts in the reconstruction. Set to True to perform
380+
an automated padding or specify a certain value as an integer.
376381
recon_size : int, optional
377382
The [recon_size, recon_size] shape of the reconstructed slice in pixels.
378383
By default (None), the reconstructed size will be the dimension of the horizontal detector.
@@ -420,7 +425,7 @@ def FISTA3d_tomobar(
420425
data: cp.ndarray,
421426
angles: np.ndarray,
422427
center: Optional[float] = None,
423-
detector_pad: int = 0,
428+
detector_pad: Union[bool, int] = False,
424429
recon_size: Optional[int] = None,
425430
recon_mask_radius: float = 0.95,
426431
iterations: int = 20,
@@ -445,8 +450,9 @@ def FISTA3d_tomobar(
445450
An array of angles given in radians.
446451
center : float, optional
447452
The center of rotation (CoR).
448-
detector_pad : int
449-
Detector width padding with edge values to remove circle/arc type artifacts in the reconstruction.
453+
detector_pad : bool, int
454+
Detector width padding with edge values to remove circle/arc type artifacts in the reconstruction. Set to True to perform
455+
an automated padding or specify a certain value as an integer.
450456
recon_size : int, optional
451457
The [recon_size, recon_size] shape of the reconstructed slice in pixels.
452458
By default (None), the reconstructed size will be the dimension of the horizontal detector.
@@ -516,7 +522,7 @@ def _instantiate_direct_recon_class(
516522
data: cp.ndarray,
517523
angles: np.ndarray,
518524
center: Optional[float] = None,
519-
detector_pad: int = 0,
525+
detector_pad: Union[bool, int] = False,
520526
recon_size: Optional[int] = None,
521527
gpu_id: int = 0,
522528
) -> Type:
@@ -526,7 +532,7 @@ def _instantiate_direct_recon_class(
526532
data (cp.ndarray): data array
527533
angles (np.ndarray): angles
528534
center (Optional[float], optional): center of recon. Defaults to None.
529-
detector_pad (int): Detector width padding. Defaults to 0.
535+
detector_pad : (Union[bool, int]) : Detector width padding. Defaults to False.
530536
recon_size (Optional[int], optional): recon_size. Defaults to None.
531537
gpu_id (int, optional): gpu ID. Defaults to 0.
532538
@@ -537,6 +543,10 @@ def _instantiate_direct_recon_class(
537543
center = data.shape[2] // 2 # making a crude guess
538544
if recon_size is None:
539545
recon_size = data.shape[2]
546+
if detector_pad is True:
547+
detector_pad = __estimate_detectorHoriz_padding(data.shape[2])
548+
elif detector_pad is False:
549+
detector_pad = 0
540550
RecToolsCP = RecToolsDIRCuPy(
541551
DetectorsDimH=data.shape[2], # Horizontal detector dimension
542552
DetectorsDimH_pad=detector_pad, # padding for horizontal detector
@@ -556,7 +566,7 @@ def _instantiate_direct_recon2d_class(
556566
data: np.ndarray,
557567
angles: np.ndarray,
558568
center: Optional[float] = None,
559-
detector_pad: int = 0,
569+
detector_pad: Union[bool, int] = False,
560570
recon_size: Optional[int] = None,
561571
gpu_id: int = 0,
562572
) -> Type:
@@ -566,7 +576,7 @@ def _instantiate_direct_recon2d_class(
566576
data (cp.ndarray): data array
567577
angles (np.ndarray): angles
568578
center (Optional[float], optional): center of recon. Defaults to None.
569-
detector_pad (int): Detector width padding. Defaults to 0.
579+
detector_pad : (Union[bool, int]) : Detector width padding. Defaults to False.
570580
recon_size (Optional[int], optional): recon_size. Defaults to None.
571581
gpu_id (int, optional): gpu ID. Defaults to 0.
572582
@@ -577,6 +587,10 @@ def _instantiate_direct_recon2d_class(
577587
center = data.shape[2] // 2 # making a crude guess
578588
if recon_size is None:
579589
recon_size = data.shape[2]
590+
if detector_pad is True:
591+
detector_pad = __estimate_detectorHoriz_padding(data.shape[2])
592+
elif detector_pad is False:
593+
detector_pad = 0
580594
RecTools = RecToolsDIR(
581595
DetectorsDimH=data.shape[2], # Horizontal detector dimension
582596
DetectorsDimH_pad=detector_pad, # padding for horizontal detector
@@ -595,7 +609,7 @@ def _instantiate_iterative_recon_class(
595609
data: cp.ndarray,
596610
angles: np.ndarray,
597611
center: Optional[float] = None,
598-
detector_pad: int = 0,
612+
detector_pad: Union[bool, int] = False,
599613
recon_size: Optional[int] = None,
600614
gpu_id: int = 0,
601615
datafidelity: str = "LS",
@@ -606,7 +620,7 @@ def _instantiate_iterative_recon_class(
606620
data (cp.ndarray): data array
607621
angles (np.ndarray): angles
608622
center (Optional[float], optional): center of recon. Defaults to None.
609-
detector_pad (int): Detector width padding. Defaults to 0.
623+
detector_pad : (Union[bool, int]) : Detector width padding. Defaults to False.
610624
recon_size (Optional[int], optional): recon_size. Defaults to None.
611625
datafidelity (str, optional): Data fidelity
612626
gpu_id (int, optional): gpu ID. Defaults to 0.
@@ -618,6 +632,10 @@ def _instantiate_iterative_recon_class(
618632
center = data.shape[2] // 2 # making a crude guess
619633
if recon_size is None:
620634
recon_size = data.shape[2]
635+
if detector_pad is True:
636+
detector_pad = __estimate_detectorHoriz_padding(data.shape[2])
637+
elif detector_pad is False:
638+
detector_pad = 0
621639
RecToolsCP = RecToolsIRCuPy(
622640
DetectorsDimH=data.shape[2], # Horizontal detector dimension
623641
DetectorsDimH_pad=detector_pad, # padding for horizontal detector
@@ -649,3 +667,8 @@ def _take_neg_log_np(data: np.ndarray) -> np.ndarray:
649667
data[np.isnan(data)] = 6.0
650668
data[np.isinf(data)] = 0
651669
return data
670+
671+
672+
def __estimate_detectorHoriz_padding(detX_size) -> int:
673+
det_half = detX_size // 2
674+
return int(np.sqrt(2 * (det_half**2)) // 2)

0 commit comments

Comments
 (0)