Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First Pass WCS extract region bound fix #882

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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