lezargus.container.parent module#

Parent class for the containers to implement arithmetic and other functions.

The Astropy NDArrayData arithmetic class is not wavelength aware, and so we implement our own class with similar functionality to it to allow for wavelength aware operations. Unlike specutils, the interpolation for doing arithmetic operations of spectral classes of different wavelength solutions must be explicit. This is to prevent errors from mis-matched spectra being operated on.

class lezargus.container.parent.LezargusContainerArithmetic(wavelength: ndarray, data: ndarray, uncertainty: ndarray, wavelength_unit: Unit, data_unit: Unit, mask: ndarray, flags: ndarray, header: dict)[source]#

Bases: object

Lezargus wavelength-aware arithmetic.

This is the class which allows for the arithmetic behind the scenes to work with wavelength knowledge. All we do is overwrite the NDDataArray arithmetic functions to perform wavelength checks and pass it through without wavelength issues.

wavelength#

The wavelength of the spectra. The unit of wavelength is typically in microns; but, check the wavelength_unit value.

Type:

ndarray

data#

The data or flux of the spectra cube. The unit of the flux is typically in flam; but, check the data_unit value.

Type:

ndarray

uncertainty#

The uncertainty in the data. The unit of the uncertainty is the same as the flux value; per uncertainty_unit.

Type:

ndarray

wavelength_unit#

The unit of the wavelength array.

Type:

Astropy Unit

data_unit#

The unit of the data array.

Type:

Astropy Unit

uncertainty_unit#

The unit of the uncertainty array. This unit is the same as the data unit.

Type:

Astropy Unit

mask#

A mask of the data, used to remove problematic areas. Where True, the values of the data is considered masked.

Type:

ndarray

flags#

Flags of the data. These flags store metadata about the data.

Type:

ndarray

header#

The header information, or metadata in general, about the data.

Type:

Header

__add__(operand: Self) Self[source]#

Perform an addition operation.

Parameters:

operand (Self-like) – The container object to add to this.

Returns:

result – A copy of this object with the resultant calculations done.

Return type:

Self-like

__init__(wavelength: ndarray, data: ndarray, uncertainty: ndarray, wavelength_unit: Unit, data_unit: Unit, mask: ndarray, flags: ndarray, header: dict) None[source]#

Construct a wavelength-aware NDDataArray for arithmetic.

Parameters:
  • wavelength (ndarray) – The wavelength of the spectra. The unit of wavelength is typically in microns; but, check the wavelength_unit value.

  • data (ndarray) – The data of the spectra cube. The unit of the flux is typically in flam; but, check the data_unit value.

  • uncertainty (ndarray) – The uncertainty in the data of the spectra. The unit of the uncertainty is the same as the data value; per uncertainty_unit.

  • wavelength_unit (Astropy Unit) – The unit of the wavelength array.

  • data_unit (Astropy Unit) – The unit of the data array.

  • mask (ndarray) – A mask of the data, used to remove problematic areas. Where True, the values of the data is considered masked.

  • flags (ndarray) – Flags of the data. These flags store metadata about the data.

  • header (Header, default = None) – A set of header data describing the data. Note that when saving, this header is written to disk with minimal processing. We highly suggest writing of the metadata to conform to the FITS Header specification as much as possible.

Return type:

None

__justify_arithmetic_operation(operand: Self | float) bool#

Justify operations between two objects is valid.

Operations done between different instances of the Lezargus data structure need to keep in mind the wavelength dependance of the data. We implement simple checks here to formalize if an operation between this object, and some other operand, can be performed.

Parameters:

operand (Self-like or number) – The container object that we have an operation to apply with.

Returns:

  • justification (bool) – The state of the justification test. If it is True, then the operation can continue, otherwise, False.

  • .. note:: – This function will also raise exceptions upon discovery of incompatible objects. Therefore, the False return case is not really that impactful.

__mul__(operand: Self) Self[source]#

Perform a multiplication operation.

Parameters:

operand (Self-like) – The container object to add to this.

Returns:

result – A copy of this object with the resultant calculations done.

Return type:

Self-like

__pow__(operand: Self) Self[source]#

Perform a true division operation.

Parameters:

operand (Self-like) – The container object to add to this.

Returns:

result – A copy of this object with the resultant calculations done.

Return type:

Self-like

__sub__(operand: Self) Self[source]#

Perform a subtraction operation.

Parameters:

operand (Self-like) – The container object to add to this.

Returns:

result – A copy of this object with the resultant calculations done.

Return type:

Self-like

__truediv__(operand: Self) Self[source]#

Perform a true division operation.

Parameters:

operand (Self-like) – The container object to add to this.

Returns:

result – A copy of this object with the resultant calculations done.

Return type:

Self-like

classmethod _read_fits_file(filename: str) Self[source]#

Read in a FITS file into an object.

This is a wrapper around the main FITS class for uniform handling. The respective containers should wrap around this for container-specific handling and should not overwrite this function.

Parameters:

filename (str) – The file to read in.

Returns:

container – The Lezargus container which was read into the file.

Return type:

Self-like

_write_fits_file(filename: str, overwrite: bool = False) None[source]#

Write a FITS object to disk..

This is a wrapper around the main FITS class for uniform handling. The respective containers should wrap around this for container-specific handling and should not overwrite this function.

Parameters:
  • filename (str) – The file to be written out.

  • overwrite (bool, default = False) – If True, overwrite any file conflicts.

Return type:

None