From 25bd96bc018008f530c48d0496ae39eecf4bce62 Mon Sep 17 00:00:00 2001 From: obiwan76 Date: Fri, 29 Nov 2024 21:35:47 -0500 Subject: [PATCH] support for new sensing point and target phase map --- webbpsf/trending.py | 61 ++++++++++++++++++++++++++++++++++++----- webbpsf/webbpsf_core.py | 15 +++++++--- 2 files changed, 65 insertions(+), 11 deletions(-) diff --git a/webbpsf/trending.py b/webbpsf/trending.py index ae530817..0f4bf74e 100644 --- a/webbpsf/trending.py +++ b/webbpsf/trending.py @@ -313,11 +313,20 @@ def wfe_histogram_plot( elif ote_only is True: opd_data = fits.getdata(full_file_path, ext=1) mask = opd_data != 0 + sensing_apername = fits.getheader(full_file_path, ext=0)['APERNAME'] - # Get WSS Target Phase Map - was_targ_file = os.path.join( + # Get WSS Target Phase Map for the sensing aperture + # Note that the sensing maintenance program changed field point from NRC A3 to A1 around Dec 2024. + if sensing_apername == 'NRCA3_FP1': + was_targ_file = os.path.join( webbpsf.utils.get_webbpsf_data_path(), 'NIRCam', 'OPD', 'wss_target_phase_fp1.fits' ) + elif sensing_apername == 'NRCA1_FP6': + was_targ_file = os.path.join( + webbpsf.utils.get_webbpsf_data_path(), 'NIRCam', 'OPD', 'wss_target_phase_fp6.fits' + ) + + target_1024 = astropy.io.fits.getdata(was_targ_file) target_256 = poppy.utils.krebin(target_1024, (256, 256)) / 16 wf_si = target_256 * mask # Nircam target phase map at FP1 @@ -607,6 +616,7 @@ def single_measurement_trending_plot( opd, opdhdu = _read_opd(filename) mask = opd != 0 opd[~mask] = np.nan + sensing_apername = opdhdu[0].header['APERNAME'] # hdr_rmswfe = opdhdu[1].header['RMS_WFE'] visit = opdhdu[0].header['OBS_ID'][0:12] @@ -628,18 +638,44 @@ def single_measurement_trending_plot( print(' Previous OPD is:', prev_filename) prev_opd, prev_opd_hdu = _read_opd(prev_filename) + prev_sensing_apername = prev_opd_hdu[0].header['APERNAME'] if subtract_target: if verbose: print(' Subtracting NIRCam SI WFE target phase map') - # Get WSS Target Phase Map - was_targ_file = os.path.join(webbpsf.utils.get_webbpsf_data_path(), 'NIRCam', 'OPD', 'wss_target_phase_fp1.fits') + # Get WSS Target Phase Map for the sensing aperture + # Note that the sensing maintenance program changed field point from NRC A3 to A1 around Dec 2024. + if sensing_apername == 'NRCA3_FP1': + was_targ_file = os.path.join( + webbpsf.utils.get_webbpsf_data_path(), 'NIRCam', 'OPD', 'wss_target_phase_fp1.fits' + ) + elif sensing_apername == 'NRCA1_FP6': + was_targ_file = os.path.join( + webbpsf.utils.get_webbpsf_data_path(), 'NIRCam', 'OPD', 'wss_target_phase_fp6.fits' + ) + + # target phase map for prev. Needed just when the sensing aperture changed + + if prev_sensing_apername == 'NRCA3_FP1': + prev_was_targ_file = os.path.join( + webbpsf.utils.get_webbpsf_data_path(), 'NIRCam', 'OPD', 'wss_target_phase_fp1.fits' + ) + elif prev_sensing_apername == 'NRCA1_FP6': + prev_was_targ_file = os.path.join( + webbpsf.utils.get_webbpsf_data_path(), 'NIRCam', 'OPD', 'wss_target_phase_fp6.fits' + ) + + target_1024 = astropy.io.fits.getdata(was_targ_file) target_256 = poppy.utils.krebin(target_1024, (256, 256)) / 16 # scale factor for rebinning w/out increasing values + prev_target_1024 = astropy.io.fits.getdata(prev_was_targ_file) + prev_target_256 = poppy.utils.krebin(prev_target_1024, + (256, 256)) / 16 # scale factor for rebinning w/out increasing values + opd -= target_256 - prev_opd -= target_256 + prev_opd -= prev_target_256 # Compute deltas and decompose deltatime = get_datetime_utc(opdhdu, return_as='astropy') - get_datetime_utc(prev_opd_hdu, return_as='astropy') @@ -961,9 +997,20 @@ def vprint(*text): opd, opdhdu = _read_opd(opdtable[which_opds_mask][0]['fileName']) mask = opd != 0 + sensing_apername = opdhdu[0].header['APERNAME'] + + # Get WSS Target Phase Map for the sensing aperture + # Note that the sensing maintenance program changed field point from NRC A3 to A1 around Dec 2024. + if sensing_apername == 'NRCA3_FP1': + was_targ_file = os.path.join( + webbpsf.utils.get_webbpsf_data_path(), 'NIRCam', 'OPD', 'wss_target_phase_fp1.fits' + ) + elif sensing_apername == 'NRCA1_FP6': + was_targ_file = os.path.join( + webbpsf.utils.get_webbpsf_data_path(), 'NIRCam', 'OPD', 'wss_target_phase_fp6.fits' + ) + - # Get WSS Target Phase Map - was_targ_file = os.path.join(webbpsf.utils.get_webbpsf_data_path(), 'NIRCam', 'OPD', 'wss_target_phase_fp1.fits') target_1024 = astropy.io.fits.getdata(was_targ_file) target_256 = poppy.utils.krebin(target_1024, (256, 256)) diff --git a/webbpsf/webbpsf_core.py b/webbpsf/webbpsf_core.py index a531d37e..aaf4776b 100644 --- a/webbpsf/webbpsf_core.py +++ b/webbpsf/webbpsf_core.py @@ -1720,10 +1720,17 @@ def load_wss_opd(self, filename, output_path=None, backout_si_wfe=True, verbose= # note that there is a slight focus offset between the two wavelengths, due to NIRCam's refractive design # Set to the sensing aperture, and retrieve the OPD there sensing_inst.set_position_from_aperture_name(sensing_apername) - # special case: for the main sensing point FP1, we use the official WAS target phase map, rather than the - # WebbPSF-internal SI WFE model. - was_targ_file = os.path.join(utils.get_webbpsf_data_path(), 'NIRCam', 'OPD', 'wss_target_phase_fp1.fits') - if sensing_apername == 'NRCA3_FP1' and os.path.exists(was_targ_file): + # special case: for the main sensing points FP1 or FP6, we use the official WAS target phase map, + # rather than the WebbPSF-internal SI WFE model. + + # Select correct target phase map based on sensing field point. + # Note that the sensing maintenance program changed field point from NRC A3 to A1 around Dec 2024. + if sensing_apername == 'NRCA3_FP1': + was_targ_file = os.path.join(utils.get_webbpsf_data_path(), 'NIRCam', 'OPD', 'wss_target_phase_fp1.fits') + elif sensing_apername == 'NRCA1_FP6': + was_targ_file = os.path.join(utils.get_webbpsf_data_path(), 'NIRCam', 'OPD', 'wss_target_phase_fp6.fits') + + if (sensing_apername == 'NRCA3_FP1' or sensing_apername == 'NRCA1_FP6') and os.path.exists(was_targ_file): sensing_fp_si_wfe = poppy.FITSOpticalElement(opd=was_targ_file).opd else: sensing_fp_si_wfe = sensing_inst.get_wfe('si')