Skip to content

Commit

Permalink
removing nvtx instances to allow docs to build, removing function dou…
Browse files Browse the repository at this point in the history
…bleundescore duplications
  • Loading branch information
dkazanc committed Sep 2, 2024
1 parent 3391946 commit 023bef6
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 410 deletions.
1 change: 1 addition & 0 deletions httomolibgpu/cupywrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)
from unittest.mock import Mock
import numpy as cp

cupy_run = False

nvtx = Mock()
28 changes: 2 additions & 26 deletions httomolibgpu/misc/morph.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from httomolibgpu import cupywrapper

cp = cupywrapper.cp
nvtx = cupywrapper.nvtx
cupy_run = cupywrapper.cupy_run

from unittest.mock import Mock
Expand Down Expand Up @@ -64,17 +63,6 @@ def sino_360_to_180(
cp.ndarray
Output 3D data.
"""
if cupywrapper.cupy_run:
return __sino_360_to_180(data, overlap, rotation)
else:
print("sino_360_to_180 won't be executed because CuPy is not installed")
return data


@nvtx.annotate()
def __sino_360_to_180(
data: cp.ndarray, overlap: int = 0, rotation: Literal["left", "right"] = "left"
) -> cp.ndarray:
if data.ndim != 3:
raise ValueError("only 3D data is supported")

Expand All @@ -85,8 +73,8 @@ def __sino_360_to_180(
raise ValueError("overlap must be less than data.shape[2]")
if overlap < 0:
raise ValueError("only positive overlaps are allowed.")
if rotation not in ['left', 'right']:

if rotation not in ["left", "right"]:
raise ValueError('rotation parameter must be either "left" or "right"')

n = dx // 2
Expand Down Expand Up @@ -133,18 +121,6 @@ def data_resampler(
Returns:
cp.ndarray: Up/Down-scaled 3D cupy array
"""
if cupywrapper.cupy_run:
return __data_resampler(data, newshape, axis, interpolation)
else:
print("data_resampler won't be executed because CuPy is not installed")
return data


@nvtx.annotate()
def __data_resampler(
data: cp.ndarray, newshape: list, axis: int = 1, interpolation: str = "linear"
) -> cp.ndarray:

if data.ndim != 3:
raise ValueError("only 3D data is supported")

Expand Down
48 changes: 0 additions & 48 deletions httomolibgpu/misc/rescale.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from httomolibgpu import cupywrapper

cp = cupywrapper.cp
nvtx = cupywrapper.nvtx

from typing import Literal, Optional, Tuple, Union

Expand Down Expand Up @@ -70,53 +69,6 @@ def rescale_to_int(
The original data, clipped to the range specified with the perc_range_min and
perc_range_max, and scaled to the full range of the output integer type
"""
if cupywrapper.cupy_run:
return __rescale_to_int(data, perc_range_min, perc_range_max, bits, glob_stats)
else:
print("rescale_to_int won't be executed because CuPy is not installed")
return data


@nvtx.annotate()
def __rescale_to_int(
data: cp.ndarray,
perc_range_min: float = 0.0,
perc_range_max: float = 100.0,
bits: Literal[8, 16, 32] = 8,
glob_stats: Optional[Tuple[float, float, float, int]] = None,
):
"""
Rescales the data and converts it fit into the range of an unsigned integer type
with the given number of bits.
Parameters
----------
data : cp.ndarray
Required input data array, on GPU
perc_range_min: float, optional
The lower cutoff point in the input data, in percent of the data range (defaults to 0).
The lower bound is computed as min + perc_range_min/100*(max-min)
perc_range_max: float, optional
The upper cutoff point in the input data, in percent of the data range (defaults to 100).
The upper bound is computed as min + perc_range_max/100*(max-min)
bits: Literal[8, 16, 32], optional
The number of bits in the output integer range (defaults to 8).
Allowed values are:
- 8 -> uint8
- 16 -> uint16
- 32 -> uint32
glob_stats: tuple, optional
Global statistics of the full dataset (beyond the data passed into this call).
It's a tuple with (min, max, sum, num_items). If not given, the min/max is
computed from the given data.
Returns
-------
cp.ndarray
The original data, clipped to the range specified with the perc_range_min and
perc_range_max, and scaled to the full range of the output integer type
"""

if bits == 8:
output_dtype: Union[type[np.uint8], type[np.uint16], type[np.uint32]] = np.uint8
elif bits == 16:
Expand Down
50 changes: 0 additions & 50 deletions httomolibgpu/prep/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from httomolibgpu import cupywrapper

cp = cupywrapper.cp
nvtx = cupywrapper.nvtx
cupy_run = cupywrapper.cupy_run

from unittest.mock import Mock
Expand Down Expand Up @@ -82,55 +81,6 @@ def distortion_correction_proj_discorpy(
cp.ndarray
3D array. Distortion-corrected array.
"""
if cupywrapper.cupy_run:
return __distortion_correction_proj_discorpy(
data, metadata_path, preview, order, mode
)
else:
print(
"distortion_correction_proj_discorpy won't be executed because CuPy is not installed"
)
return data


@nvtx.annotate()
def __distortion_correction_proj_discorpy(
data: cp.ndarray,
metadata_path: str,
preview: Dict[str, List[int]],
order: int = 1,
mode: str = "reflect",
):
"""Unwarp a stack of images using a backward model.
Parameters
----------
data : cp.ndarray
3D array.
metadata_path : str
The path to the file containing the distortion coefficients for the
data.
preview : Dict[str, List[int]]
A dict containing three key-value pairs:
- a list containing the `start` value of each dimension
- a list containing the `stop` value of each dimension
- a list containing the `step` value of each dimension
order : int, optional.
The order of the spline interpolation.
mode : {'reflect', 'grid-mirror', 'constant', 'grid-constant', 'nearest',
'mirror', 'grid-wrap', 'wrap'}, optional
To determine how to handle image boundaries.
Returns
-------
cp.ndarray
3D array. Distortion-corrected image(s).
"""

# Check if it's a stack of 2D images, or only a single 2D image
if len(data.shape) == 2:
data = cp.expand_dims(data, axis=0)
Expand Down
21 changes: 0 additions & 21 deletions httomolibgpu/prep/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from httomolibgpu import cupywrapper

cp = cupywrapper.cp
nvtx = cupywrapper.nvtx
cupy_run = cupywrapper.cupy_run

from unittest.mock import Mock
Expand Down Expand Up @@ -75,26 +74,6 @@ def normalize(
cp.ndarray
Normalised 3D tomographic data as a CuPy array.
"""
if cupywrapper.cupy_run:
return __normalize(
data, flats, darks, cutoff, minus_log, nonnegativity, remove_nans
)
else:
print("normalize won't be executed because CuPy is not installed")
return data


@nvtx.annotate()
def __normalize(
data: cp.ndarray,
flats: cp.ndarray,
darks: cp.ndarray,
cutoff: float = 10.0,
minus_log: bool = True,
nonnegativity: bool = False,
remove_nans: bool = True,
) -> cp.ndarray:

_check_valid_input(data, flats, darks)

dark0 = cp.empty(darks.shape[1:], dtype=float32)
Expand Down
48 changes: 1 addition & 47 deletions httomolibgpu/prep/phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
from httomolibgpu import cupywrapper

cp = cupywrapper.cp
nvtx = cupywrapper.nvtx
cupy_run = cupywrapper.cupy_run

from unittest.mock import Mock

if cupy_run:
from httomolibgpu.cuda_kernels import load_cuda_module
from cupyx.scipy.fft import fft2, ifft2, fftshift
Expand Down Expand Up @@ -98,36 +98,6 @@ def paganin_filter_savu(
cp.ndarray
The stack of filtered projections.
"""
if cupywrapper.cupy_run:
return __paganin_filter_savu(
data,
ratio,
energy,
distance,
resolution,
pad_y,
pad_x,
pad_method,
increment,
)
else:
print("__paganin_filter_savu won't be executed because CuPy is not installed")
return data


@nvtx.annotate()
def __paganin_filter_savu(
data: cp.ndarray,
ratio: float = 250.0,
energy: float = 53.0,
distance: float = 1.0,
resolution: float = 1.28,
pad_y: int = 100,
pad_x: int = 100,
pad_method: str = "edge",
increment: float = 0.0,
) -> cp.ndarray:

# Check the input data is valid
if data.ndim != 3:
raise ValueError(
Expand Down Expand Up @@ -321,22 +291,6 @@ def paganin_filter_tomopy(
cp.ndarray
The 3D array of Paganin phase-filtered projection images.
"""
if cupywrapper.cupy_run:
return __paganin_filter_tomopy(tomo, pixel_size, dist, energy, alpha)
else:
print("paganin_filter_tomopy won't be executed because CuPy is not installed")
return tomo


@nvtx.annotate()
def __paganin_filter_tomopy(
tomo: cp.ndarray,
pixel_size: float = 1e-4,
dist: float = 50.0,
energy: float = 53.0,
alpha: float = 1e-3,
) -> cp.ndarray:

# Check the input data is valid
if tomo.ndim != 3:
raise ValueError(
Expand Down
Loading

0 comments on commit 023bef6

Please sign in to comment.