Skip to content

Commit

Permalink
Updates to allow rectangular FOV and return_intermediates moved to JW…
Browse files Browse the repository at this point in the history
…Instruemnt calc_psf
  • Loading branch information
shanosborne committed May 18, 2018
1 parent dcd30d5 commit 2419622
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
15 changes: 8 additions & 7 deletions webbpsf/distortion.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,20 @@ def apply_distortion(HDUlist_or_filename=None, fill_value=0):
oversamp = psf[ext].header["OVERSAMP"] # will be 1 for ext=1
xpix_center = psf[ext].header["DET_X"] # center x location in pixels
ypix_center = psf[ext].header["DET_Y"] # center y location in pixels
length = psf[ext].shape[0] # can assume square
len_y = psf[ext].shape[0]
len_x = psf[ext].shape[1]

# Convert the PSF center point from pixels to arcseconds using pysiaf
xarc_center, yarc_center = aper.sci_to_idl(xpix_center, ypix_center)

# ###############################################
# Create an array of indices (in pixels) for where the PSF is located on the detector
# 1) Set up blank indices (in pixels)
ypix, xpix = np.indices((length, length), dtype=float)
ypix, xpix = np.indices((len_y, len_x), dtype=float)

# 2) Shift indices to be centered on (0,0) (starting to transform into the Ideal frame)
ypix -= (length - 1.) / 2.
xpix -= (length - 1.) / 2.
ypix -= (len_y - 1.) / 2.
xpix -= (len_x - 1.) / 2.

# 3) Convert these indices from pixels to arcseconds
# Note: This also shifts the oversampled indices so they span the same region as the detector-sampled indices
Expand All @@ -108,11 +109,11 @@ def apply_distortion(HDUlist_or_filename=None, fill_value=0):
# ###############################################
# Create an array of indices (in pixels) that the final data will be interpolated on to
# 1) Set up blank indices (in pixels)
ynew, xnew = np.indices([length, length], dtype=float)
ynew, xnew = np.indices([len_y, len_x], dtype=float)

# 2) Shift indices to be in the Ideal frame (centered on 0)
xnew -= (length - 1.) / 2.
ynew -= (length - 1.) / 2.
xnew -= (len_x - 1.) / 2.
ynew -= (len_y - 1.) / 2.

# 3) Shift the oversampled indices so they span the same region as the detector-sampled indices
# Note: the oversampled array is still longer by a factor of the oversample
Expand Down
10 changes: 7 additions & 3 deletions webbpsf/webbpsf_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,9 @@ def calc_psf(self, outfile=None, source=None, nlambda=None, monochromatic=None,
save_intermediates=save_intermediates,
return_intermediates=return_intermediates, normalize=normalize)

if return_intermediates:
psf, intermediates = psf

# If chosen to add distortion
if add_distortion:

Expand Down Expand Up @@ -779,17 +782,18 @@ def calc_psf(self, outfile=None, source=None, nlambda=None, monochromatic=None,
psf_distorted.writeto(outfile, overwrite=True, output_verify='ignore') # already created in the 1st calc_psf
_log.info("Re-saved result with distortion to " + outfile)

return psf_distorted
psf = psf_distorted

if return_intermediates:
return psf, intermediates

else:
return psf


calcPSF = calc_psf
calc_psf.__doc__ += SpaceTelescopeInstrument.calc_psf.__doc__ # allow users to see poppy calc_psf docstring too



class MIRI(JWInstrument):
""" A class modeling the optics of MIRI, the Mid-InfraRed Instrument.
Expand Down

0 comments on commit 2419622

Please sign in to comment.