Skip to content

Commit

Permalink
Add unit test for defocus and weak lens. Fixes spacetelescope#59 (spa…
Browse files Browse the repository at this point in the history
…cetelescope#256)

* add test for defocus and weak lens
* minor: fix import in test case display path [ci skip]
  • Loading branch information
mperrin authored Dec 10, 2018
1 parent 19f85b1 commit 368dbcb
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions webbpsf/tests/test_nircam.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,32 @@ def test_nircam_coron_unocculted(plot=False):
psf = nc.calc_psf(monochromatic=2.12e-6)
return(psf)

def test_defocus(fov_arcsec=1, display=False):
"""Test we can apply a defocus to a PSF
via either a weak lens, or via the options dict,
and we get consistent results either way.
Test for #59 among other things
"""
nrc = webbpsf_core.NIRCam()
nrc.pupilopd=None
nrc.include_si_wfe=False

# Calculate defocus with a weak lens
nrc.pupil_mask = 'WEAK LENS +4'
psf = nrc.calc_psf(nlambda=1, fov_arcsec=fov_arcsec, oversample=1, display=False, add_distortion=False)

# Calculate equivalent via the options structure
nrc.pupil_mask = None
nrc.options['defocus_waves']=3.9024 # as measured
nrc.options['defocus_wavelength']=2.12e-6
psf_2 = nrc.calc_psf(nlambda=1, fov_arcsec=fov_arcsec, oversample=1, display=False, add_distortion=False)

assert np.allclose(psf[0].data, psf_2[0].data), "Defocused PSFs calculated two ways don't agree"

if display:
import webbpsf
plt.figure()
webbpsf.display_psf(psf)
plt.figure()
webbpsf.display_psf(psf_2)

0 comments on commit 368dbcb

Please sign in to comment.