pypeit.core.spectrum module
Temporary light-weight spectrum object.
Ideally this would be replaced by specutils.Spectrum
- class pypeit.core.spectrum.Spectrum(wave, flux, ivar=None, gpm=None, meta=None)[source]
Bases:
objectA light-weight container class for a spectrum.
The flux array can be either 1D or 2D. If 2D, its shape is always assumed to be \((N_{\rm pix},N_{\rm spec})\), where \(N_{\rm pix}\) is the number of pixels per spectrum and \(N_{\rm spec}\) is the number of spectra. The wavelength array must always be provided as 1D; i.e., for a 2D flux array, the wavelength vector must be correct for each flux vector along the 1st axis of the 2D array.
- Parameters:
wave (array-like) – Vacuum wavelengths in angstrom. Must be 1D, and its length must match the first axis of
flux.flux (array-like) – Flux data at each wavelength. Can be 2D or 1D; see class description.
ivar (array-like, optional) – Inverse variance in the flux. Shape must match
flux. If None, assumes uncertainties are unknown.gpm (array-like, optional) – Boolean good-pixel mask. Shape must match
flux. If None, assumes all pixels are valid.meta (dict, optional) – Collection of relevant metadata.
- inverse()[source]
Replace the spectrum with its multiplicative inverse.
This modifies the spectrum in place. If uncertainties are available, they are propagated. Any divisions by 0 result in an inverse variance of 0 and the good pixel mask is set to False.
- multiply(a)[source]
Multiply the spectrum by a scalar, vector, or another spectrum.
This modifies the spectral data in place. If uncertainties are available, they are propagated. Any divisions by 0 result in an inverse variance of 0 and the good pixel mask is set to False.
- Parameters:
a (scalar, array-like,
pypeit.core.spectrum.Spectrum) – Multiplicative factor. If an array, its shape must matchflux. If a spectrum, the wavelength arrays of the two spectrum must be identical.
- property ndim
The dimensionality of the flux array
- resample(new_wave, pixel_fraction_threshold=0.8, conserve=False)[source]
Resample the spectrum to a new wavelength array.
If available, errors and masking are both propagated through the calculation. This function is basically a wrapper for
Resample.- Parameters:
new_wave (array-like) – New wavelength vector for the spectrum
pixel_fraction_threshold (float, optional) – The resampling calculates the fraction of each output pixel that has unmasked contributions from the original spectrum. Fractions below this threshold will be masked in the output spectrum.
conserve (bool, optional) – Conserve the flux in the resampled spectrum. If the units of the spectrum are flux integrated over the pixel, this should typically be True; if the units are flux density (e.g., \({\rm ergs/s/cm}^2{\rm /angstrom}\)), this should typically be False.
- Returns:
A new spectrum object with the resample data.
- Return type:
- property shape
The shape of the flux array
- property size
The size of the flux array
- to_magnitude(zeropoint=0.0)[source]
Convert the spectrum to magnitudes.
For fluxes, \(f\), this returns
\[m = -2.5 \log_{\rm 10} (f) + Z,\]where \(Z\) is the provided zeropoint.
This modifies the spectrum in place. If uncertainties are available, they are propagated. Any pixels with non-positive fluxes are masked.
- Parameters:
zeropoint (float, optional) – The magnitude conversion zeropoint (see above)