httomolibgpu 3.1.1__py3-none-any.whl → 5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,7 +32,7 @@ from unittest.mock import Mock
32
32
  if cupy_run:
33
33
  from httomolibgpu.cuda_kernels import load_cuda_module
34
34
  from cupyx.scipy.ndimage import shift, gaussian_filter
35
- from skimage.registration import phase_cross_correlation
35
+ from ._phase_cross_correlation import phase_cross_correlation
36
36
  from cupyx.scipy.fftpack import get_fft_plan
37
37
  from cupyx.scipy.fft import fft2, fftshift
38
38
  else:
@@ -49,7 +49,7 @@ else:
49
49
  import math
50
50
  from typing import List, Literal, Optional, Tuple, Union
51
51
 
52
- from httomolibgpu.misc.supp_func import data_checker
52
+ from httomolibgpu.misc.utils import data_checker
53
53
 
54
54
  __all__ = [
55
55
  "find_center_vo",
@@ -110,7 +110,12 @@ def find_center_vo(
110
110
  data = cp.expand_dims(data, 1)
111
111
  ind = 0
112
112
 
113
- data = data_checker(data, verbosity=True, 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
+ )
114
119
 
115
120
  angles_tot, detY_size, detX_size = data.shape
116
121
 
@@ -459,7 +464,12 @@ def find_center_360(
459
464
  if data.ndim != 3:
460
465
  raise ValueError("A 3D array must be provided")
461
466
 
462
- data = data_checker(data, verbosity=True, 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
+ )
463
473
 
464
474
  # this method works with a 360-degree sinogram.
465
475
  if ind is None:
@@ -741,9 +751,6 @@ def _calculate_curvature(list_metric):
741
751
  return curvature, np.float32(min_pos)
742
752
 
743
753
 
744
- # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
745
-
746
-
747
754
  ## %%%%%%%%%%%%%%%%%%%%%%find_center_pc%%%%%%%%%%%%%%%%%%%%%%%%%%%%
748
755
  def find_center_pc(
749
756
  proj1: cp.ndarray,
@@ -775,9 +782,18 @@ def find_center_pc(
775
782
  np.float32
776
783
  Rotation axis location.
777
784
  """
778
-
779
- proj1 = data_checker(proj1, verbosity=True, method_name="find_center_pc")
780
- proj2 = data_checker(proj2, verbosity=True, 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
+ )
781
797
 
782
798
  imgshift = 0.0 if rotc_guess is None else rotc_guess - (proj1.shape[1] - 1.0) / 2.0
783
799
 
@@ -789,7 +805,7 @@ def find_center_pc(
789
805
 
790
806
  # do phase cross correlation between two images
791
807
  shiftr = phase_cross_correlation(
792
- reference_image=proj1.get(), moving_image=proj2.get(), upsample_factor=1.0 / tol
808
+ reference_image=proj1, moving_image=proj2, upsample_factor=1.0 / tol
793
809
  )
794
810
 
795
811
  # Compute center of rotation as the center of first image and the
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: httomolibgpu
3
- Version: 3.1.1
3
+ Version: 5.0
4
4
  Summary: Commonly used tomography data processing methods at DLS.
5
5
  Author-email: Daniil Kazantsev <daniil.kazantsev@diamond.ac.uk>, Yousef Moazzam <yousef.moazzam@diamond.ac.uk>, Naman Gera <naman.gera@diamond.ac.uk>
6
6
  License: BSD-3-Clause
@@ -0,0 +1,29 @@
1
+ httomolibgpu/__init__.py,sha256=Fdj5ipIGgeKqSCYRb5bBVMAZ04ZvZJzuBoGOAqc0zgk,937
2
+ httomolibgpu/cupywrapper.py,sha256=6ITGJ2Jw5I5kVmKEL5LlsnLRniEqqBLsHiAjvLtk0Xk,493
3
+ httomolibgpu/cuda_kernels/__init__.py,sha256=VQNMaGcVDwiE-C64FfLtubHpLriLG0Y3_QnjHBSHrN0,884
4
+ httomolibgpu/cuda_kernels/calc_metrics.cu,sha256=oV7ZPcwjWafmZjbNsUkBYPvOViJ_nX3zBoOAuPCmIrA,11335
5
+ httomolibgpu/cuda_kernels/center_360_shifts.cu,sha256=Ya_8hxjXGtPBsPY3qfGJaugwnYrTFjFFretRcLiUfFQ,1631
6
+ httomolibgpu/cuda_kernels/generate_mask.cu,sha256=3il3r1J2cnTCd3UXO4GWGfBgGxj4pvrZnXviW_SXpO0,2650
7
+ httomolibgpu/cuda_kernels/median_kernel.cu,sha256=EECLUCoJkT9GQ9Db_FF6fYOG6cDSiAePTRZNxE4VZ68,1692
8
+ httomolibgpu/cuda_kernels/raven_filter.cu,sha256=KX2TM_9tMpvoGCHezDNWYABCnv2cT9mlMo4IhxRUac0,1437
9
+ httomolibgpu/cuda_kernels/remove_nan_inf.cu,sha256=gv0ihkf6A_D_po9x7pmgFsQFhwZ1dB_HYc_0Tu-bpUU,630
10
+ httomolibgpu/misc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ httomolibgpu/misc/corr.py,sha256=e1eUsWLSM9SB5xzWTDW0o9pAD_lbrr4DL-QQmyM8v4c,4503
12
+ httomolibgpu/misc/denoise.py,sha256=-D9UPbZyUAcCptBHUUXsmj1NFzd6HrrRjJJh4T5gmhQ,4787
13
+ httomolibgpu/misc/morph.py,sha256=T_JxZE6xulB3FwvFH0iqF26pJmBJoln_sGuvOoRGAHQ,7266
14
+ httomolibgpu/misc/rescale.py,sha256=8MwTd68tF8HTMk4qbCYgcaBsRV7wOxlrbFPAjUcx0zs,4285
15
+ httomolibgpu/misc/utils.py,sha256=rHRuQUO47SlTanvKDBgiC0im4tXlGLCw5B_zvlLzzbc,4736
16
+ httomolibgpu/prep/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
+ httomolibgpu/prep/alignment.py,sha256=GVxnyioipmqsHb4s3mPQ8tKGoPIQMPftDrQxUO-HBuE,5491
18
+ httomolibgpu/prep/normalize.py,sha256=hee0H4mE7FrSZgcF1fjLsKT06xjTJymkyAxpe2itQe4,4202
19
+ httomolibgpu/prep/phase.py,sha256=eDi4Y2dZ0ZDgblCku1XhHiSuK6rHnmsDFuZdDvlnHMU,8505
20
+ httomolibgpu/prep/stripe.py,sha256=8_DV0ON6AWARuziqkmhom56gWTardtqC_z3xG8geg0o,14774
21
+ httomolibgpu/recon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
+ httomolibgpu/recon/_phase_cross_correlation.py,sha256=h5r1g5lMmS9p32k2SuC8pjji6McpwBZiN95zQd2xvBo,16616
23
+ httomolibgpu/recon/algorithm.py,sha256=ds-_io7kGzo5FiJq8k4--PYtIWak3y9H7yuyg1lymyQ,25121
24
+ httomolibgpu/recon/rotation.py,sha256=GaSwNrlDnlP_iIrTfKUQLiXsShJ5aSDvdKPwofggtwQ,27948
25
+ httomolibgpu-5.0.dist-info/licenses/LICENSE,sha256=bXeLsgelPUUXw8HCIYiVC97Dpjhm2nB54m7TACdH8ng,48032
26
+ httomolibgpu-5.0.dist-info/METADATA,sha256=0_lrMXVwbSoLpLzIx_i24kCU7VWAMkXFaBaT6rQ0O-c,3339
27
+ httomolibgpu-5.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
28
+ httomolibgpu-5.0.dist-info/top_level.txt,sha256=nV0Ty_YvSPVd1O6MNWuIplD0w1nwk5hT76YgBZ-bzUw,13
29
+ httomolibgpu-5.0.dist-info/RECORD,,
@@ -1,192 +0,0 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- # ---------------------------------------------------------------------------
4
- # Copyright 2022 Diamond Light Source Ltd.
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- # ---------------------------------------------------------------------------
18
- # Created By : Tomography Team at DLS <scientificsoftware@diamond.ac.uk>
19
- # Created Date: 02/June/2025
20
- # ---------------------------------------------------------------------------
21
- """This is a collection of supplementary functions (utils) to perform various data checks"""
22
-
23
- from httomolibgpu import cupywrapper
24
- from typing import Optional
25
-
26
- cp = cupywrapper.cp
27
- cupy_run = cupywrapper.cupy_run
28
-
29
- import numpy as np
30
-
31
- from unittest.mock import Mock
32
-
33
- if cupy_run:
34
- from httomolibgpu.cuda_kernels import load_cuda_module
35
- else:
36
- load_cuda_module = Mock()
37
-
38
-
39
- def _naninfs_check(
40
- data: cp.ndarray,
41
- verbosity: bool = True,
42
- method_name: Optional[str] = None,
43
- ) -> cp.ndarray:
44
- """
45
- This function finds NaN's, +-Inf's in the input data and then prints the warnings and correct the data if correction is enabled.
46
-
47
- Parameters
48
- ----------
49
- data : cp.ndarray
50
- Input CuPy or Numpy array either float32 or uint16 data type.
51
- verbosity : bool
52
- If enabled, then the printing of the warning happens when data contains infs or nans
53
- method_name : str, optional.
54
- Method's name for which input data is tested.
55
-
56
- Returns
57
- -------
58
- ndarray
59
- Uncorrected or corrected (nans and infs converted to zeros) input array.
60
- """
61
- present_nans_infs_b = False
62
-
63
- if cupy_run:
64
- xp = cp.get_array_module(data)
65
- else:
66
- import numpy as xp
67
-
68
- if xp.__name__ == "cupy":
69
- input_type = data.dtype
70
- if len(data.shape) == 2:
71
- dy, dx = data.shape
72
- dz = 1
73
- else:
74
- dz, dy, dx = data.shape
75
-
76
- present_nans_infs = cp.zeros(shape=(1)).astype(cp.uint8)
77
-
78
- block_x = 128
79
- # setting grid/block parameters
80
- block_dims = (block_x, 1, 1)
81
- grid_x = (dx + block_x - 1) // block_x
82
- grid_y = dy
83
- grid_z = dz
84
- grid_dims = (grid_x, grid_y, grid_z)
85
- params = (data, dz, dy, dx, present_nans_infs)
86
-
87
- kernel_args = "remove_nan_inf<{0}>".format(
88
- "float" if input_type == "float32" else "unsigned short"
89
- )
90
-
91
- module = load_cuda_module("remove_nan_inf", name_expressions=[kernel_args])
92
- remove_nan_inf_kernel = module.get_function(kernel_args)
93
- remove_nan_inf_kernel(grid_dims, block_dims, params)
94
-
95
- if present_nans_infs[0].get() == 1:
96
- present_nans_infs_b = True
97
- else:
98
- if not np.all(np.isfinite(data)):
99
- present_nans_infs_b = True
100
- np.nan_to_num(data, copy=False, nan=0.0, posinf=0.0, neginf=0.0)
101
-
102
- if present_nans_infs_b:
103
- if verbosity:
104
- print(
105
- 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."
106
- )
107
-
108
- return data
109
-
110
-
111
- def _zeros_check(
112
- data: cp.ndarray,
113
- verbosity: bool = True,
114
- percentage_threshold: float = 50,
115
- method_name: Optional[str] = None,
116
- ) -> bool:
117
- """
118
- This function finds all zeros present in the data. If the amount of zeros is larger than percentage_threshold it prints the warning.
119
-
120
- Parameters
121
- ----------
122
- data : cp.ndarray
123
- Input CuPy or Numpy array.
124
- verbosity : bool
125
- If enabled, then the printing of the warning happens when data contains infs or nans.
126
- percentage_threshold: float:
127
- If the number of zeros in input data is more than the percentage of all data points, then print the data warning
128
- method_name : str, optional.
129
- Method's name for which input data is tested.
130
-
131
- Returns
132
- -------
133
- bool
134
- True if the data contains too many zeros
135
- """
136
- if cupy_run:
137
- xp = cp.get_array_module(data)
138
- else:
139
- import numpy as xp
140
-
141
- nonzero_elements_total = 1
142
- for tot_elements_mult in data.shape:
143
- nonzero_elements_total *= tot_elements_mult
144
-
145
- warning_zeros = False
146
- zero_elements_total = nonzero_elements_total - int(xp.count_nonzero(data))
147
-
148
- if (zero_elements_total / nonzero_elements_total) * 100 >= percentage_threshold:
149
- warning_zeros = True
150
- if verbosity:
151
- print(
152
- f"Warning!!! Input data to method: {method_name} contains more than {percentage_threshold} percent of zeros."
153
- )
154
-
155
- return warning_zeros
156
-
157
-
158
- def data_checker(
159
- data: cp.ndarray,
160
- verbosity: bool = True,
161
- method_name: Optional[str] = None,
162
- ) -> cp.ndarray:
163
- """
164
- Function that performs the variety of checks on input data, in some cases also correct the data and prints warnings.
165
- Currently it checks for: the presence of infs and nans in data.
166
-
167
- Parameters
168
- ----------
169
- data : xp.ndarray
170
- Input CuPy or Numpy array either float32 or uint16 data type.
171
- verbosity : bool
172
- If enabled, then the printing of the warning happens when data contains infs or nans.
173
- method_name : str, optional.
174
- Method's name for which input data is tested.
175
-
176
- Returns
177
- -------
178
- cp.ndarray
179
- Returns corrected or not data array.
180
- """
181
-
182
- data = _naninfs_check(data, verbosity=verbosity, method_name=method_name)
183
-
184
- # ! The number of zero elements check is currently switched off as it requires sorting or AtomicAdd, which makes it inefficient on GPUs. !
185
- # _zeros_check(
186
- # data,
187
- # verbosity=verbosity,
188
- # percentage_threshold=50,
189
- # method_name=method_name,
190
- # )
191
-
192
- return data
@@ -1,28 +0,0 @@
1
- httomolibgpu/__init__.py,sha256=sz3ia5rSjC4lj6Xw4VZekh3OxmeVB2E2747bzyHqQdY,838
2
- httomolibgpu/cupywrapper.py,sha256=6ITGJ2Jw5I5kVmKEL5LlsnLRniEqqBLsHiAjvLtk0Xk,493
3
- httomolibgpu/cuda_kernels/__init__.py,sha256=VQNMaGcVDwiE-C64FfLtubHpLriLG0Y3_QnjHBSHrN0,884
4
- httomolibgpu/cuda_kernels/calc_metrics.cu,sha256=oV7ZPcwjWafmZjbNsUkBYPvOViJ_nX3zBoOAuPCmIrA,11335
5
- httomolibgpu/cuda_kernels/center_360_shifts.cu,sha256=Ya_8hxjXGtPBsPY3qfGJaugwnYrTFjFFretRcLiUfFQ,1631
6
- httomolibgpu/cuda_kernels/generate_mask.cu,sha256=3il3r1J2cnTCd3UXO4GWGfBgGxj4pvrZnXviW_SXpO0,2650
7
- httomolibgpu/cuda_kernels/median_kernel.cu,sha256=EECLUCoJkT9GQ9Db_FF6fYOG6cDSiAePTRZNxE4VZ68,1692
8
- httomolibgpu/cuda_kernels/raven_filter.cu,sha256=KX2TM_9tMpvoGCHezDNWYABCnv2cT9mlMo4IhxRUac0,1437
9
- httomolibgpu/cuda_kernels/remove_nan_inf.cu,sha256=gv0ihkf6A_D_po9x7pmgFsQFhwZ1dB_HYc_0Tu-bpUU,630
10
- httomolibgpu/misc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- httomolibgpu/misc/corr.py,sha256=1tUjwMku-MAPiLaH9IFe3zmF0p6rJFLruoObXSZelXY,4665
12
- httomolibgpu/misc/denoise.py,sha256=l5FVdpur1I6YQcJJBfYTKjEsiDNyRYtpdOQZ7ZHicJw,4997
13
- httomolibgpu/misc/morph.py,sha256=AlLk_kGFHF6vNrdICMpsXmTUDnCc7ey97-_DqwZb3Wc,7475
14
- httomolibgpu/misc/rescale.py,sha256=K4VQ1AdxOAhe8tTSVb9VXVZsjBap5VlOtxHVdf9MU08,4416
15
- httomolibgpu/misc/supp_func.py,sha256=yDzNmRlIlIikQ4sKd2y9trQ9yQtblECmQ2JM5vmIY5I,6233
16
- httomolibgpu/prep/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
- httomolibgpu/prep/alignment.py,sha256=BuFTfLZD5_THQAKP_ikQ3fRE8JpN-JItGllZgrHRU5s,5657
18
- httomolibgpu/prep/normalize.py,sha256=ozVUAs4UY2DY7MQtJKllUgahp_4wRFKPuc_3iQl6bCE,4879
19
- httomolibgpu/prep/phase.py,sha256=zIuAVqlnHVqcDUBtj40NRBoHaO7O2KqGZ5CCUABRXBQ,7282
20
- httomolibgpu/prep/stripe.py,sha256=YgOVb7Z5H7NFM3d2Y1jfNNwwj7ZMDv9nMZMMCvdBnVM,15150
21
- httomolibgpu/recon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
- httomolibgpu/recon/algorithm.py,sha256=pCByNRby-6SUdH8QfC1z1BXVazTGcErLAyRgOPlm37o,28075
23
- httomolibgpu/recon/rotation.py,sha256=k_E0lBRprJz6AGclagIkrzk_9dipADxPtL5BxrggSwM,27729
24
- httomolibgpu-3.1.1.dist-info/licenses/LICENSE,sha256=bXeLsgelPUUXw8HCIYiVC97Dpjhm2nB54m7TACdH8ng,48032
25
- httomolibgpu-3.1.1.dist-info/METADATA,sha256=W0UoO0iumuI9Hs5WmIa3Q0Pxyf0v69yF4LLRq_D_g34,3341
26
- httomolibgpu-3.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
- httomolibgpu-3.1.1.dist-info/top_level.txt,sha256=nV0Ty_YvSPVd1O6MNWuIplD0w1nwk5hT76YgBZ-bzUw,13
28
- httomolibgpu-3.1.1.dist-info/RECORD,,