Skip to content

Commit 232384d

Browse files
committed
updates to tests and functions using new data checker
1 parent 79c4e1d commit 232384d

File tree

9 files changed

+130
-225
lines changed

9 files changed

+130
-225
lines changed

httomolibgpu/misc/corr.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"remove_outlier",
4242
]
4343

44+
4445
def median_filter(
4546
data: cp.ndarray,
4647
kernel_size: int = 3,

httomolibgpu/misc/morph.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"data_resampler",
4141
]
4242

43+
4344
def sino_360_to_180(
4445
data: cp.ndarray, overlap: float = 0, side: Literal["left", "right"] = "left"
4546
) -> cp.ndarray:

httomolibgpu/misc/utils.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@
3939
]
4040

4141

42-
def data_checker(data: cp.ndarray, infsnans_correct: bool= True, zeros_warning: bool = False, data_to_method_name: Optional[str] = None, verbosity: bool = True) -> cp.ndarray:
42+
def data_checker(
43+
data: cp.ndarray,
44+
infsnans_correct: bool = True,
45+
zeros_warning: bool = False,
46+
data_to_method_name: Optional[str] = None,
47+
verbosity: bool = True,
48+
) -> cp.ndarray:
4349
"""Function that performs checks on input data to ensure its validity, performs corrections and prints the warnings.
4450
Currently it checks for the presence of Infs and NaNs in the data and corrects them.
4551
@@ -54,7 +60,7 @@ def data_checker(data: cp.ndarray, infsnans_correct: bool= True, zeros_warning:
5460
verbosity : bool
5561
Print the warnings.
5662
data_to_method_name : str, optional.
57-
Method's name for which the tested data is intended. This is for printing purposes when the method runs in HTTomo.
63+
Method's name the output of which is tested. This is tailored for printing purposes when the method runs in HTTomo.
5864
5965
Returns
6066
-------
@@ -67,11 +73,12 @@ def data_checker(data: cp.ndarray, infsnans_correct: bool= True, zeros_warning:
6773
)
6874

6975
if infsnans_correct:
70-
data = __naninfs_check(data, verbosity=verbosity, method_name=data_to_method_name)\
71-
76+
data = __naninfs_check(
77+
data, verbosity=verbosity, method_name=data_to_method_name
78+
)
7279
# TODO
7380
# if zeros_warning:
74-
#__zeros_check(data, verbosity=verbosity, percentage_threshold = 50, method_name=data_to_method_name)
81+
# __zeros_check(data, verbosity=verbosity, percentage_threshold = 50, method_name=data_to_method_name)
7582

7683
return data
7784

@@ -91,7 +98,7 @@ def __naninfs_check(
9198
verbosity : bool
9299
If enabled, then the printing of the warning happens when data contains infs or nans
93100
method_name : str, optional.
94-
Method's name for which input data is tested.
101+
Method's name for which the output data is tested.
95102
96103
Returns
97104
-------
@@ -132,8 +139,8 @@ def __naninfs_check(
132139
if present_nans_infs_b:
133140
if verbosity:
134141
print(
135-
f"Warning!!! Input data to method: {method_name} contains Inf's or/and NaN's. This will be corrected but it is recommended to check the validity of input to the method."
142+
"Warning! Output data of the \033[31m{}\033[0m method contains Inf's or/and NaN's. Corrected to zeros.".format(
143+
method_name
144+
)
136145
)
137-
138146
return data
139-

httomolibgpu/prep/stripe.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ def raven_filter(
386386
if data.dtype != cp.float32:
387387
raise ValueError("The input data should be float32 data type")
388388

389-
390389
# Padding of the sinogram
391390
data = cp.pad(data, ((pad_y, pad_y), (0, 0), (pad_x, pad_x)), mode=pad_method)
392391

httomolibgpu/recon/rotation.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ def find_center_vo(
110110
data = cp.expand_dims(data, 1)
111111
ind = 0
112112

113-
data = data_checker(data, infsnans_correct=True, zeros_warning = False, data_to_method_name="find_center_vo")
113+
data = data_checker(
114+
data,
115+
infsnans_correct=True,
116+
zeros_warning=False,
117+
data_to_method_name="find_center_vo",
118+
)
114119

115120
angles_tot, detY_size, detX_size = data.shape
116121

@@ -459,7 +464,12 @@ def find_center_360(
459464
if data.ndim != 3:
460465
raise ValueError("A 3D array must be provided")
461466

462-
data = data_checker(data, infsnans_correct=True, zeros_warning = False, data_to_method_name="find_center_360")
467+
data = data_checker(
468+
data,
469+
infsnans_correct=True,
470+
zeros_warning=False,
471+
data_to_method_name="find_center_360",
472+
)
463473

464474
# this method works with a 360-degree sinogram.
465475
if ind is None:
@@ -740,6 +750,7 @@ def _calculate_curvature(list_metric):
740750

741751
return curvature, np.float32(min_pos)
742752

753+
743754
## %%%%%%%%%%%%%%%%%%%%%%find_center_pc%%%%%%%%%%%%%%%%%%%%%%%%%%%%
744755
def find_center_pc(
745756
proj1: cp.ndarray,
@@ -771,8 +782,18 @@ def find_center_pc(
771782
np.float32
772783
Rotation axis location.
773784
"""
774-
proj1 = data_checker(proj1, infsnans_correct=True, zeros_warning = False, data_to_method_name="find_center_pc")
775-
proj2 = data_checker(proj2, infsnans_correct=True, zeros_warning = False, data_to_method_name="find_center_pc")
785+
proj1 = data_checker(
786+
proj1,
787+
infsnans_correct=True,
788+
zeros_warning=False,
789+
data_to_method_name="find_center_pc",
790+
)
791+
proj2 = data_checker(
792+
proj2,
793+
infsnans_correct=True,
794+
zeros_warning=False,
795+
data_to_method_name="find_center_pc",
796+
)
776797

777798
imgshift = 0.0 if rotc_guess is None else rotc_guess - (proj1.shape[1] - 1.0) / 2.0
778799

tests/test_misc/test_supp_func.py

Lines changed: 0 additions & 205 deletions
This file was deleted.

0 commit comments

Comments
 (0)