curvelets.utils package¶
- curvelets.utils.apply_along_wedges(c_struct, fun)¶
Apply functions across a UDCT curvelet-like structure
- Parameters:
c_struct (list[list[list[
U]]]) – Input curvelet structure. First index: scales, second: directions, third: wedges.fun (Callable[[
U, int, int, int, int, int, int],T]) – Function to apply to each item in the structure. The function’s arguments are respectively: item, wedge index, direction index, scale index, number of wedges in direction, number of directions in scale, number of scales.
- Returns:
Result of applying the function to each item.
- Return type:
list[list[list[
T]]]
Examples
>>> import numpy as np >>> from curvelets.numpy import UDCT >>> from curvelets.utils import apply_along_wedges >>> x = np.zeros((32, 32)) >>> C = UDCT(x.shape, num_scales=3, wedges_per_direction=3) >>> y = C.forward(x) >>> apply_along_wedges(y, lambda w, *_: w.shape) [[[(16, 16)]], [[(8, 8), (8, 8), (8, 8)], [(8, 8), (8, 8), (8, 8)]], [[(16, 8), (16, 8), (16, 8), (16, 8), (16, 8), (16, 8)], [(8, 16), (8, 16), (8, 16), (8, 16), (8, 16), (8, 16)]]]
- curvelets.utils.array_split_nd(ary, *args)¶
Split an array into multiple sub-arrays recursively, possibly unevenly.
- Parameters:
ary (
NDArray[D]) – Input array.args (
int, optional) – Number of splits for each axis ofary. Axis 0 will be split intoargs[0]subarrays, axis 1 will be intoargs[1]subarrays, etc. An axis of lengthl = ary.shape[axis]that should be split inton = args[axis]sections, will returnl % nsub-arrays of sizel//n + 1and the rest of sizel//n.
- Returns:
Recursive lists of lists of
NDArray[D]. The number of depth of nesting is equivalent to the number arguments in args.- Return type:
list[Any]
See also
numpy.array_splitSplit an array into multiple sub-arrays.
Examples
>>> from curvelets.utils import array_split_nd >>> ary = np.outer(1 + np.arange(2), 2 + np.arange(3)) array([[2, 3, 4], [4, 6, 8]]) >>> array_split_nd(ary, 2, 3) [[array([[2]]), array([[3]]), array([[4]])], [array([[4]]), array([[6]]), array([[8]])]] >>> ary = np.outer(np.arange(3), np.arange(5)) >>> array_split_nd(ary, 2, 3) [[array([[0, 0], [0, 1]]), array([[0, 0], [2, 3]]), array([[0], [4]])], [array([[0, 2]]), array([[4, 6]]), array([[8]])]]
- curvelets.utils.deepflatten(lst)¶
Flatten arbitrarily nested lists
- Parameters:
lst (list[Any]) – Nested list of lists.
- Yields:
Iterator[Iterable[Any]] – Elements in
lstin order.- Return type:
Examples
>>> from curvelets.utils import deepflatten >>> list(deepflatten([[[[[[1],2,[[3,4]]]]]]])) [1, 2, 3, 4]
- curvelets.utils.make_r(shape, exponent=1, origin=None)¶
Compute radial distance array from origin.
Creates an array where each element contains the radial distance from a specified origin point, raised to the given exponent. This function is primarily used in example scripts for generating test patterns.
- Parameters:
- Returns:
Array of radial distances from origin, raised to the exponent.
- Return type:
Examples
>>> import numpy as np >>> from curvelets.utils import make_r >>> r = make_r((5, 5), exponent=1) >>> r.shape (5, 5) >>> r[2, 2] # Center point should be 0 0.0 >>> r = make_r((3, 3), exponent=2, origin=(0, 0)) >>> r[0, 0] # Origin point should be 0 0.0
- curvelets.utils.make_zone_plate(shape, amplitude=1.0, phase=0.0)¶
Generate a zone plate test pattern.
Creates a zone plate pattern, which is a circular pattern of concentric rings with alternating intensity. This is commonly used as a test image for frequency domain analysis. This function is primarily used in example scripts.
- Parameters:
- Returns:
Zone plate pattern array with values in the range [-amplitude, amplitude].
- Return type:
Examples
>>> import numpy as np >>> from curvelets.utils import make_zone_plate >>> zone_plate = make_zone_plate((64, 64)) >>> zone_plate.shape (64, 64) >>> np.min(zone_plate) >= -1.0 True >>> np.max(zone_plate) <= 1.0 True >>> zone_plate = make_zone_plate((128, 128), amplitude=2.0, phase=np.pi/2) >>> zone_plate.shape (128, 128)
- curvelets.utils.ndargmax(ary)¶
N-dimensional argmax of array.
- Parameters:
ary (
NDArray) – Input array.- Returns:
N-dimensional index of the maximum of
ary.- Return type:
tuple[numpy.intp, …]
Examples
>>> import numpy as np >>> from curvelets.utils import ndargmax >>> x = np.zeros((10, 10, 10)) >>> x[1, 1, 1] = 1.0 >>> ndargmax(x) (1, 1, 1)
- curvelets.utils.normal_vector_field(data, rows, cols, dx=1, dy=1)¶
Creates equally spaced vectors normal to the data.
- Parameters:
- Returns:
Normal vectors shaped
(nrows, ncols, 2)- Return type: