SpectRes: Simple Spectral Resampling¶
SpectRes is a Python function which efficiently resamples spectra and their associated uncertainties onto an arbitrary wavelength grid. The function works with any grid of wavelength values, including non-uniform sampling, and preserves the integrated flux. This may be of use for binning data to increase the signal to noise ratio, obtaining synthetic photometry, or resampling model spectra to match the sampling of observational data.
SpectRes can be installed using pip
pip install spectres
The code is developed at github.com/ACCarnall/spectres. Take a look in the examples folder for some more guidance.
For an explanation of how the code works take a look at ArXiv1705.05165. Please consider citing this publication if you use SpectRes in your research.
spectres(new_wavs, spec_wavs, spec_fluxes, spec_errs=None, fill=None, verbose=True)¶
Function for resampling spectra (and optionally associated uncertainties) onto a new wavelength basis.
- new_wavs (numpy.ndarray) – Array containing the new wavelength sampling desired for the spectrum or spectra.
- spec_wavs (numpy.ndarray) – 1D array containing the current wavelength sampling of the spectrum or spectra.
- spec_fluxes (numpy.ndarray) – Array containing spectral fluxes at the wavelengths specified in spec_wavs, last dimension must correspond to the shape of spec_wavs. Extra dimensions before this may be used to include multiple spectra.
- spec_errs (numpy.ndarray (optional)) – Array of the same shape as spec_fluxes containing uncertainties associated with each spectral flux value.
- fill (float (optional)) – Where new_wavs extends outside the wavelength range in spec_wavs this value will be used as a filler in new_fluxes and new_errs.
- verbose (bool (optional)) – Setting verbose to False will suppress the default warning about new_wavs extending outside spec_wavs and “fill” being used.
- new_fluxes (numpy.ndarray) – Array of resampled flux values, first dimension is the same length as new_wavs, other dimensions are the same as spec_fluxes.
- new_errs (numpy.ndarray) – Array of uncertainties associated with fluxes in new_fluxes. Only returned if spec_errs was specified.