From d20dca66e19c6e2fcfd9c71d3ddef219deb54154 Mon Sep 17 00:00:00 2001 From: Maria Date: Wed, 7 Feb 2024 22:18:41 -0500 Subject: [PATCH] JP-3247: Retrieve pixel area from AREA reference file (#8187) Co-authored-by: Howard Bushouse --- CHANGES.rst | 3 ++ docs/jwst/photom/main.rst | 5 ++- jwst/photom/photom.py | 77 ++++++++++++++++++++++++++++++--------- 3 files changed, 65 insertions(+), 20 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index f79479d062..ec4e080bfa 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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] diff --git a/docs/jwst/photom/main.rst b/docs/jwst/photom/main.rst index e669014a1e..1d98734cb5 100644 --- a/docs/jwst/photom/main.rst +++ b/docs/jwst/photom/main.rst @@ -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 diff --git a/jwst/photom/photom.py b/jwst/photom/photom.py index 78dbbed131..273653f529 100644 --- a/jwst/photom/photom.py +++ b/jwst/photom/photom.py @@ -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': @@ -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 @@ -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 @@ -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)) @@ -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): """