-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
Improved GWCS handling in Spectrum1D #1074
Changes from all commits
75b1dd9
c168476
68cbf24
9b49fd8
0c97cba
a287776
6cc3171
b6f1c2f
43cabcc
89d3611
a3a6535
de78a58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,6 @@ | |
from astropy.table import Table | ||
from astropy.io import fits | ||
from astropy.nddata import StdDevUncertainty, VarianceUncertainty, InverseVariance | ||
from astropy.time import Time | ||
from astropy.wcs import WCS | ||
from gwcs.wcstools import grid_from_bounding_box | ||
|
||
from ...spectra import Spectrum1D, SpectrumList | ||
|
@@ -583,38 +581,9 @@ def _jwst_s3d_loader(filename, **kwargs): | |
except (ValueError, KeyError): | ||
flux_unit = None | ||
|
||
# The spectral axis is first. We need it last | ||
flux_array = hdu.data.T | ||
flux_array = hdu.data | ||
flux = Quantity(flux_array, unit=flux_unit) | ||
|
||
# Get the wavelength array from the GWCS object which returns a | ||
# tuple of (RA, Dec, lambda). | ||
# Since the spatial and spectral axes are orthogonal in s3d data, | ||
# it is much faster to compute a slice down the spectral axis. | ||
grid = grid_from_bounding_box(wcs.bounding_box)[:, :, 0, 0] | ||
_, _, wavelength_array = wcs(*grid) | ||
_, _, wavelength_unit = wcs.output_frame.unit | ||
|
||
wavelength = Quantity(wavelength_array, unit=wavelength_unit) | ||
|
||
# The GWCS is currently broken for some IFUs, here we work around that | ||
wcs = None | ||
if wavelength.shape[0] != flux.shape[-1]: | ||
# Need MJD-OBS for this workaround | ||
if 'MJD-OBS' not in hdu.header: | ||
for key in ('MJD-BEG', 'DATE-OBS'): # Possible alternatives | ||
if key in hdu.header: | ||
if key.startswith('MJD'): | ||
hdu.header['MJD-OBS'] = hdu.header[key] | ||
break | ||
else: | ||
t = Time(hdu.header[key]) | ||
hdu.header['MJD-OBS'] = t.mjd | ||
break | ||
wcs = WCS(hdu.header) | ||
# Swap to match the flux transpose | ||
wcs = wcs.swapaxes(-1, 0) | ||
|
||
# Merge primary and slit headers and dump into meta | ||
slit_header = hdu.header | ||
header = primary_header.copy() | ||
|
@@ -625,7 +594,7 @@ def _jwst_s3d_loader(filename, **kwargs): | |
ext_name = primary_header.get("ERREXT", "ERR") | ||
err_type = hdulist[ext_name].header.get("ERRTYPE", 'ERR') | ||
err_unit = hdulist[ext_name].header.get("BUNIT", None) | ||
err_array = hdulist[ext_name].data.T | ||
err_array = hdulist[ext_name].data | ||
|
||
# ERRTYPE can be one of "ERR", "IERR", "VAR", "IVAR" | ||
# but mostly ERR for JWST cubes | ||
|
@@ -643,13 +612,10 @@ def _jwst_s3d_loader(filename, **kwargs): | |
|
||
# get mask information | ||
mask_name = primary_header.get("MASKEXT", "DQ") | ||
mask = hdulist[mask_name].data.T | ||
mask = hdulist[mask_name].data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just curious, why was data being transposed before? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specutils currently demands that the spectral axis be last in a multidimensional spectrum. Specutils 2.0 is going to remove that requirements, so we'll be able to keep the data in the same shape as you would get if you read it in with say |
||
|
||
spec = Spectrum1D(flux=flux, wcs=wcs, meta=meta, uncertainty=err, mask=mask, spectral_axis_index=0) | ||
|
||
if wcs is not None: | ||
spec = Spectrum1D(flux=flux, wcs=wcs, meta=meta, uncertainty=err, mask=mask) | ||
else: | ||
spec = Spectrum1D(flux=flux, spectral_axis=wavelength, meta=meta, | ||
uncertainty=err, mask=mask) | ||
spectra.append(spec) | ||
|
||
return SpectrumList(spectra) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs a change log entry