lezargus.library.array module

lezargus.library.array module#

Collection of array or image manipulation functions.

If there are any functions which are done on arrays (or anything that is just an array under the hood), we usually group it here. Moreover, functions which would otherwise operate on images are also placed here. As images are just arrays under the hood (and to avoid conflict with /lezargus/container/image.py), image manipulation functions are kept here too.

Note that all of these functions follow the axes convention of indexing being (x, y, lambda). If a cube is not of this shape, then it will likely return erroneous results, but, the functions themselves cannot detect this.

lezargus.library.array.bin_cube_array_spatially(cube: hint.NDArray, x_bin: int, y_bin: int, mode: str = 'add') hint.NDArray[source]#

Bin a cube spatially into super pixels.

We only bin the cube in the spatial directions, the spectral direction is not touched.

Parameters:
  • cube (ndarray) – The data cube to binned.

  • x_bin (int) – The number of pixels in the x-direction to bin over per super pixel.

  • y_bin (int) – The number of pixels in the y-direction to bin over per super pixel.

  • mode (string, default = "add") –

    The mode to combine the data.

    • add : Add the pixels together.

    • mean : Use the mean of the pixels.

Returns:

binned_image – The data cube after binning.

Return type:

ndarray

lezargus.library.array.bin_image_array(image: hint.NDArray, x_bin: int, y_bin: int, mode: str = 'add') hint.NDArray[source]#

Bin an image by using integer super pixels.

A lot of inspiration for this function is from here: https://scipython.com/blog/binning-a-2d-array-in-numpy/

Parameters:
  • image (ndarray) – The input image/array to binned.

  • x_bin (int) – The number of pixels in the x-direction to bin over per super pixel.

  • y_bin (int) – The number of pixels in the y-direction to bin over per super pixel.

  • mode (string, default = "add") –

    The mode to combine the data.

    • add : Add the pixels together.

    • mean : Use the mean of the pixels.

Returns:

binned_image – The image/array after binning.

Return type:

ndarray