specutils icon indicating copy to clipboard operation
specutils copied to clipboard

JWST reader can't find the SRCTYPE keyword

Open ibusko opened this issue 4 years ago • 3 comments

This is a problem detected in jdaviz (issue 390) by @havok2063:

When trying to load JWST x1d spectrum, I now get the following error when loading the data in SpecViz,:

RuntimeError: Keyword SRCTYPE is None. It should be 'POINT' or 'EXTENDED'. Can't decide between "flux" and "surf_bright" columns.

The cause is that the keyword now resides in the SCI header, not in the PRIMARY as is assumed by the current code.

@ibusko pinpointed that the offending code is in specutils/io/default_loaders/jwst_reader.py.

ibusko avatar Jan 21 '21 20:01 ibusko

The SRCTYPE keyword will be either in the SCI extension header or the EXTRACT1D extension header, depending on the data product type. See https://github.com/spacetelescope/jwst/pull/4885. Presumably for x1d files it will be in the EXTRACT1D.

havok2063 avatar Jan 22 '21 16:01 havok2063

It would be useful to assume one or the other if the keyword isn't specified, if that is not too onerous. The JWST pipeline is able to run on files that do not have it set, but then I can't read the files in via specutils. (... maybe this should also be a JWST pipeline issue to add the keyword if it's missing....)

skendrew avatar Apr 22 '21 13:04 skendrew

Currently the JWST loaders loop over all hdus and search for the SRCTYPE keyword and raises an error if it can't find it anywhere. For x1d files it should be in the EXTRACT1D header. For 2d and 3d spectroscopic data, it should be in SCI. The missing SRCTYPE keyword was a JWST pipeline bug, as well as the SCI extension in x1d files. Both of these should have been fixed in Build 7.7.1. Older data won't be loadable. The loader of x1d data only uses the keyword to determine whether to load the spectrum data from the FLUX or SURF_BRIGHT table columns.

havok2063 avatar Apr 22 '21 18:04 havok2063