diff --git a/specutils/manipulation/extract_spectral_region.py b/specutils/manipulation/extract_spectral_region.py index bae78c118..6123d8795 100644 --- a/specutils/manipulation/extract_spectral_region.py +++ b/specutils/manipulation/extract_spectral_region.py @@ -5,6 +5,7 @@ import numpy as np from astropy import units as u +from astropy.wcs.wcs import WCS from ..spectra import Spectrum1D, SpectralRegion __all__ = ['extract_region', 'extract_bounding_spectral_region', 'spectral_slab'] @@ -164,7 +165,16 @@ def extract_region(spectrum, region, return_single_spectrum=False): if left_index > right_index: left_index, right_index = right_index, left_index - extracted_spectrum.append(spectrum[..., left_index:right_index]) + # Slice spectrum to calculated indices + extracted_spectra = spectrum[..., left_index:right_index] + + # Set the Astropy WCS wavelength reference value to new lower bound of spectrum + if type(extracted_spectra.wcs) is WCS: + extracted_spectra.wcs.wcs.crval[0] = min(extracted_spectra.wavelength + ).to( + u.Unit(extracted_spectra.wcs.wcs.cunit[0]) # noqa + ).value + extracted_spectrum.append(extracted_spectra) # If there is only one subregion in the region then we will # just return a spectrum.