Utilities#

Utilities used by the aomodel package.

  • vec_to_img and img_to_vec convert quickly from 2-D arrays (images) to 1-D vectors (rasterized images). These functions are used in ReVAR and Metrics.

  • parabolic_interpolation_max is used in Long-Range AutoRegression when finding a cut-off frequency.

Functions#

Functions:

vec_to_img(data_vec, mask)

Reshapes row vector(s) into 2-D array(s) ("images") in raster order using a mask.

img_to_vec(image_data, mask)

Reshapes 2-D array(s) ("image(s)") into row vector(s) in raster order using a mask.

parabolic_interpolation_max(input_vals, ...)

Uses parabolic interpolation to estimate the input to a function which gives the largest output.

aomodel.utils.img_to_vec(image_data, mask)[source]#

Reshapes 2-D array(s) (“image(s)”) into row vector(s) in raster order using a mask. The function can reshape either a single image into a single vector or a 3-D array (containing a sequence of images) into a sequence of rows vectors (i.e., a 2-D array).

Parameters:
  • image_data (ndarray) – numpy 2-D or 3-D array containing the images.

    • If image_data is 2-D, a single image is reshaped into a single vector. In this case, the input must have shape (image height, image width).

    • If image_data is 3-D, a sequence of images is reshaped into a sequence of row vectors. In this case, the input must have shape (number of images, image height, image width).

  • mask (ndarray) – numpy 2-D boolean array of shape (image height, image width) indicating which 2-D indices of each time-step correspond to valid pixel values. Only indices set to “True” will be included in the output vectors.

Returns:

output_vector (ndarray) – numpy 1-D or 2-D array with the vector(s) (i.e., flattened image(s)). If image_data is 2-D, only a single 1-D array is returned. If image_data is 3-D, a 2-D array of shape (number of images, image dimensionality) is returned.

aomodel.utils.parabolic_interpolation_max(input_vals, function_vals)[source]#

Uses parabolic interpolation to estimate the input to a function which gives the largest output.

Parameters:
  • input_vals (ndarray) – numpy 1-D array of input values.

  • function_vals (ndarray) – numpy 1-D array of function values at the corresponding inputs.

Returns:

max_input (float) – the estimate of the input resulting in the peak function value.

aomodel.utils.vec_to_img(data_vec, mask)[source]#

Reshapes row vector(s) into 2-D array(s) (“images”) in raster order using a mask. The values of the returned data outside of the mask are set to float(“nan”). The function can convert either a vector to a single image or a 2-D array (containing a sequence of vectors) to a sequence of images (in a 3-D array).

Parameters:
  • data_vec (ndarray) – numpy 1-D or 2-D array with the input vector(s).

    • If data_vec is 1-D, a single vector is converted to a single image.

    • If data_vec is 2-D, it has shape (number of images, image dimensionality) and contains multiple vectors.

  • mask (ndarray) – numpy 2-D boolean array of shape (image height, image width) indicating which 2-D indices of each time-step correspond to valid pixel values. The number of values in the mask that are set to “True” must equal the dimensionality of the input data vector(s).

Returns:

output_image (ndarray) – numpy 2-D or 3-D array containing the image(s). If data_vec is 1-D, only a single 2-D array of shape (image height, image width) is returned. If data_vec is 2-D, a 3-D array of shape (number of images, image height, image width) is returned.


Disclaimer: Approved for public release; distribution is unlimited. Public Affairs release approval # AFRL-2026-1309.