Skip to content

Commit

Permalink
Avoid adding detector IPC to MIRI MRS IFU sims. Improve testing rigor…
Browse files Browse the repository at this point in the history
… & consistency
  • Loading branch information
mperrin committed Dec 18, 2024
1 parent 3408e31 commit 95dad0b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions stpsf/detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,9 @@ def apply_miri_ifu_broadening(hdulist, options, slice_width=0.196):
model_type = options.get('ifu_broadening', 'empirical_cruciform')

if model_type is None or model_type.lower() == 'none':
webbpsf.webbpsf_core._log.debug('MIRI MRS: IFU broadening option is set to None, skipping IFU PSF broadening effects.')
return hdulist
webbpsf.webbpsf_core._log.debug('MIRI MRS: Adding IFU PSF broadening effects.')

ext = 1 # Apply this effect to the OVERDIST extension, which at this point in the code will be ext 1

Expand Down
10 changes: 9 additions & 1 deletion stpsf/stpsf_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,12 @@ def _get_pixelscale_from_apername(self, apername):
# The slight departures from this are handled in the distortion model; see distortion.py
return (ap.XSciScale + ap.YSciScale) / 2

@property
def mode(self):
# This exists just for API consistency with the subclasses that have an imaging vs IFU mode toggle,
# so that all JWST instrument classes have a mode attribute, consistently, whether used or not
return "imaging"

def _get_fits_header(self, result, options):
"""populate FITS Header keywords"""
super(JWInstrument, self)._get_fits_header(result, options)
Expand Down Expand Up @@ -1252,7 +1258,9 @@ def _calc_psf_format_output(self, result, options):
add_distortion = options.get('add_distortion', True)
crop_psf = options.get('crop_psf', True)
# you can turn on/off IPC corrections via the add_ipc option, default True.
add_ipc = options.get('add_ipc', True)
# except for IFU mode simulations, it doesn't make sense to add the regular detector IPC
# instead the more complex IFU broadening models should be applied
add_ipc = options.get('add_ipc', True if self.mode != 'IFU' else False)

# Add distortion if set in calc_psf
if add_distortion:
Expand Down
6 changes: 3 additions & 3 deletions stpsf/tests/test_miri.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,17 @@ def test_miri_ifu_broadening():

# test flux conservation. THis is close but not exact, due to the optical distortion part which is distinct from but
# happens at same point in the calculation as the IFU broadening effect.
assert np.isclose(psf['DET_SAMP'].data.sum(), psf['DET_DIST'].data.sum(), rtol=2e-4), "IFU broadening should not change total flux much"
assert np.isclose(psf['DET_SAMP'].data.sum(), psf['DET_DIST'].data.sum()), "IFU broadening should not change total flux much"


# Now test that we can also optionally turn off that effect
miri.options['ifu_broadening'] = None
psf_nb = miri.calc_psf(monochromatic=2.8e-6, fov_pixels=10)
psf_nb = miri.calc_psf(monochromatic=6.8e-6, fov_pixels=20)

fwhm_oversamp = stpsf.measure_fwhm(psf_nb, ext='OVERSAMP')
fwhm_overdist = stpsf.measure_fwhm(psf_nb, ext='OVERDIST')
# The PSF will still be a little broader in this case due to the IPC model, but not by a lot..
assert fwhm_oversamp < fwhm_overdist <= 1.1 * fwhm_oversamp, "IFU broadening model should be disabled for this test case"
assert fwhm_overdist == fwhm_oversamp, "IFU broadening model should be disabled for this test case"

# test flux conservation with and without the IFU broadening. This should be a more exact match
assert np.isclose(psf_nb['DET_DIST'].data.sum(), psf['DET_DIST'].data.sum() ), "IFU broadening should not change total flux much"
Expand Down

0 comments on commit 95dad0b

Please sign in to comment.