From 7fd0fbcc3ddb62b0e8b4d705a58726951e512f47 Mon Sep 17 00:00:00 2001 From: obiwan76 Date: Mon, 2 Dec 2024 16:57:05 -0500 Subject: [PATCH] this commit adress mperrin comments by adding a function to utils to better handle the use of the correct target phase maps based on the NIRCAM aperture --- webbpsf/trending.py | 39 ++++----------------------------------- webbpsf/utils.py | 22 ++++++++++++++++++++++ webbpsf/webbpsf_core.py | 8 ++------ 3 files changed, 28 insertions(+), 41 deletions(-) diff --git a/webbpsf/trending.py b/webbpsf/trending.py index 0f4bf74e..05b3be28 100644 --- a/webbpsf/trending.py +++ b/webbpsf/trending.py @@ -317,14 +317,7 @@ def wfe_histogram_plot( # 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' - ) + was_targ_file = webbpsf.utils.get_target_phase_map_filename(sensing_apername) target_1024 = astropy.io.fits.getdata(was_targ_file) @@ -646,25 +639,8 @@ def single_measurement_trending_plot( # 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' - ) + was_targ_file = webbpsf.utils.get_target_phase_map_filename(sensing_apername) + prev_was_targ_file = webbpsf.utils.get_target_phase_map_filename(prev_sensing_apername) target_1024 = astropy.io.fits.getdata(was_targ_file) @@ -1001,15 +977,8 @@ def vprint(*text): # 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' - ) + was_targ_file = webbpsf.utils.get_target_phase_map_filename(sensing_apername) target_1024 = astropy.io.fits.getdata(was_targ_file) target_256 = poppy.utils.krebin(target_1024, (256, 256)) diff --git a/webbpsf/utils.py b/webbpsf/utils.py index 529e68f7..f4c0ea47 100644 --- a/webbpsf/utils.py +++ b/webbpsf/utils.py @@ -1048,3 +1048,25 @@ def label_wavelength(nwavelengths, wavelength_slices): else: raise ValueError('Maximum number of wavelengths exceeded. ' 'Cannot be more than 10,000.') return label + + +def get_target_phase_map_filename(apername): + """Get WSS Target Phase Map for the specified aperture + Note that the sensing maintenance program changed field point from NRC A3 to A1 around Dec 2024. + """ + path = os.getenv('WEBBPSF_PATH') + if apername == 'NRCA3_FP1': + fn = 'wss_target_phase_fp1.fits' + elif apername == 'NRCA1_FP6': + fn = 'wss_target_phase_fp6.fits' + else: + raise ValueError(f"Target phase map not available for aperture = {apername}") + + was_targ_file = os.path.join( + get_webbpsf_data_path(), 'NIRCam', 'OPD', fn) + + if not os.path.exists(was_targ_file): + raise ValueError("File wss_target_phase_{}.fits, \ + not found under {}.".format(apername.split('_')[1].lower(),path)) + + return was_targ_file \ No newline at end of file diff --git a/webbpsf/webbpsf_core.py b/webbpsf/webbpsf_core.py index aaf4776b..a3145dc8 100644 --- a/webbpsf/webbpsf_core.py +++ b/webbpsf/webbpsf_core.py @@ -1725,12 +1725,8 @@ def load_wss_opd(self, filename, output_path=None, backout_si_wfe=True, verbose= # 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): + if sensing_apername in ['NRCA3_FP1', 'NRCA1_FP6']: + was_targ_file = utils.get_target_phase_map_filename(sensing_apername) sensing_fp_si_wfe = poppy.FITSOpticalElement(opd=was_targ_file).opd else: sensing_fp_si_wfe = sensing_inst.get_wfe('si')