httomolibgpu 5.2__py3-none-any.whl → 5.3__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.
- httomolibgpu/cupywrapper.py +2 -0
- httomolibgpu/prep/phase.py +70 -11
- {httomolibgpu-5.2.dist-info → httomolibgpu-5.3.dist-info}/METADATA +1 -1
- {httomolibgpu-5.2.dist-info → httomolibgpu-5.3.dist-info}/RECORD +7 -7
- {httomolibgpu-5.2.dist-info → httomolibgpu-5.3.dist-info}/WHEEL +0 -0
- {httomolibgpu-5.2.dist-info → httomolibgpu-5.3.dist-info}/licenses/LICENSE +0 -0
- {httomolibgpu-5.2.dist-info → httomolibgpu-5.3.dist-info}/top_level.txt +0 -0
httomolibgpu/cupywrapper.py
CHANGED
|
@@ -2,6 +2,7 @@ cupy_run = False
|
|
|
2
2
|
try:
|
|
3
3
|
import cupy as cp
|
|
4
4
|
import nvtx
|
|
5
|
+
from cupyx.scipy.fft import next_fast_len
|
|
5
6
|
|
|
6
7
|
try:
|
|
7
8
|
cp.cuda.Device(0).compute_capability
|
|
@@ -15,5 +16,6 @@ except ImportError as e:
|
|
|
15
16
|
)
|
|
16
17
|
from unittest.mock import Mock
|
|
17
18
|
import numpy as cp
|
|
19
|
+
from scipy.fft import next_fast_len
|
|
18
20
|
|
|
19
21
|
nvtx = Mock()
|
httomolibgpu/prep/phase.py
CHANGED
|
@@ -26,6 +26,7 @@ from httomolibgpu.memory_estimator_helpers import _DeviceMemStack
|
|
|
26
26
|
|
|
27
27
|
cp = cupywrapper.cp
|
|
28
28
|
cupy_run = cupywrapper.cupy_run
|
|
29
|
+
next_fast_len = cupywrapper.next_fast_len
|
|
29
30
|
|
|
30
31
|
from unittest.mock import Mock
|
|
31
32
|
|
|
@@ -38,7 +39,7 @@ else:
|
|
|
38
39
|
fftshift = Mock()
|
|
39
40
|
|
|
40
41
|
from numpy import float32
|
|
41
|
-
from typing import Optional, Tuple
|
|
42
|
+
from typing import Literal, Optional, Tuple
|
|
42
43
|
import math
|
|
43
44
|
|
|
44
45
|
__all__ = [
|
|
@@ -56,6 +57,10 @@ def paganin_filter(
|
|
|
56
57
|
distance: float = 1.0,
|
|
57
58
|
energy: float = 53.0,
|
|
58
59
|
ratio_delta_beta: float = 250,
|
|
60
|
+
calculate_padding_value_method: Literal[
|
|
61
|
+
"next_power_of_2", "next_fast_length", "use_pad_x_y"
|
|
62
|
+
] = "next_power_of_2",
|
|
63
|
+
pad_x_y: Optional[list] = None,
|
|
59
64
|
calc_peak_gpu_mem: bool = False,
|
|
60
65
|
) -> cp.ndarray:
|
|
61
66
|
"""
|
|
@@ -74,6 +79,10 @@ def paganin_filter(
|
|
|
74
79
|
Beam energy in keV.
|
|
75
80
|
ratio_delta_beta : float
|
|
76
81
|
The ratio of delta/beta, where delta is the phase shift and real part of the complex material refractive index and beta is the absorption.
|
|
82
|
+
calculate_padding_value_method: str
|
|
83
|
+
Method to calculate the padded size of the input data. Accepted values are 'next_power_of_2', 'next_fast_length' and 'use_pad_x_y`.
|
|
84
|
+
pad_x_y list | None:
|
|
85
|
+
Padding values in pixels horizontally and vertically. Must be None, unless `calculate_padding_value_method` is 'use_pad_x_y'.
|
|
77
86
|
calc_peak_gpu_mem: bool
|
|
78
87
|
Parameter to support memory estimation in HTTomo. Irrelevant to the method itself and can be ignored by user.
|
|
79
88
|
|
|
@@ -93,9 +102,9 @@ def paganin_filter(
|
|
|
93
102
|
mem_stack.malloc(np.prod(tomo) * np.float32().itemsize)
|
|
94
103
|
dz_orig, dy_orig, dx_orig = tomo.shape if not mem_stack else tomo
|
|
95
104
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
105
|
+
padded_tomo, pad_tup = _pad_projections(
|
|
106
|
+
tomo, calculate_padding_value_method, pad_x_y, mem_stack
|
|
107
|
+
)
|
|
99
108
|
|
|
100
109
|
dz, dy, dx = padded_tomo.shape if not mem_stack else padded_tomo
|
|
101
110
|
|
|
@@ -219,21 +228,59 @@ def _shift_bit_length(x: int) -> int:
|
|
|
219
228
|
return 1 << (x - 1).bit_length()
|
|
220
229
|
|
|
221
230
|
|
|
222
|
-
def _calculate_pad_size(
|
|
231
|
+
def _calculate_pad_size(
|
|
232
|
+
datashape: tuple,
|
|
233
|
+
calculate_padding_value_method: Literal[
|
|
234
|
+
"next_power_of_2", "next_fast_length", "use_pad_x_y"
|
|
235
|
+
],
|
|
236
|
+
pad_x_y: Optional[list],
|
|
237
|
+
) -> list:
|
|
223
238
|
"""Calculating the padding size
|
|
224
239
|
|
|
225
240
|
Args:
|
|
226
|
-
datashape (tuple):
|
|
241
|
+
datashape (tuple):
|
|
242
|
+
the shape of the 3D data
|
|
243
|
+
calculate_padding_value_method: str
|
|
244
|
+
Method to calculate the padded size of the input data. Accepted values are 'next_power_of_2', 'next_fast_length' and 'use_pad_x_y`.
|
|
245
|
+
pad_x_y (int, int) | None:
|
|
246
|
+
Padding values in pixels horizontally and vertically. Must be None, unless `calculate_padding_value_method` is 'use_pad_x_y'.
|
|
227
247
|
|
|
228
248
|
Returns:
|
|
229
249
|
list: the padded dimensions
|
|
230
250
|
"""
|
|
251
|
+
if pad_x_y is not None and calculate_padding_value_method != "use_pad_x_y":
|
|
252
|
+
raise ValueError(
|
|
253
|
+
'calculate_padding_value_method must be "use_pad_x_y" when pad_x_y is specified'
|
|
254
|
+
)
|
|
255
|
+
elif calculate_padding_value_method == "use_pad_x_y":
|
|
256
|
+
if pad_x_y is None:
|
|
257
|
+
raise ValueError(
|
|
258
|
+
'pad_x_y must be provided when calculate_padding_value_method is "use_pad_x_y"'
|
|
259
|
+
)
|
|
260
|
+
elif (
|
|
261
|
+
not isinstance(pad_x_y, list)
|
|
262
|
+
or len(pad_x_y) != 2
|
|
263
|
+
or not isinstance(pad_x_y[0], int)
|
|
264
|
+
or not isinstance(pad_x_y[1], int)
|
|
265
|
+
):
|
|
266
|
+
raise ValueError("pad_x_y must be a list of two integers")
|
|
267
|
+
|
|
268
|
+
if calculate_padding_value_method == "next_power_of_2":
|
|
269
|
+
calculate_padded_dim = lambda _, size: _shift_bit_length(size + 1)
|
|
270
|
+
elif calculate_padding_value_method == "next_fast_length":
|
|
271
|
+
calculate_padded_dim = lambda _, size: next_fast_len(size)
|
|
272
|
+
elif calculate_padding_value_method == "use_pad_x_y":
|
|
273
|
+
calculate_padded_dim = lambda dim, size: size + 2 * pad_x_y[2 - dim]
|
|
274
|
+
else:
|
|
275
|
+
raise ValueError(
|
|
276
|
+
f'Unexpected calculate_padding_value_method: "{calculate_padding_value_method}"'
|
|
277
|
+
)
|
|
231
278
|
pad_list = []
|
|
232
279
|
for index, element in enumerate(datashape):
|
|
233
280
|
if index == 0:
|
|
234
281
|
pad_width = (0, 0) # do not pad the slicing dim
|
|
235
282
|
else:
|
|
236
|
-
diff =
|
|
283
|
+
diff = calculate_padded_dim(index, element) - element
|
|
237
284
|
if element % 2 == 0:
|
|
238
285
|
pad_width_scalar = diff // 2
|
|
239
286
|
pad_width = (pad_width_scalar, pad_width_scalar)
|
|
@@ -248,17 +295,27 @@ def _calculate_pad_size(datashape: tuple) -> list:
|
|
|
248
295
|
return pad_list
|
|
249
296
|
|
|
250
297
|
|
|
251
|
-
def
|
|
252
|
-
tomo: cp.ndarray,
|
|
298
|
+
def _pad_projections(
|
|
299
|
+
tomo: cp.ndarray,
|
|
300
|
+
calculate_padding_value_method: Literal[
|
|
301
|
+
"next_power_of_2", "next_fast_length", "use_pad_x_y"
|
|
302
|
+
],
|
|
303
|
+
pad_x_y: Optional[list],
|
|
304
|
+
mem_stack: Optional[_DeviceMemStack],
|
|
253
305
|
) -> Tuple[cp.ndarray, Tuple[int, int]]:
|
|
254
306
|
"""
|
|
255
|
-
Performs padding of each projection to
|
|
307
|
+
Performs padding of each projection to a size optimal for FFT.
|
|
256
308
|
If the shape is not even we also care of that before padding.
|
|
257
309
|
|
|
258
310
|
Parameters
|
|
259
311
|
----------
|
|
260
312
|
tomo : cp.ndarray
|
|
261
313
|
3d projection data
|
|
314
|
+
calculate_padding_value_method: str
|
|
315
|
+
Method to calculate the padded size of the input data. Accepted values are 'next_power_of_2', 'next_fast_length' and 'use_pad_x_y`.
|
|
316
|
+
pad_x_y: list | None:
|
|
317
|
+
Padding values in pixels horizontally and vertically. Must be None, unless `calculate_padding_value_method` is 'use_pad_x_y'.
|
|
318
|
+
|
|
262
319
|
|
|
263
320
|
Returns
|
|
264
321
|
-------
|
|
@@ -268,7 +325,9 @@ def _pad_projections_to_second_power(
|
|
|
268
325
|
"""
|
|
269
326
|
full_shape_tomo = cp.shape(tomo) if not mem_stack else tomo
|
|
270
327
|
|
|
271
|
-
pad_list = _calculate_pad_size(
|
|
328
|
+
pad_list = _calculate_pad_size(
|
|
329
|
+
full_shape_tomo, calculate_padding_value_method, pad_x_y
|
|
330
|
+
)
|
|
272
331
|
|
|
273
332
|
if mem_stack:
|
|
274
333
|
padded_tomo = [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: httomolibgpu
|
|
3
|
-
Version: 5.
|
|
3
|
+
Version: 5.3
|
|
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
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
httomolibgpu/__init__.py,sha256=Dt_TYhjJGPVathlceTYQhoRSyH8n7FGQJlRMUlFZNdc,959
|
|
2
|
-
httomolibgpu/cupywrapper.py,sha256=
|
|
2
|
+
httomolibgpu/cupywrapper.py,sha256=vHuBN4Wo3YxPnQP0OAJypLfZA6AXyXFgVmaZw_67pvo,579
|
|
3
3
|
httomolibgpu/memory_estimator_helpers.py,sha256=QaJady-z8y9Emw7W-lB608vBTNvVYv3obboQKVj6E9M,705
|
|
4
4
|
httomolibgpu/cuda_kernels/__init__.py,sha256=VQNMaGcVDwiE-C64FfLtubHpLriLG0Y3_QnjHBSHrN0,884
|
|
5
5
|
httomolibgpu/cuda_kernels/calc_metrics.cu,sha256=oV7ZPcwjWafmZjbNsUkBYPvOViJ_nX3zBoOAuPCmIrA,11335
|
|
@@ -18,14 +18,14 @@ httomolibgpu/misc/utils.py,sha256=rHRuQUO47SlTanvKDBgiC0im4tXlGLCw5B_zvlLzzbc,47
|
|
|
18
18
|
httomolibgpu/prep/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
19
|
httomolibgpu/prep/alignment.py,sha256=GVxnyioipmqsHb4s3mPQ8tKGoPIQMPftDrQxUO-HBuE,5491
|
|
20
20
|
httomolibgpu/prep/normalize.py,sha256=hee0H4mE7FrSZgcF1fjLsKT06xjTJymkyAxpe2itQe4,4202
|
|
21
|
-
httomolibgpu/prep/phase.py,sha256=
|
|
21
|
+
httomolibgpu/prep/phase.py,sha256=N3Ep_Krn4rqbGOnNhApSbIYM7gVstBtequXTklBDQLk,14907
|
|
22
22
|
httomolibgpu/prep/stripe.py,sha256=OZPimFxe9TOSaEcErORFxd6HCcFcR62-q5XYBvC10FM,36918
|
|
23
23
|
httomolibgpu/recon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
24
|
httomolibgpu/recon/_phase_cross_correlation.py,sha256=Ru2oLAPv8XOSSuZer5yNQrxD_8lMAwBSvtkVAVs5TCc,16469
|
|
25
25
|
httomolibgpu/recon/algorithm.py,sha256=ds-_io7kGzo5FiJq8k4--PYtIWak3y9H7yuyg1lymyQ,25121
|
|
26
26
|
httomolibgpu/recon/rotation.py,sha256=GaSwNrlDnlP_iIrTfKUQLiXsShJ5aSDvdKPwofggtwQ,27948
|
|
27
|
-
httomolibgpu-5.
|
|
28
|
-
httomolibgpu-5.
|
|
29
|
-
httomolibgpu-5.
|
|
30
|
-
httomolibgpu-5.
|
|
31
|
-
httomolibgpu-5.
|
|
27
|
+
httomolibgpu-5.3.dist-info/licenses/LICENSE,sha256=bXeLsgelPUUXw8HCIYiVC97Dpjhm2nB54m7TACdH8ng,48032
|
|
28
|
+
httomolibgpu-5.3.dist-info/METADATA,sha256=prUDINLOyJMUnUz3YQCkfhuDJtPyQCoELYedj2ktUD0,3365
|
|
29
|
+
httomolibgpu-5.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
30
|
+
httomolibgpu-5.3.dist-info/top_level.txt,sha256=nV0Ty_YvSPVd1O6MNWuIplD0w1nwk5hT76YgBZ-bzUw,13
|
|
31
|
+
httomolibgpu-5.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|