Skip to content

Interpolation Utility Functions

This module contains basic paraxial interpolation functions.

scale

Paraxially interpolates an array based on the sampling ratio, and npixels_out.

TODO: Check if a half-pixel offset is produced

Parameters:

Name Type Description Default
array Array

The input field to interpolate, either in amplitude and phase, or real and imaginary.

required
npixels int

The number of pixel in the output array.

required
ratio float

The relative input to output scales, TODO: does 2 make it bigger or smaller? i.e. input scale/output scale. <- get this right.

required
order int = 1

The interpolation order to use. Can be 0 or 1.

1

Returns:

Name Type Description
array Array

The interpolated array.

Source code in src/dLux/utils/interpolation.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def scale(array: Array, npixels: int, ratio: float, order: int = 1) -> Array:
    """
    Paraxially interpolates an array based on the sampling ratio, and npixels_out.

    # TODO: Check if a half-pixel offset is produced

    Parameters
    ----------
    array : Array
        The input field to interpolate, either in amplitude and phase, or real
        and imaginary.
    npixels : int
        The number of pixel in the output array.
    ratio : float
        The relative input to output scales, TODO: does 2 make it bigger or
        smaller? i.e. input scale/output scale. <- get this right.
    order : int = 1
        The interpolation order to use. Can be 0 or 1.

    Returns
    -------
    array : Array
        The interpolated array.
    """
    # Get coords arrays
    npixels_in = array.shape[-1]
    # TODO: Update with array_coordinates
    coordinates = generate_coordinates(npixels_in, npixels, ratio)
    return map_coordinates(array, coordinates, order=order)
rotate

Rotates an array by the angle, using interpolation.

Parameters:

Name Type Description Default
array Array

The array to rotate.

required
angle (Array, radians)

The angle to rotate the array by.

required
order int = 1

The interpolation order to use. Can be 0 or 1.

1

Returns:

Name Type Description
array Array

The rotated array.

Source code in src/dLux/utils/interpolation.py
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
def rotate(array: Array, angle: Array, order: int = 1) -> Array:
    """
    Rotates an array by the angle, using interpolation.

    Parameters
    ----------
    array : Array
        The array to rotate.
    angle : Array, radians
        The angle to rotate the array by.
    order : int = 1
        The interpolation order to use. Can be 0 or 1.

    Returns
    -------
    array : Array
        The rotated array.
    """

    # TODO: Use rotate_coords
    def _rotate(coordinates: Array, rotation: Array) -> Array:
        x, y = coordinates[0], coordinates[1]
        new_x = np.cos(-rotation) * x + np.sin(-rotation) * y
        new_y = -np.sin(-rotation) * x + np.cos(-rotation) * y
        return np.array([new_x, new_y])

    # Get coordinates
    npixels = array.shape[0]
    centre = (npixels - 1) / 2
    coordinates = dlu.nd_coords((npixels, npixels), indexing="ij")
    coordinates_rotated = _rotate(coordinates, angle) + centre

    # Interpolate
    return map_coordinates(array, coordinates_rotated, order=order)