Skip to content

Commit

Permalink
JP-3247: Retrieve pixel area from AREA reference file (#8187)
Browse files Browse the repository at this point in the history
Co-authored-by: Howard Bushouse <[email protected]>
  • Loading branch information
penaguerrero and hbushouse committed Feb 8, 2024
1 parent 88f14f6 commit d20dca6
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ photom
the pipeline put the (variable, calculated per pixel) dispersion back in. Assumes that
the dispersion needs to be in Angstroms/pixel to match the required factor of ~10. [#8207]

- Get the values of PIXAR_A2 and PIXAR_SR from AREA reference file
instead of PHOTOM reference file to avoid missmatching values. [#8187]

- Added a hook to bypass the ``photom`` step when the ``extract_1d`` step
was bypassed and came before the ``photom`` step, e.g. for NIRISS SOSS
data in the FULL subarray. [#8225]
Expand Down
5 changes: 3 additions & 2 deletions docs/jwst/photom/main.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ The step also populates the keywords PIXAR_SR and PIXAR_A2 in the
science data product, which give the average pixel area in units of
steradians and square arcseconds, respectively.
For most instrument modes, the average pixel area values are copied from the
primary header of the PHOTOM reference file.
For NIRSpec, however, the pixel area values are copied from a binary table
primary header of the AREA reference file, when this file is available. Otherwise
the pixel area values are copied from the primary header of the PHOTOM reference
file. For NIRSpec, however, the pixel area values are copied from a binary table
extension in the AREA reference file.

NIRSpec IFU
Expand Down
77 changes: 59 additions & 18 deletions jwst/photom/photom.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def calc_nirspec(self, ftab, area_fname):
if row is None:
continue
self.photom_io(ftab.phot_table[row])

# Bright object fixed-slit exposures use a SlitModel
elif self.exptype == 'NRS_BRIGHTOBJ':

Expand Down Expand Up @@ -1150,6 +1151,30 @@ def create_1d_conversion(self, model, conversion, waves, relresps):

return conversion, no_cal

def pixarea_from_ftab(self, ftab):
"""
Short Summary
-------------
Read the pixel area values in the PIXAR_A2 and PIXAR_SR keys from the
primary header of the photom reference file.
Parameters
----------
ftab : `~jwst.datamodels.JwstDataModel`
A photom reference file data model
"""
area_ster, area_a2 = None, None
area_ster = ftab.meta.photometry.pixelarea_steradians
log.info('Attempting to obtain PIXAR_SR and PIXAR_A2 values from PHOTOM reference file.')
if area_ster is None:
log.warning('The PIXAR_SR keyword is missing from %s', ftab.meta.filename)
area_a2 = ftab.meta.photometry.pixelarea_arcsecsq
if area_a2 is None:
log.warning('The PIXAR_A2 keyword is missing from %s', ftab.meta.filename)
if area_ster is not None and area_a2 is not None:
log.info('Values for PIXAR_SR and PIXAR_A2 obtained from PHOTOM reference file.')
return area_ster, area_a2

def save_area_info(self, ftab, area_fname):
"""
Short Summary
Expand All @@ -1172,13 +1197,18 @@ def save_area_info(self, ftab, area_fname):
Pixel area reference file name
"""

# Load the pixel area reference file
use_pixarea_rfile = False
area_ster, area_a2 = None, None
if area_fname is not None and area_fname != "N/A":
use_pixarea_rfile = True
# Load the pixel area reference file
pix_area = datamodels.open(area_fname)

# Copy the pixel area data array to the appropriate attribute
# of the science data model
if self.instrument != 'NIRSPEC':
if self.instrument != 'NIRSPEC':

if use_pixarea_rfile:
# Copy the pixel area data array to the appropriate attribute
# of the science data model
if isinstance(self.input, datamodels.MultiSlitModel):
# Note that this only copied to the first slit.
self.input.slits[0].area = pix_area.data
Expand All @@ -1190,21 +1220,29 @@ def save_area_info(self, ftab, area_fname):
self.input.area = pix_area.data[ystart: yend,
xstart: xend]
log.info('Pixel area map copied to output.')
else:
self.save_area_nirspec(pix_area)

pix_area.close()

# Load the average pixel area values from the photom reference file header
# Don't need to do this for NIRSpec, because pixel areas come from
# the AREA ref file, which have already been copied using save_area_nirspec
if self.instrument != 'NIRSPEC':
area_ster = ftab.meta.photometry.pixelarea_steradians
if area_ster is None:
log.warning('The PIXAR_SR keyword is missing from %s', ftab.meta.filename)
area_a2 = ftab.meta.photometry.pixelarea_arcsecsq
if area_a2 is None:
log.warning('The PIXAR_A2 keyword is missing from %s', ftab.meta.filename)
# Load the average pixel area values from the AREA reference file header
# Don't need to do this for NIRSpec, because pixel areas will be
# copied using save_area_nirspec
try:
area_ster = pix_area.meta.photometry.pixelarea_steradians
if area_ster is None:
log.warning('The PIXAR_SR keyword is missing from %s', area_fname)
area_a2 = pix_area.meta.photometry.pixelarea_arcsecsq
if area_a2 is None:
log.warning('The PIXAR_A2 keyword is missing from %s', area_fname)
if area_ster is not None and area_a2 is not None:
log.info('Values for PIXAR_SR and PIXAR_A2 obtained from AREA reference file.')

# The area reference file might be older, try the photom reference file
except AttributeError or KeyError:
area_ster, area_a2 = self.pixarea_from_ftab(ftab)

pix_area.close()

# The area reference file might be older, try the photom reference file
else:
area_ster, area_a2 = self.pixarea_from_ftab(ftab)

# Copy the pixel area values to the output
log.debug('PIXAR_SR = %s, PIXAR_A2 = %s', str(area_ster), str(area_a2))
Expand All @@ -1221,6 +1259,9 @@ def save_area_info(self, ftab, area_fname):
else:
self.input.meta.photometry.pixelarea_arcsecsq = area_a2
self.input.meta.photometry.pixelarea_steradians = area_ster
else:
self.save_area_nirspec(pix_area)
pix_area.close()

def save_area_nirspec(self, pix_area):
"""
Expand Down

0 comments on commit d20dca6

Please sign in to comment.