lezargus.container.spectra module#
Spectra data container.
This module and class primarily deals with spectral data.
- class lezargus.container.spectra.LezargusSpectra(wavelength: ndarray, data: ndarray, uncertainty: ndarray | None = None, wavelength_unit: str | Unit | None = None, data_unit: str | Unit | None = None, mask: ndarray | None = None, flags: ndarray | None = None, header: Header | None = None)[source]#
Bases:
LezargusContainerArithmetic
Container to hold spectral data and perform operations on it.
- wavelength#
The wavelength of the spectra. The unit of wavelength is typically in microns; but, check the
wavelength_unit
value.- Type:
ndarray
- data#
The flux of the spectra. The unit of the flux is typically in flam; but, check the
flux_unit
value.- Type:
ndarray
- uncertainty#
The uncertainty in the flux of the spectra. 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
- flux_unit#
The unit of the flux array.
- Type:
Astropy Unit
- uncertainty_unit#
The unit of the uncertainty array. This unit is the same as the flux unit.
- Type:
Astropy Unit
- mask#
A mask of the flux data, used to remove problematic areas. Where True, the values of the flux is considered mask.
- Type:
ndarray
- flags#
Flags of the flux data. These flags store metadata about the flux.
- Type:
ndarray
- header#
The header information, or metadata in general, about the data.
- Type:
Header
- __init__(wavelength: ndarray, data: ndarray, uncertainty: ndarray | None = None, wavelength_unit: str | Unit | None = None, data_unit: str | Unit | None = None, mask: ndarray | None = None, flags: ndarray | None = None, header: Header | None = None) None [source]#
Instantiate the spectra class.
- Parameters:
wavelength (ndarray) – The wavelength of the spectra.
data (ndarray) – The flux of the spectra.
uncertainty (ndarray, default = None) – The uncertainty of the spectra. By default, it is None and the uncertainty value is 0.
wavelength_unit (Astropy-Unit like, default = None) – The wavelength unit of the spectra. It must be interpretable by the Astropy Units package. If None, the the unit is dimensionless.
data_unit (Astropy-Unit like, default = None) – The data unit of the spectra. It must be interpretable by the Astropy Units package. If None, the the unit is dimensionless.
mask (ndarray, default = None) – A mask which should be applied to the spectra, if needed.
flags (ndarray, default = None) – A set of flags which describe specific points of data in the spectra.
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
- interpolate(wavelength: ndarray, skip_mask: bool = True, skip_flags: bool = True) tuple[ndarray, ndarray, ndarray | None, ndarray | None] [source]#
Interpolation calling function for spectra.
Each entry is considered a single point to interpolate over.
- Parameters:
wavelength (ndarray) – The wavelength values which we are going to interpolate to. The units of the data of this array should be the same as the wavelength unit stored.
skip_mask (bool, default = True) – If provided, the propagation of data mask through the interpolation is skipped. It is computationally a little expensive otherwise.
skip_flags (bool, default = True) – If provided, the propagation of data flags through the interpolation is skipped. It is computationally a little expensive otherwise.
- Returns:
interp_data (ndarray) – The interpolated data.
interp_uncertainty (ndarray) – The interpolated uncertainty.
interp_mask (ndarray or None) – A best guess attempt at finding the appropriate mask for the interpolated data. If skip_mask=True, then we skip the computation and return None instead.
interp_flags (ndarray or None) – A best guess attempt at finding the appropriate flags for the interpolated data. If skip_flags=True, then we skip the computation and return None instead.
- classmethod read_fits_file(filename: str) Self [source]#
Read a Lezargus spectra FITS file.
We load a Lezargus FITS file from disk. Note that this should only be used for 1-D spectra files.
- Parameters:
filename (str) – The filename to load.
- Returns:
spectra – The LezargusSpectra class instance.
- Return type:
Self-like
- stitch(*spectra: LezargusSpectra, weight: list[ndarray] | str = 'uniform', average_routine: Callable[[ndarray, ndarray, ndarray], tuple[float, float]] = None) Self [source]#
Stitch together different spectra; we do not scaling.
We stitch this spectra with input spectra. If the spectra are not already to the same scale however, this will result in wildly incorrect results. The header information is preserved, though we take what we can from the other objects.
- Parameters:
*spectra (LezargusSpectra) – A set of Lezargus spectra which we will stitch to this one.
weight (list[ndarray] or str, default = None) –
A list of the weights in the data for stitching. Each entry in the list must have a corresponding entry in the wavelength and data list, or None. For convenience, we provide short-cut inputs for the following:
uniform : Uniform weights.
invar : Inverse variance weights.
average_routine (Callable, str, default = None) – The function used to average all of the spectra together. It must also be able to accept weights and propagate uncertainties. If None, we default to the weighted mean. Namely, it must be of the form f(val, uncert, weight) = avg, uncert.
- Returns:
stitch_spectra – The spectra after stitching.
- Return type: