Skip to content

Gradient Energy¤

get_GE

dLuxToliman.gradient_energy.get_GE(array) ¤

Calculates the spatial gradient energy of the array.

Parameters:

Name Type Description Default
array Array

The array to calculate the gradient energy for.

required

Returns:

Name Type Description
array Array

The array of gradient energies.

Source code in dLuxToliman/gradient_energy.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def get_GE(array: Array) -> Array:
    """
    Calculates the spatial gradient energy of the array.

    Parameters
    ----------
    array : Array
        The array to calculate the gradient energy for.

    Returns
    -------
    array : Array
        The array of gradient energies.
    """
    grads_vec = np.gradient(array)
    return np.hypot(grads_vec[0], grads_vec[1])
get_RGE

dLuxToliman.gradient_energy.get_RGE(array, epsilon=1e-08) ¤

Calculates the spatial radial gradient energy of the array.

Parameters:

Name Type Description Default
array Array

The array to calculate the radial gradient energy for.

required
epsilon float

A small value added to the radial values to help with gradient stability.

1e-08

Returns:

Name Type Description
array Array

The array of radial gradient energies.

Source code in dLuxToliman/gradient_energy.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def get_RGE(array: Array, epsilon: float = 1e-8) -> Array:  # TODO : Add epsilon
    """
    Calculates the spatial radial gradient energy of the array.

    Parameters
    ----------
    array : Array
        The array to calculate the radial gradient energy for.
    epsilon : float
        A small value added to the radial values to help with gradient
        stability.

    Returns
    -------
    array : Array
        The array of radial gradient energies.
    """
    npix = array.shape[0]
    positions = dlu.pixel_coords(npix, npix)
    grads_vec = np.gradient(array)

    xnorm = positions[1] * grads_vec[0]
    ynorm = positions[0] * grads_vec[1]

    return np.square(xnorm + ynorm)
get_RWGE

dLuxToliman.gradient_energy.get_RWGE(array, epsilon=1e-08) ¤

Calculates the spatial radially weighted gradient energy of the array.

Parameters:

Name Type Description Default
array Array

The array to calculate the radially weighted gradient energy for.

required
epsilon float

A small value added to the radially weighted values to help with gradient stability.

1e-08

Returns:

Name Type Description
array Array

The array of radial radially weighted energies.

Source code in dLuxToliman/gradient_energy.py
53
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
def get_RWGE(array: Array, epsilon: float = 1e-8) -> Array:
    """
    Calculates the spatial radially weighted gradient energy of the array.

    Parameters
    ----------
    array : Array
        The array to calculate the radially weighted gradient energy for.
    epsilon : float
        A small value added to the radially weighted values to help with
        gradient stability.

    Returns
    -------
    array : Array
        The array of radial radially weighted energies.
    """
    npix = array.shape[0]
    positions = dlu.pixel_coords(npix, npix)
    radii = dlu.pixel_coords(npix, npix, polar=True)[0]
    radii_norm = positions / (radii + epsilon)
    grads_vec = np.gradient(array)

    xnorm = radii_norm[1] * grads_vec[0]
    ynorm = radii_norm[0] * grads_vec[1]

    return np.square(xnorm + ynorm)
get_radial_mask

dLuxToliman.gradient_energy.get_radial_mask(npixels, rmin, rmax) ¤

Calculates a binary radial mask, masking out radii below rmin, and above rmax.

Parameters:

Name Type Description Default
npixels int

The linear size of the array.

required
rmin Array

The inner radius to mask out.

required
rmax Array

The outer radius to mask out.

required

Returns:

Name Type Description
mask Array

A mask with the values below rmin and above rmax masked out.

Source code in dLuxToliman/gradient_energy.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def get_radial_mask(npixels: int, rmin: Array, rmax: Array) -> Array:
    """
    Calculates a binary radial mask, masking out radii below rmin, and above
    rmax.

    Parameters
    ----------
    npixels : int
        The linear size of the array.
    rmin : Array
        The inner radius to mask out.
    rmax : Array
        The outer radius to mask out.

    Returns
    -------
    mask: Array
        A mask with the values below rmin and above rmax masked out.
    """
    radii = dlu.pixel_coords(npixels, npixels, polar=True)[0]
    return np.asarray((radii < rmax) & (radii > rmin), dtype=float)