Skip to content

Commit

Permalink
this commit adress mperrin comments by adding a function to utils to …
Browse files Browse the repository at this point in the history
…better handle the use of the correct target phase maps based on the NIRCAM aperture
  • Loading branch information
obi-wan76 committed Dec 2, 2024
1 parent 6937630 commit 7fd0fbc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 41 deletions.
39 changes: 4 additions & 35 deletions webbpsf/trending.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
22 changes: 22 additions & 0 deletions webbpsf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 2 additions & 6 deletions webbpsf/webbpsf_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 7fd0fbc

Please sign in to comment.