Skip to content

Commit 56ada04

Browse files
committed
docs2
1 parent 579e3c4 commit 56ada04

File tree

9 files changed

+43
-48
lines changed

9 files changed

+43
-48
lines changed

docs/source/conf.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"nvtx",
2323
"cupy",
2424
"cupyx",
25+
"tomobar.methodsDIR_CuPy",
26+
"tomobar.methodsIR_CuPy",
2527
"PIL",
2628
"skimage",
2729
"scipy",
@@ -40,6 +42,15 @@ def __repr__(self):
4042

4143
sys.modules["cupy"] = CustomMock()
4244
sys.modules["numpy"] = CustomMock()
45+
sys.modules["cupyx.scipy.interpolate"] = CustomMock()
46+
sys.modules["cupyx.scipy.ndimage"] = CustomMock()
47+
sys.modules["cupyx.scipy.fft"] = CustomMock()
48+
sys.modules["cupyx.scipy.fftpack"] = CustomMock()
49+
sys.modules["scipy.fftpack"] = CustomMock()
50+
sys.modules["tomobar.methodsDIR_CuPy"] = CustomMock()
51+
sys.modules["tomobar.methodsIR_CuPy "] = CustomMock()
52+
sys.modules["skimage.registration"] = CustomMock()
53+
4354

4455
# ------------------------------------------------------------------------------
4556

docs/source/reference/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This section contains the API reference and usage information for HttomolibGPU.
88

99
HTTomolibGPU Modules
1010
---------------------
11-
v.2.0
11+
v.2.1
1212
'''''
1313

1414
.. toctree::

httomolibgpu/misc/morph.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ def __sino_360_to_180(
8080
raise ValueError("overlap must be less than data.shape[2]")
8181
if overlap < 0:
8282
raise ValueError("only positive overlaps are allowed.")
83+
84+
if rotation not in ['left', 'right']:
85+
raise ValueError('rotation parameter must be either "left" or "right"')
8386

8487
n = dx // 2
8588

@@ -93,16 +96,14 @@ def __sino_360_to_180(
9396
weights * data[:n, :, :overlap]
9497
+ (weights * data[n : 2 * n, :, :overlap])[:, :, ::-1]
9598
)
96-
elif rotation == "right":
99+
if rotation == "right":
97100
weights = cp.linspace(1.0, 0, overlap, dtype=cp.float32)
98101
out[:, :, : dz - overlap] = data[:n, :, :-overlap]
99102
out[:, :, -dz + overlap :] = data[n : 2 * n, :, :-overlap][:, :, ::-1]
100103
out[:, :, dz - overlap : dz] = (
101104
weights * data[:n, :, -overlap:]
102105
+ (weights * data[n : 2 * n, :, -overlap:])[:, :, ::-1]
103106
)
104-
else:
105-
raise ValueError('rotation parameter must be either "left" or "right"')
106107

107108
return out
108109

httomolibgpu/prep/alignment.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
cp = cupywrapper.cp
2727
nvtx = cupywrapper.nvtx
28+
cupyx = cupywrapper.cupyx
29+
30+
from cupyx.scipy.ndimage import map_coordinates
2831

2932
from typing import Dict, List
3033

@@ -72,7 +75,7 @@ def distortion_correction_proj_discorpy(
7275
Returns
7376
-------
7477
cp.ndarray
75-
3D array. Distortion-corrected image(s).
78+
3D array. Distortion-corrected array.
7679
"""
7780
if cupywrapper.cupy_run:
7881
return __distortion_correction_proj_discorpy(
@@ -121,9 +124,7 @@ def __distortion_correction_proj_discorpy(
121124
-------
122125
cp.ndarray
123126
3D array. Distortion-corrected image(s).
124-
"""
125-
126-
from cupyx.scipy.ndimage import map_coordinates
127+
"""
127128

128129
# Check if it's a stack of 2D images, or only a single 2D image
129130
if len(data.shape) == 2:

httomolibgpu/prep/normalize.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
from httomolibgpu import cupywrapper
2525

2626
cp = cupywrapper.cp
27-
2827
nvtx = cupywrapper.nvtx
2928

29+
from cupy import mean
30+
3031
from numpy import float32
3132
from typing import Tuple
3233

@@ -86,8 +87,7 @@ def __normalize(
8687
minus_log: bool = True,
8788
nonnegativity: bool = False,
8889
remove_nans: bool = True,
89-
) -> cp.ndarray:
90-
from cupy import mean
90+
) -> cp.ndarray:
9191

9292
_check_valid_input(data, flats, darks)
9393

httomolibgpu/prep/phase.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
from httomolibgpu import cupywrapper
2525

2626
cp = cupywrapper.cp
27-
2827
nvtx = cupywrapper.nvtx
2928

29+
from httomolibgpu.cuda_kernels import load_cuda_module
30+
from cupyx.scipy.fft import fft2, ifft2, fftshift
31+
3032
from numpy import float32
3133
from typing import Union
3234
import math
@@ -117,8 +119,6 @@ def __paganin_filter_savu(
117119
pad_method: str = "edge",
118120
increment: float = 0.0,
119121
) -> cp.ndarray:
120-
from httomolibgpu.cuda_kernels import load_cuda_module
121-
from cupyx.scipy.fft import fft2, ifft2
122122

123123
# Check the input data is valid
124124
if data.ndim != 3:
@@ -327,8 +327,7 @@ def __paganin_filter_tomopy(
327327
dist: float = 50.0,
328328
energy: float = 53.0,
329329
alpha: float = 1e-3,
330-
) -> cp.ndarray:
331-
from cupyx.scipy.fft import fft2, ifft2, fftshift
330+
) -> cp.ndarray:
332331

333332
# Check the input data is valid
334333
if tomo.ndim != 3:

httomolibgpu/prep/stripe.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
from httomolibgpu import cupywrapper
2525

2626
cp = cupywrapper.cp
27-
2827
nvtx = cupywrapper.nvtx
28+
29+
from cupyx.scipy.ndimage import median_filter, binary_dilation, uniform_filter1d
30+
2931
from typing import Union
3032

3133
__all__ = [
@@ -96,8 +98,6 @@ def _rs_sort(sinogram, size, dim):
9698
"""
9799
Remove stripes using the sorting technique.
98100
"""
99-
from cupyx.scipy.ndimage import median_filter
100-
101101
sinogram = cp.transpose(sinogram)
102102

103103
#: Sort each column of the sinogram by its grayscale values
@@ -245,8 +245,6 @@ def _rs_sort2(sinogram, size, matindex, dim):
245245
"""
246246
Remove stripes using the sorting technique.
247247
"""
248-
from cupyx.scipy.ndimage import median_filter
249-
250248
sinogram = cp.transpose(sinogram)
251249
matcomb = cp.asarray(cp.dstack((matindex, sinogram)))
252250

@@ -321,9 +319,6 @@ def _rs_large(sinogram, snr, size, matindex, drop_ratio=0.1, norm=True):
321319
"""
322320
Remove large stripes.
323321
"""
324-
from cupyx.scipy.ndimage import median_filter
325-
from cupyx.scipy.ndimage import binary_dilation
326-
327322
drop_ratio = max(min(drop_ratio, 0.8), 0) # = cp.clip(drop_ratio, 0.0, 0.8)
328323
(nrow, ncol) = sinogram.shape
329324
ndrop = int(0.5 * drop_ratio * nrow)
@@ -372,10 +367,6 @@ def _rs_dead(sinogram, snr, size, matindex, norm=True):
372367
"""
373368
Remove unresponsive and fluctuating stripes.
374369
"""
375-
from cupyx.scipy.ndimage import median_filter
376-
from cupyx.scipy.ndimage import binary_dilation
377-
from cupyx.scipy.ndimage import uniform_filter1d
378-
379370
sinogram = cp.copy(sinogram) # Make it mutable
380371
(nrow, _) = sinogram.shape
381372
# sinosmooth = cp.apply_along_axis(uniform_filter1d, 0, sinogram, 10)

httomolibgpu/recon/algorithm.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@
2424
from httomolibgpu import cupywrapper
2525

2626
cp = cupywrapper.cp
27-
2827
nvtx = cupywrapper.nvtx
29-
from numpy import float32, complex64
30-
from typing import Optional, Type
3128

3229
from tomobar.methodsDIR_CuPy import RecToolsDIRCuPy
3330
from tomobar.methodsIR_CuPy import RecToolsIRCuPy
3431

32+
from numpy import float32, complex64
33+
from typing import Optional, Type
34+
35+
3536
__all__ = [
3637
"FBP",
3738
"LPRec",

httomolibgpu/recon/rotation.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@
2424
from httomolibgpu import cupywrapper
2525

2626
cp = cupywrapper.cp
27-
2827
nvtx = cupywrapper.nvtx
2928

29+
from httomolibgpu.cuda_kernels import load_cuda_module
30+
from cupyx.scipy.ndimage import shift, gaussian_filter
31+
from skimage.registration import phase_cross_correlation
32+
from cupyx.scipy.fftpack import get_fft_plan
33+
from cupyx.scipy.fft import rfft2
34+
3035
import math
3136
from typing import List, Literal, Optional, Tuple, Union
3237

@@ -96,8 +101,7 @@ def __find_center_vo(
96101
step: float = 0.25,
97102
ratio: float = 0.5,
98103
drop: int = 20,
99-
) -> float:
100-
from cupyx.scipy.ndimage import gaussian_filter
104+
) -> float:
101105

102106
if data.ndim == 2:
103107
data = cp.expand_dims(data, 1)
@@ -185,7 +189,6 @@ def _search_fine(sino, srad, step, init_cen, ratio, drop):
185189

186190
@nvtx.annotate()
187191
def _create_mask(nrow, ncol, radius, drop):
188-
from httomolibgpu.cuda_kernels import load_cuda_module
189192

190193
du = 1.0 / ncol
191194
dv = (nrow - 1.0) / (nrow * 2.0 * np.pi)
@@ -258,11 +261,6 @@ def _calculate_chunks(
258261

259262
@nvtx.annotate()
260263
def _calculate_metric(list_shift, sino1, sino2, sino3, mask, out):
261-
from httomolibgpu.cuda_kernels import load_cuda_module
262-
from cupyx.scipy.ndimage import shift
263-
from cupyx.scipy.fftpack import get_fft_plan
264-
from cupyx.scipy.fft import rfft2
265-
266264
# this tries to simplify - if shift_col is integer, no need to spline interpolate
267265
assert list_shift.dtype == cp.float32, "shifts must be single precision floats"
268266
assert sino1.dtype == cp.float32, "sino1 must be float32"
@@ -351,8 +349,6 @@ def _calculate_metric(list_shift, sino1, sino2, sino3, mask, out):
351349

352350
@nvtx.annotate()
353351
def _downsample(sino, level, axis):
354-
from httomolibgpu.cuda_kernels import load_cuda_module
355-
356352
assert sino.dtype == cp.float32, "single precision floating point input required"
357353
assert sino.flags["C_CONTIGUOUS"], "list_shift must be C-contiguous"
358354

@@ -612,7 +608,6 @@ def _search_overlap(
612608
Initial position of the searching window where the position
613609
corresponds to the center of the window.
614610
"""
615-
from cupyx.scipy.ndimage import gaussian_filter
616611

617612
if denoise is True:
618613
# note: the filtering makes the output contiguous
@@ -650,8 +645,6 @@ def _calc_metrics(mat1, mat2, win_width, side, use_overlap, norm):
650645
assert mat1.flags.c_contiguous, "only contiguos arrays supported"
651646
assert mat2.flags.c_contiguous, "only contiguos arrays supported"
652647

653-
from httomolibgpu.cuda_kernels import load_cuda_module
654-
655648
_calc_metrics_module = load_cuda_module(
656649
"calc_metrics",
657650
name_expressions=[
@@ -766,9 +759,7 @@ def __find_center_pc(
766759
tol: float = 0.5,
767760
rotc_guess: Union[float, Optional[str]] = None,
768761
) -> float:
769-
from cupyx.scipy.ndimage import shift
770-
from skimage.registration import phase_cross_correlation
771-
762+
772763
imgshift = 0.0 if rotc_guess is None else rotc_guess - (proj1.shape[1] - 1.0) / 2.0
773764

774765
proj1 = shift(proj1, [0, -imgshift], mode="constant", cval=0)

0 commit comments

Comments
 (0)