Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion specutils/manipulation/extract_spectral_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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.
Expand Down