Skip to content

Commit

Permalink
support for new sensing point and target phase map
Browse files Browse the repository at this point in the history
  • Loading branch information
obi-wan76 committed Nov 30, 2024
1 parent 540a751 commit 25bd96b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 11 deletions.
61 changes: 54 additions & 7 deletions webbpsf/trending.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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')
Expand Down Expand Up @@ -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))

Expand Down
15 changes: 11 additions & 4 deletions webbpsf/webbpsf_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 25bd96b

Please sign in to comment.