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 | None = None, data_unit: Unit | None = None, pixel_scale: float | None = None, slice_scale: float | None = None, mask: ndarray | None = None, flags: ndarray | None = None, header: Header | None = None)[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 meters; 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 W m^-2 m^-1; 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
- pixel_scale#
The pixel plate scale of the image, in radians per pixel. Typically, this is the scale in the E-W or “x” direction. See
slice_scale
for the N-S or “y” direction.- Type:
float
- slice_scale#
The pixel slice scale of the image, in radians per slice. Typically, this is the scale in the N-S or “y” direction. See
pixel_scale
for the E-W or “x” direction.- Type:
float
- 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 | None = None, data_unit: Unit | None = None, pixel_scale: float | None = None, slice_scale: float | None = None, mask: ndarray | None = None, flags: ndarray | None = None, header: Header | None = None) None [source]#
Construct a wavelength-aware Lezargus data container.
- Parameters:
wavelength (ndarray) – The wavelength axis of the spectral component of the data, if any. The unit of wavelength is typically in meters; but, check the
wavelength_unit
value.data (ndarray) – The data stored in this container. The unit of the flux is typically in W m^-2 m^-1; 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. If None, we assume unit-less.
data_unit (Astropy Unit) – The unit of the data array. If None, we assume unit-less.
pixel_scale (float, default = None) – The E-W, “x” dimension, pixel plate scale of the spatial component, if any. Must be in radians per pixel. Scale is None if none is provided.
slice_scale (float, default = None) – The N-S, “y” dimension, pixel slice scale of the spatial component, if any. Must be in radians per pixel. Scale is None if none is provided.
mask (ndarray, default = None) – A mask of the data, used to remove problematic areas. Where True, the values of the data is considered masked. If None, we assume the mask is all clear.
flags (ndarray, default = None) – Flags of the data. These flags store metadata about the data. If None, we assume that there are no harmful flags.
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. If None, we just use an empty header.
- 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 float) – 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 multiply 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 exponentiate 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 subtract 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 true divide 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