Skip to content

Commit 023bef6

Browse files
committed
removing nvtx instances to allow docs to build, removing function doubleundescore duplications
1 parent 3391946 commit 023bef6

File tree

9 files changed

+13
-410
lines changed

9 files changed

+13
-410
lines changed

httomolibgpu/cupywrapper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
)
1515
from unittest.mock import Mock
1616
import numpy as cp
17+
1718
cupy_run = False
1819

1920
nvtx = Mock()

httomolibgpu/misc/morph.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from httomolibgpu import cupywrapper
2525

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

3029
from unittest.mock import Mock
@@ -64,17 +63,6 @@ def sino_360_to_180(
6463
cp.ndarray
6564
Output 3D data.
6665
"""
67-
if cupywrapper.cupy_run:
68-
return __sino_360_to_180(data, overlap, rotation)
69-
else:
70-
print("sino_360_to_180 won't be executed because CuPy is not installed")
71-
return data
72-
73-
74-
@nvtx.annotate()
75-
def __sino_360_to_180(
76-
data: cp.ndarray, overlap: int = 0, rotation: Literal["left", "right"] = "left"
77-
) -> cp.ndarray:
7866
if data.ndim != 3:
7967
raise ValueError("only 3D data is supported")
8068

@@ -85,8 +73,8 @@ def __sino_360_to_180(
8573
raise ValueError("overlap must be less than data.shape[2]")
8674
if overlap < 0:
8775
raise ValueError("only positive overlaps are allowed.")
88-
89-
if rotation not in ['left', 'right']:
76+
77+
if rotation not in ["left", "right"]:
9078
raise ValueError('rotation parameter must be either "left" or "right"')
9179

9280
n = dx // 2
@@ -133,18 +121,6 @@ def data_resampler(
133121
Returns:
134122
cp.ndarray: Up/Down-scaled 3D cupy array
135123
"""
136-
if cupywrapper.cupy_run:
137-
return __data_resampler(data, newshape, axis, interpolation)
138-
else:
139-
print("data_resampler won't be executed because CuPy is not installed")
140-
return data
141-
142-
143-
@nvtx.annotate()
144-
def __data_resampler(
145-
data: cp.ndarray, newshape: list, axis: int = 1, interpolation: str = "linear"
146-
) -> cp.ndarray:
147-
148124
if data.ndim != 3:
149125
raise ValueError("only 3D data is supported")
150126

httomolibgpu/misc/rescale.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from httomolibgpu import cupywrapper
2424

2525
cp = cupywrapper.cp
26-
nvtx = cupywrapper.nvtx
2726

2827
from typing import Literal, Optional, Tuple, Union
2928

@@ -70,53 +69,6 @@ def rescale_to_int(
7069
The original data, clipped to the range specified with the perc_range_min and
7170
perc_range_max, and scaled to the full range of the output integer type
7271
"""
73-
if cupywrapper.cupy_run:
74-
return __rescale_to_int(data, perc_range_min, perc_range_max, bits, glob_stats)
75-
else:
76-
print("rescale_to_int won't be executed because CuPy is not installed")
77-
return data
78-
79-
80-
@nvtx.annotate()
81-
def __rescale_to_int(
82-
data: cp.ndarray,
83-
perc_range_min: float = 0.0,
84-
perc_range_max: float = 100.0,
85-
bits: Literal[8, 16, 32] = 8,
86-
glob_stats: Optional[Tuple[float, float, float, int]] = None,
87-
):
88-
"""
89-
Rescales the data and converts it fit into the range of an unsigned integer type
90-
with the given number of bits.
91-
92-
Parameters
93-
----------
94-
data : cp.ndarray
95-
Required input data array, on GPU
96-
perc_range_min: float, optional
97-
The lower cutoff point in the input data, in percent of the data range (defaults to 0).
98-
The lower bound is computed as min + perc_range_min/100*(max-min)
99-
perc_range_max: float, optional
100-
The upper cutoff point in the input data, in percent of the data range (defaults to 100).
101-
The upper bound is computed as min + perc_range_max/100*(max-min)
102-
bits: Literal[8, 16, 32], optional
103-
The number of bits in the output integer range (defaults to 8).
104-
Allowed values are:
105-
- 8 -> uint8
106-
- 16 -> uint16
107-
- 32 -> uint32
108-
glob_stats: tuple, optional
109-
Global statistics of the full dataset (beyond the data passed into this call).
110-
It's a tuple with (min, max, sum, num_items). If not given, the min/max is
111-
computed from the given data.
112-
113-
Returns
114-
-------
115-
cp.ndarray
116-
The original data, clipped to the range specified with the perc_range_min and
117-
perc_range_max, and scaled to the full range of the output integer type
118-
"""
119-
12072
if bits == 8:
12173
output_dtype: Union[type[np.uint8], type[np.uint16], type[np.uint32]] = np.uint8
12274
elif bits == 16:

httomolibgpu/prep/alignment.py

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from httomolibgpu import cupywrapper
2525

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

3029
from unittest.mock import Mock
@@ -82,55 +81,6 @@ def distortion_correction_proj_discorpy(
8281
cp.ndarray
8382
3D array. Distortion-corrected array.
8483
"""
85-
if cupywrapper.cupy_run:
86-
return __distortion_correction_proj_discorpy(
87-
data, metadata_path, preview, order, mode
88-
)
89-
else:
90-
print(
91-
"distortion_correction_proj_discorpy won't be executed because CuPy is not installed"
92-
)
93-
return data
94-
95-
96-
@nvtx.annotate()
97-
def __distortion_correction_proj_discorpy(
98-
data: cp.ndarray,
99-
metadata_path: str,
100-
preview: Dict[str, List[int]],
101-
order: int = 1,
102-
mode: str = "reflect",
103-
):
104-
"""Unwarp a stack of images using a backward model.
105-
106-
Parameters
107-
----------
108-
data : cp.ndarray
109-
3D array.
110-
111-
metadata_path : str
112-
The path to the file containing the distortion coefficients for the
113-
data.
114-
115-
preview : Dict[str, List[int]]
116-
A dict containing three key-value pairs:
117-
- a list containing the `start` value of each dimension
118-
- a list containing the `stop` value of each dimension
119-
- a list containing the `step` value of each dimension
120-
121-
order : int, optional.
122-
The order of the spline interpolation.
123-
124-
mode : {'reflect', 'grid-mirror', 'constant', 'grid-constant', 'nearest',
125-
'mirror', 'grid-wrap', 'wrap'}, optional
126-
To determine how to handle image boundaries.
127-
128-
Returns
129-
-------
130-
cp.ndarray
131-
3D array. Distortion-corrected image(s).
132-
"""
133-
13484
# Check if it's a stack of 2D images, or only a single 2D image
13585
if len(data.shape) == 2:
13686
data = cp.expand_dims(data, axis=0)

httomolibgpu/prep/normalize.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from httomolibgpu import cupywrapper
2525

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

3029
from unittest.mock import Mock
@@ -75,26 +74,6 @@ def normalize(
7574
cp.ndarray
7675
Normalised 3D tomographic data as a CuPy array.
7776
"""
78-
if cupywrapper.cupy_run:
79-
return __normalize(
80-
data, flats, darks, cutoff, minus_log, nonnegativity, remove_nans
81-
)
82-
else:
83-
print("normalize won't be executed because CuPy is not installed")
84-
return data
85-
86-
87-
@nvtx.annotate()
88-
def __normalize(
89-
data: cp.ndarray,
90-
flats: cp.ndarray,
91-
darks: cp.ndarray,
92-
cutoff: float = 10.0,
93-
minus_log: bool = True,
94-
nonnegativity: bool = False,
95-
remove_nans: bool = True,
96-
) -> cp.ndarray:
97-
9877
_check_valid_input(data, flats, darks)
9978

10079
dark0 = cp.empty(darks.shape[1:], dtype=float32)

httomolibgpu/prep/phase.py

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
from httomolibgpu import cupywrapper
2525

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

3029
from unittest.mock import Mock
30+
3131
if cupy_run:
3232
from httomolibgpu.cuda_kernels import load_cuda_module
3333
from cupyx.scipy.fft import fft2, ifft2, fftshift
@@ -98,36 +98,6 @@ def paganin_filter_savu(
9898
cp.ndarray
9999
The stack of filtered projections.
100100
"""
101-
if cupywrapper.cupy_run:
102-
return __paganin_filter_savu(
103-
data,
104-
ratio,
105-
energy,
106-
distance,
107-
resolution,
108-
pad_y,
109-
pad_x,
110-
pad_method,
111-
increment,
112-
)
113-
else:
114-
print("__paganin_filter_savu won't be executed because CuPy is not installed")
115-
return data
116-
117-
118-
@nvtx.annotate()
119-
def __paganin_filter_savu(
120-
data: cp.ndarray,
121-
ratio: float = 250.0,
122-
energy: float = 53.0,
123-
distance: float = 1.0,
124-
resolution: float = 1.28,
125-
pad_y: int = 100,
126-
pad_x: int = 100,
127-
pad_method: str = "edge",
128-
increment: float = 0.0,
129-
) -> cp.ndarray:
130-
131101
# Check the input data is valid
132102
if data.ndim != 3:
133103
raise ValueError(
@@ -321,22 +291,6 @@ def paganin_filter_tomopy(
321291
cp.ndarray
322292
The 3D array of Paganin phase-filtered projection images.
323293
"""
324-
if cupywrapper.cupy_run:
325-
return __paganin_filter_tomopy(tomo, pixel_size, dist, energy, alpha)
326-
else:
327-
print("paganin_filter_tomopy won't be executed because CuPy is not installed")
328-
return tomo
329-
330-
331-
@nvtx.annotate()
332-
def __paganin_filter_tomopy(
333-
tomo: cp.ndarray,
334-
pixel_size: float = 1e-4,
335-
dist: float = 50.0,
336-
energy: float = 53.0,
337-
alpha: float = 1e-3,
338-
) -> cp.ndarray:
339-
340294
# Check the input data is valid
341295
if tomo.ndim != 3:
342296
raise ValueError(

0 commit comments

Comments
 (0)