lezargus.container.broadcast module#

Functions to properly broadcast one Lezargus container into another.

Sometimes operations are needed to be performed between two dimensions of data structures. We have functions here which serve to convert from one structure to another based on some broadcasting pattern. We properly handle the internal conversions (such as the flags, mask, wavelength, etc) as well based on the input template structure broadcasting to.

lezargus.container.broadcast.broadcast_spectra_to_cube_center(input_spectra: LezargusSpectra, template_cube: LezargusCube, wavelength_mode: str = 'error', allow_even_center: bool = True) LezargusCube[source]#

Make a LezargusCube from a LezargusSpectra via center broadcasting.

We make a LezargusCube, from a provided template, using center broadcasting. Center broadcasting is the provided spectral slice is centered in the cube; all other values are zero (or the blank equivalent for masks and flags). If any side of an image slice of the template cube is even, we can still try to place the image in the center, biasing it towards the lower value corner.

In the case of both the input spectra and provided template cube having different wavelength arrays, we follow the provided mode to handle the different cases. The input template cube only provides the array shapes and the wavelength axis (dependant on the mode); the rest comes from the input spectra.

Parameters:
  • input_spectra (LezargusSpectra) – The input spectra which will be broadcasted to fit the input template cube.

  • template_cube (LezargusCube) – The template cube which will serve as a template to determine the dimensional properties of the resulting broadcasting cube.

  • wavelength_mode (str, default = "error") –

    The mode to handle possible wavelength array conflicts between the spectra and the cube. The available options are:

    • ”spectra” : Prefer the spectra’s wavelength array; the cube’s wavelength is ignored.

    • ”cube” : Prefer the cube’s wavelength array; the spectra is interpolated to align to the new wavelength.

    • ”error” : We log an error and return None.

  • allow_even_center (bool, default = True) – If True, and if any axis of an image slice is even, a warning is logged and the spectra is put it as close to the center as possible. If False, instead, an exception is raised.

Returns:

broadcast_cube – The LezargusCube after the spectra was center broadcast spatially. Any header information came from first the spectra then the cube.

Return type:

LezargusCube

lezargus.container.broadcast.broadcast_spectra_to_cube_uniform(input_spectra: LezargusSpectra, template_cube: LezargusCube, wavelength_mode: str = 'error') LezargusCube[source]#

Make a LezargusCube from a LezargusSpectra via uniform broadcasting.

We make a LezargusCube, from a provided template, using uniform broadcasting. Uniform broadcasting is where all spectral slices, within the cube, are all the same for a uniform spatial distribution of the spectra, which is in this case the provided input spectra.

In the case of both the input spectra and provided template cube having different wavelength arrays, we follow the provided mode to handle the different cases. The input template cube only provides the array shapes and the wavelength axis (dependant on the mode); the rest comes from the input spectra.

Parameters:
  • input_spectra (LezargusSpectra) – The input spectra which will be broadcasted to fit the input template cube.

  • template_cube (LezargusCube) – The template cube which will serve as a template to determine the dimensional properties of the resulting broadcasting cube.

  • wavelength_mode (str, default = "error") –

    The mode to handle possible wavelength array conflicts between the spectra and the cube. The available options are:

    • ”spectra” : Prefer the spectra’s wavelength array; the cube’s wavelength is ignored.

    • ”cube” : Prefer the cube’s wavelength array; the spectra is interpolated to align to the new wavelength.

    • ”error” : We log an error. We still attempt to figure it out, defaulting to the spectra’s wavelength array.

Returns:

broadcast_cube – The LezargusCube after the spectra was uniformly broadcast spatially. Any header information came from first the spectra then the cube.

Return type:

LezargusCube