Skip to content

Commit

Permalink
JP-3770: emicorr memory and run time improvement (spacetelescope#8849)
Browse files Browse the repository at this point in the history
  • Loading branch information
penaguerrero authored and hayescr committed Oct 29, 2024
1 parent 15f39f9 commit 1f5e7a0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions changes/8849.emicorr.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed the interleaved noise array and do interleaving of noise and subtraction in-place to avoid creating 2 arrays of equal dimensions to data.
16 changes: 7 additions & 9 deletions jwst/emicorr/emicorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,25 +438,23 @@ def apply_emicorr(output_model, emicorr_model,
# This is the phase matched noise model to subtract from each pixel of the input image
dd_noise = lut[(phaseall * period_in_pixels).astype(int)]

# Interleave (straight copy) into 4 amps
noise = np.zeros((nints, ngroups, ny, nx)) # same size as input data
noise_x = np.arange(nx4) * 4
for k in range(4):
noise[:, :, :, noise_x + k] = dd_noise

# Safety catch; anywhere the noise value is not finite, set it to zero
noise[~np.isfinite(noise)] = 0.0
dd_noise[~np.isfinite(dd_noise)] = 0.0

# Subtract EMI noise from the input data
log.info('Subtracting EMI noise from data')
output_model.data = output_model.data - noise

# Interleave (straight copy) into 4 amps
noise_x = np.arange(nx4) * 4
for k in range(4):
output_model.data[..., noise_x + k] -= dd_noise

# clean up
del data
del dd_all
del times_this_int
del phaseall
del noise
del dd_noise

if save_intermediate_results and save_onthefly_reffile is not None:
if 'FAST' in readpatt:
Expand Down
4 changes: 2 additions & 2 deletions jwst/emicorr/tests/test_emicorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import numpy as np
from jwst.emicorr import emicorr, emicorr_step
from stdatamodels.jwst.datamodels import Level1bModel, EmiModel
from stdatamodels.jwst.datamodels import RampModel, EmiModel


subarray_example_case = {
Expand All @@ -33,7 +33,7 @@

def mk_data_mdl(data, subarray, readpatt, detector):
# create input_model
input_model = Level1bModel(data=data)
input_model = RampModel(data=data)
input_model.meta.instrument.name = 'MIRI'
input_model.meta.instrument.detector = detector
input_model.meta.exposure.type = 'MIR_4QPM'
Expand Down

0 comments on commit 1f5e7a0

Please sign in to comment.