Skip to content

Commit

Permalink
fixed a problem about applying IPC effects twice when using the psf c…
Browse files Browse the repository at this point in the history
…al path inside the gridded library
  • Loading branch information
obi-wan76 committed Jan 26, 2024
1 parent 976dcf3 commit 51773c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 7 additions & 2 deletions webbpsf/detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,21 @@ def apply_detector_ipc(psf_hdulist, extname = 'DET_DIST'):

# In cases for which the user has asked for the IPC to be applied to a not-present extension, we have nothing to add this to

if psf_hdulist is None: return
#if psf_hdulist is None: return
if extname not in psf_hdulist:
webbpsf.webbpsf_core._log.debug(f"Skipping IPC simulation since ext {extname} is not found")
return

# This avoid applying IPC corrections twice, especially when calling the psf_grid code path for making ePSFs
# because the IPC corrections are applied in gridded_library

keyword = 'IPCINST'
if keyword in psf_hdulist[extname].header._keyword_indices: return

inst = psf_hdulist[extname].header['INSTRUME'].upper()
oversample = psf_hdulist[extname].header['OVERSAMP']

kernel, meta = get_detector_ipc_model(inst, psf_hdulist[extname].header)

if kernel is not None:

if inst.upper()=='NIRCAM':
Expand Down
12 changes: 11 additions & 1 deletion webbpsf/gridded_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ def create_grid(self):
if self.verbose is True:
print(" Position {}/{}: {} pixels".format(i+1, len(self.location_list), loc))

# Deactivate IPC corrections, if any, before calc_psf as we are applying them later
self.webb.options['add_ipc_gridded'] = False # add dictionary key to keep track of the user's IPC input
# Deactivate IPC corrections, if any, before calc_psf as we are applying them later
if self.webb.options.get('add_ipc', True):
self.webb.options['add_ipc'] = False
self.webb.options['add_ipc_gridded'] = True

# Create PSF
psf = self.webb.calc_psf(**self._kwargs)
if self.verbose is True:
Expand All @@ -296,7 +303,10 @@ def create_grid(self):
psf[ext].data = astropy.convolution.convolve(psf[ext].data, kernel)

# Convolve PSF with a model for interpixel capacitance
# This is apply outside the gridded libary see issue #736

if self.add_distortion and self.webb.options['add_ipc_gridded']:
webbpsf.detectors.apply_detector_ipc(psf, extname=ext)
self.webb.options['add_ipc'] = True # restore the dictionary keyword for the IPC

# Add PSF to 5D array
psf_arr[i, :, :] = psf[ext].data
Expand Down

0 comments on commit 51773c5

Please sign in to comment.