Skip to content

Commit

Permalink
BUG: Recreate JWST MJD-OBS if it is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
pllim committed Dec 14, 2021
1 parent 7c12391 commit e84136a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Bug Fixes
Cubeviz
^^^^^^^

- Missing MJD-OBS in JWST data will no longer crash Cubeviz as long as
it has MJD-BEG, DATE-OBS, or DATE-BEG. [#1004]

Imviz
^^^^^

Expand Down
23 changes: 19 additions & 4 deletions jdaviz/configs/cubeviz/plugins/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,27 @@ def _parse_hdu(app, hdulist, file_name=None):
app.add_data_to_viewer('spectrum-viewer', data_label)


def _parse_jwst_s3d(app, hdulist, data_label):
def _parse_jwst_s3d(app, hdulist, data_label, ext=1):
from specutils import Spectrum1D

unit = u.Unit(hdulist[1].header.get('BUNIT', 'count'))
flux = hdulist[1].data << unit
wcs = WCS(hdulist[1].header, hdulist)
# Manually inject MJD-OBS until we can support GWCS, see
# https://github.com/spacetelescope/jdaviz/issues/690 and
# https://github.com/glue-viz/glue-astronomy/issues/59
if 'MJD-OBS' not in hdulist[ext].header:
for key in ('MJD-BEG', 'DATE-OBS', 'DATE-BEG'): # Possible alternatives
if key in hdulist[ext].header:
if key.startswith('MJD'):
hdulist[ext].header['MJD-OBS'] = hdulist[ext].header[key]
break
else:
from astropy.time import Time
t = Time(hdulist[ext].header[key])
hdulist[ext].header['MJD-OBS'] = t.mjd
break

unit = u.Unit(hdulist[ext].header.get('BUNIT', 'count'))
flux = hdulist[ext].data << unit
wcs = WCS(hdulist[ext].header, hdulist)
data = Spectrum1D(flux, wcs=wcs)

# NOTE: Tried to only pass in sliced WCS but got error in Glue.
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/configs/cubeviz/plugins/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def image_hdu_obj():
'CTYPE1': 'RA---TAN', 'CTYPE2': 'DEC--TAN', 'CTYPE3': 'WAVE-LOG',
'CRVAL1': 205.4384, 'CRVAL2': 27.004754, 'CRVAL3': 3.62159598486E-07,
'LONPOLE': 180.0, 'LATPOLE': 27.004754, 'MJDREFI': 0.0,
'MJDREFF': 0.0, 'DATE-OBS': '2014-03-30', 'MJD-OBS': 56746.0,
'MJDREFF': 0.0, 'DATE-OBS': '2014-03-30',
'RADESYS': 'FK5', 'EQUINOX': 2000.0
})

Expand Down

0 comments on commit e84136a

Please sign in to comment.