lezargus.library.container.spectrum module#
Spectrum data container, holding spectral data.
This module and class primarily deals with spectral data.
- class lezargus.library.container.spectrum.LezargusSpectrum(wavelength: hint.NDArray, data: hint.NDArray, uncertainty: hint.NDArray | float | None = None, wavelength_unit: str | hint.Unit | None = None, data_unit: str | hint.Unit | 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 | None = None)[source]#
Bases:
LezargusContainerArithmetic
Container to hold spectral data and perform operations on it.
- For all available attributes, see :py:class:`LezargusContainerArithmetic`.
- __init__(wavelength: hint.NDArray, data: hint.NDArray, uncertainty: hint.NDArray | float | None = None, wavelength_unit: str | hint.Unit | None = None, data_unit: str | hint.Unit | 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 | None = None) None [source]#
Instantiate the spectrum class.
- 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 spectrum. 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 slice/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
- convolve(kernel: hint.NDArray | None = None, kernel_stack: hint.NDArray | None = None, kernel_function: hint.Callable | None = None) hint.Self | hint.LezargusSpectrum [source]#
Convolve the spectrum with a spectral kernel.
See py:func:convolve_spectrum_by_spectral_kernel for full documentation.
- Parameters:
kernel (ndarray, default = None) – The static 2D kernel.
kernel_stack (ndarray, default = None) – The variable 2D kernel stack.
kernel_function (Callable, default = None) – The dynamic 2D kernel function.
- Returns:
convolved_spectrum – A near copy of the data cube after convolution.
- Return type:
ndarray
- interpolate(wavelength: hint.NDArray, extrapolate: bool = False, skip_mask: bool = True, skip_flags: bool = True) tuple[hint.NDArray, hint.NDArray, hint.NDArray | None, hint.NDArray | None] [source]#
Interpolation calling function for spectrum.
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.
extrapolate (bool, default = False) – If True, we extrapolate. Otherwise, the edges are NaNs.
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.
- interpolate_spectrum(wavelength: hint.NDArray, extrapolate: bool = False, skip_mask: bool = True, skip_flags: bool = True) hint.LezargusSpectrum [source]#
Interpolation calling function for spectrum.
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.
extrapolate (bool, default = False) – If True, we extrapolate. Otherwise, the edges are NaNs.
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_spectrum – The interpolated spectrum, packaged as a spectrum class.
- Return type:
- classmethod read_fits_file(filename: str) hint.Self [source]#
Read a Lezargus spectrum FITS file.
We load a Lezargus FITS file from disk. Note that this should only be used for a 1-D spectrum file.
- Parameters:
filename (str) – The filename to load.
- Returns:
spectrum – The LezargusSpectrum class instance.
- Return type:
Self-like
- classmethod stitch(*spectra: hint.LezargusSpectrum, weights: list[hint.NDArray] | str = 'uniform', average_routine: hint.Callable[[hint.NDArray, hint.NDArray, hint.NDArray], tuple[float, float]] = None) hint.Self [source]#
Stitch spectra together to make a single spectrum.
We stitch all of the input spectra. If the spectrum 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 (LezargusSpectrum) – The set of Lezargus spectra which we will stitch together.
weights (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_spectrum – The spectrum after stitching.
- Return type:
- stitch_on(*spectra: hint.LezargusSpectrum, **kwargs: object) hint.Self [source]#
Stitch this spectrum with other input spectra.
We stitch spectra onto this spectra. This function is basically a compatibility wrapper around the class method
stitch()
.- Parameters:
*spectra (LezargusSpectrum) – A set of Lezargus spectra which we will stitch to this one.
**kwargs (object) – Arguments passed to
stitch()
.
- Returns:
stitch_spectrum – The spectrum after stitching.
- Return type: