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 of ary. Axis 0 will be split into args[0] subarrays, axis 1 will be into args[1] subarrays, etc. An axis of length l = ary.shape[axis] that should be split into n = args[axis] sections, will return l % n sub-arrays of size l//n + 1 and the rest of size l//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_split

Split 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 lst in order.

Return type:

Iterable[Any]

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:
  • shape (tuple[int, ...]) – Shape of the output array.

  • exponent (float, optional) – Exponent to apply to the radial distance. Default is 1.

  • origin (tuple[int, ...] | None, optional) – Origin point for distance calculation. If None, uses the center of the array. Default is None.

Returns:

Array of radial distances from origin, raised to the exponent.

Return type:

NDArray [np.floating]

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:
  • shape (tuple[int, ...]) – Shape of the output array.

  • amplitude (float, optional) – Amplitude of the cosine pattern. Default is 1.0.

  • phase (float, optional) – Phase offset for the cosine pattern. Default is 0.0.

Returns:

Zone plate pattern array with values in the range [-amplitude, amplitude].

Return type:

NDArray [np.floating]

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:
  • data (NDArray) – Input data. Plot with plt.imshow (data.T).

  • rows (int) – Number of rows.

  • cols (int) – Number of columns.

  • dx (float, optional) – Spacing in the axis=0 direction, by default 1

  • dy (float, optional) – Spacing in the axis=1 direction, by default 1

Returns:

Normal vectors shaped (nrows, ncols, 2)

Return type:

NDArray [numpy.float64]