Skip to content

Commit

Permalink
Added Pep 484 Type Hints to the code (#3)
Browse files Browse the repository at this point in the history
* Added Pep 484 Type Hints to the code
  • Loading branch information
SZanko committed Jan 15, 2021
1 parent e58cd96 commit 74d0231
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 31 deletions.
4 changes: 2 additions & 2 deletions radontea/_alg_art.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np


def art(sinogram, angles, initial=None, iterations=1,
count=None, max_count=None):
def art(sinogram: np.ndarray, angles: np.ndarray, initial: np.ndarray = None,
iterations: int = 1, count=None, max_count=None) -> np.ndarray:
"""Algebraic Reconstruction Technique
The Algebraic Reconstruction Technique (ART) iteratively
Expand Down
17 changes: 10 additions & 7 deletions radontea/_alg_bpj.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
from . import _threed, util


def backproject(sinogram, angles, filtering="ramp", weight_angles=True,
padding=True, padval=0, count=None, max_count=None, verbose=0):
def backproject(sinogram: np.ndarray, angles: np.ndarray,
filtering: str = "ramp", weight_angles: bool = True,
padding: bool = True, padval: float = 0, count=None,
max_count=None, verbose: int = 0) -> np.ndarray:
r"""2D backprojection algorithm
Computes the inverse of the Radon transform using filtered
Expand Down Expand Up @@ -105,8 +107,8 @@ def backproject(sinogram, angles, filtering="ramp", weight_angles=True,
pad = 0
order = ln

padl = np.int(np.ceil(pad / 2))
padr = np.int(pad - padl)
padl = np.int32(np.ceil(pad / 2))
padr = np.int32(pad - padl)

if padval is None:
if verbose > 0:
Expand Down Expand Up @@ -190,9 +192,10 @@ def backproject(sinogram, angles, filtering="ramp", weight_angles=True,
return outarr


def backproject_3d(sinogram, angles, filtering="ramp", weight_angles=True,
padding=True, padval=0, count=None, max_count=None,
ncpus=None):
def backproject_3d(sinogram: np.ndarray, angles: np.ndarray,
filtering: str = "ramp", weight_angles: bool = True,
padding: bool = True, padval: float = 0, count=None,
max_count=None, ncpus=None) -> np.ndarray:
"""Convenience wrapper for 3D backprojection reconstruction
See :func:`backproject` for parameter definitions. The additional
Expand Down
10 changes: 6 additions & 4 deletions radontea/_alg_fmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
from . import _threed


def fourier_map(sinogram, angles, intp_method="cubic",
count=None, max_count=None):
def fourier_map(sinogram: np.ndarray, angles: np.ndarray,
intp_method: str = "cubic",
count=None, max_count=None) -> np.ndarray:
"""2D Fourier mapping with the Fourier slice theorem
Computes the inverse of the Radon transform using Fourier
Expand Down Expand Up @@ -184,8 +185,9 @@ def fourier_map(sinogram, angles, intp_method="cubic",
return f.real


def fourier_map_3d(sinogram, angles, intp_method="cubic",
count=None, max_count=None, ncpus=None):
def fourier_map_3d(sinogram: np.ndarray, angles: np.ndarray,
intp_method: str = "cubic",
count=None, max_count=None, ncpus=None) -> np.ndarray:
"""Convenience wrapper for 3D Fourier mapping reconstruction
See :func:`fourier_map` for parameter definitions. The additional
Expand Down
3 changes: 2 additions & 1 deletion radontea/_alg_int.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy as np


def integrate(sinogram, angles, count=None, max_count=None):
def integrate(sinogram: np.ndarray, angles: np.ndarray, count=None,
max_count=None) -> np.ndarray:
"""2D sum-reconstruction with the Fourier slice theorem
Computes the inverse of the Radon transform by computing the
Expand Down
4 changes: 2 additions & 2 deletions radontea/_alg_sart.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np


def sart(sinogram, angles, initial=None, iterations=1,
count=None, max_count=None):
def sart(sinogram: np.ndarray, angles: np.ndarray, initial: np.ndarray = None,
iterations: int = 1, count=None, max_count=None):
"""Simultaneous Algebraic Reconstruction Technique
Expand Down
11 changes: 6 additions & 5 deletions radontea/_rdn_fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import scipy.ndimage


def get_det_coords(size, spacing):
def get_det_coords(size: int, spacing: float) -> np.ndarray:
"""Compute pixel-center positions for 2D detector
The centers of the pixels of a detector are usually not aligned to
Expand All @@ -29,7 +29,8 @@ def get_det_coords(size, spacing):
return lat


def get_fan_coords(size, spacing, distance, numang):
def get_fan_coords(size: int, spacing: float, distance: float,
numang: int) -> np.ndarray:
""" Compute equispaced angular coordinates for 2d detector
The centers of the pixels of a detector are usually not aligned to
Expand Down Expand Up @@ -75,9 +76,9 @@ def get_fan_coords(size, spacing, distance, numang):
return angles, latang


def radon_fan(arr, det_size, det_spacing=1, shift_size=1,
lS=1, lD=None, return_ang=False,
count=None, max_count=None):
def radon_fan(arr, det_size: int, det_spacing: float = 1, shift_size: int = 1,
lS=1, lD=None, return_ang: bool = False,
count=None, max_count=None) -> np.ndarray:
r"""Compute the Radon transform for a fan beam geometry
Expand Down
3 changes: 2 additions & 1 deletion radontea/_rdn_prl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import scipy.ndimage


def radon_parallel(arr, angles, count=None, max_count=None,):
def radon_parallel(arr: np.ndarray, angles: np.ndarray,
count=None, max_count=None,) -> np.ndarray:
"""Compute the Radon transform (sinogram) of a circular image.
The :mod:`scipy` Radon transform performs this operation on the
Expand Down
5 changes: 4 additions & 1 deletion radontea/_threed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import numpy as np
import time

from typing import Callable


def do_work(in_queue, out_list, count, max_count):
while True:
Expand All @@ -17,7 +19,8 @@ def do_work(in_queue, out_list, count, max_count):
time.sleep(.01)


def volume_recon(func2d, sinogram=None, angles=None,
def volume_recon(func2d: Callable, sinogram: np.ndarray = None,
angles: np.ndarray = None,
count=None, max_count=None, ncpus=None, **kwargs):
"""Slice-wise 3D inversion of the Radon transform
Expand Down
13 changes: 9 additions & 4 deletions radontea/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
from ._rdn_fan import get_fan_coords
from ._rdn_fan import get_det_coords, radon_fan # noqa F401

from typing import Callable

def fan_rec(linogram, lds, method, stepsize=1, det_spacing=1,
numang=None, count=None, max_count=None, **kwargs):

def fan_rec(linogram: np.ndarray, lds: float, method: Callable, stepsize=1,
det_spacing: float = 1, numang: int = None, count=None,
max_count=None, **kwargs):
"""2D synthetic aperture reconstruction
Computes the inverse of the fan-beam Radon transform using
Expand Down Expand Up @@ -39,8 +42,10 @@ def fan_rec(linogram, lds, method, stepsize=1, det_spacing=1,
return method(sino, angles, **kwargs)


def lino2sino(linogram, lds, stepsize=1, det_spacing=1, numang=None,
retang=False, count=None, max_count=None):
def lino2sino(linogram: np.ndarray, lds: float, stepsize: float = 1,
det_spacing: float = 1, numang: int = None,
retang: bool = False,
count=None, max_count=None) -> np.ndarray:
"""Convert linogram to sinogram for an equispaced detector.
Parameters
Expand Down
6 changes: 3 additions & 3 deletions radontea/logo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from radontea import radon_parallel


def logo(x, y, N):
def logo(x, y, N) -> np.ndarray:
"""Vector representation of radontea logo.
Parameters
Expand Down Expand Up @@ -36,7 +36,7 @@ def logo(x, y, N):
return z


def get_original(N=64):
def get_original(N: int = 64) -> np.ndarray:
"""radontea logo base image"""
x = np.linspace(-N / 2, N / 2, N, endpoint=False)
X = x.reshape(1, -1)
Expand All @@ -46,7 +46,7 @@ def get_original(N=64):
return np.array((z) * 255, dtype=np.uint16)


def get_logo(N=64):
def get_logo(N: int = 64):
"""Return the radontea logo as a 2D NxN array
This function discretizes the vector image representation of the
Expand Down
2 changes: 1 addition & 1 deletion radontea/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np


def compute_angle_weights_1d(angles):
def compute_angle_weights_1d(angles: np.ndarray) -> np.ndarray:
"""
Compute the weight for each angle according to the distance between its
neighbors.
Expand Down

0 comments on commit 74d0231

Please sign in to comment.