lezargus.library.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.library.container.parent.LezargusContainerArithmetic(wavelength: hint.NDArray | float, data: hint.NDArray | float, uncertainty: hint.NDArray | float | None, wavelength_unit: hint.Unit | str | None = None, data_unit: hint.Unit | str | None = None, spectral_scale: float | None = None, pixel_scale: float | None = None, slice_scale: float | None = None, mask: hint.NDArray | None = None, flags: hint.NDArray | None = None, header: hint.Header | dict | None = None)[source]#

Bases: object

Lezargus wavelength-aware arithmetic for the major containers.

This is the class which allows for the arithmetic behind the scenes to work with wavelength knowledge.

wavelength#
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

spectral_scale#

The spectral scale of the image, as a resolution, in wavelength separation per pixel. The point spacing on the wavelength axis is not always the spectral resolution.

Type:

float

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: float | hint.Self) hint.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: hint.NDArray | float, data: hint.NDArray | float, uncertainty: hint.NDArray | float | None, wavelength_unit: hint.Unit | str | None = None, data_unit: hint.Unit | str | None = None, spectral_scale: float | None = None, pixel_scale: float | None = None, slice_scale: float | None = None, mask: hint.NDArray | None = None, flags: hint.NDArray | None = None, header: hint.Header | dict | 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.

  • spectral_scale (float, default = None) – The spectral scale, or spectral resolution, of the spectral component, if any. Must be in meters per pixel. Scale is None if none is provided.

  • 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

__mul__(operand: float | hint.Self) hint.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: float | hint.Self) hint.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

__radd__(operand: hint.Self) hint.Self[source]#

Perform an addition operation, commutative with __add__.

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

__rmul__(operand: hint.Self) hint.Self[source]#

Perform a multiplication operation, commutative with __mul__.

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

__sub__(operand: float | hint.Self) hint.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: float | hint.Self) hint.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

__verify_arithmetic_operation(operand: hint.Self | float) bool#

Verify operations between two objects is valid.

Operations done between different instances of the Lezargus data structure need to keep in mind the wavelength dependence 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:

  • verified (bool) – The state of the verification 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.

_data: hint.NDArray#

Internal variable for storing the data array. Use data instead.

classmethod _read_fits_file(filename: str) hint.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

_uncertainty: hint.NDArray#

Internal variable for storing the uncertainty array. Use uncertainty instead.

_wavelength: hint.NDArray#

Internal variable for storing the wavelength array. Use wavelength instead.

_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

property data: hint.NDArray#

Get the data array.

The data of the spectra. The unit of data is typically in meters; but, check the data_unit value.

Parameters:

None

Returns:

data – The data array of the container.

Return type:

NDArray

to_unit(data_unit: str | hint.Unit | None = None, wavelength_unit: str | hint.Unit | None = None) hint.Self[source]#

Convert the units of the current data to the new set of units.

This function only does simple unit conversion. Any equivalency conversion is not handled.

Parameters:
  • data_unit (str | Unit) – The unit we will be converting to. If the unit is not compatible, we raise an exception. If None, we default to no data unit conversion.

  • wavelength_unit (str | Unit | None, default = None) – A new wavelength unit to convert to. If the unit is not compatible, we raise an exception. If None, we default to no wavelength unit conversion.

Returns:

converted – The converted container, after the unit conversion.

Return type:

Self-like

property uncertainty: hint.NDArray#

Get the uncertainty array.

The uncertainty of the spectra. The unit of uncertainty is typically in meters; but, check the uncertainty_unit value.

Parameters:

None

Returns:

uncertainty – The uncertainty array of the container.

Return type:

NDArray

property uncertainty_unit: hint.Unit#

Return the uncertainty unit, i.e. the data unit.

Parameters:

None

Returns:

uncertainty_unit – The uncertainty unit.

Return type:

Unit

property wavelength: hint.NDArray#

Get the wavelength array.

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

Parameters:

None

Returns:

wavelength – The wavelength array of the container.

Return type:

NDArray