Skip to content

Commit

Permalink
JP-3455: Updated MIRI imager photom step (#8096)
Browse files Browse the repository at this point in the history
Co-authored-by: Howard Bushouse <[email protected]>
  • Loading branch information
mlibralato and hbushouse authored Nov 30, 2023
1 parent 2a70810 commit faee866
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ imprint
- Updated the logging to report which imprint image is being subtracted from the
science image. [#8041]

photom
--------

- Added time-dependent correction for MIRI Imager data [#8096, spacetelescope/stdatamodels#235]

pixel_replace
-------------

Expand Down
35 changes: 35 additions & 0 deletions jwst/photom/miri_imager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import logging
import numpy as np

log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)

# Routine to find a time-dependent correction to the PHOTOM value.

def time_corr_photom(param, t):
"""
Short Summary
--------------
Time dependent PHOTOM function.
The model parameters are amplitude, tau, t0. t0 is the reference day
from which the time-dependent parameters were derived. This function will return
a correction to apply to the PHOTOM value at a given MJD.
Parameters
----------
param : numpy array
Set of parameters for the PHOTOM value
t : int
Modified Julian Day (MJD) of the observation
Returns
-------
corr: float
The time-dependent correction to the photmjsr term.
"""

amplitude, tau, t0 = param["amplitude"], param["tau"], param["t0"]
corr = amplitude * np.exp(-(t - t0)/tau)

return corr
28 changes: 27 additions & 1 deletion jwst/photom/photom.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from .. lib.wcs_utils import get_wavelengths
from . import miri_mrs
from . import miri_imager

log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -468,7 +469,32 @@ def calc_miri(self, ftab):
row = find_row(ftab.phot_table, fields_to_match)
if row is None:
return
self.photom_io(ftab.phot_table[row])
self.photom_io(ftab.phot_table[row])

# Check if reference file contains the coefficients for the time-dependent correction of the PHOTOM value
try:
ftab.getarray_noinit("timecoeff")
log.info("Applying the time-dependent correction to the PHOTOM value.")

mid_time = self.input.meta.exposure.mid_time
photom_corr = miri_imager.time_corr_photom(ftab.timecoeff[row], mid_time)

data = np.array(
[(self.filter, self.subarray, ftab.phot_table[row]['photmjsr']+photom_corr, ftab.phot_table[row]['uncertainty'])],
dtype=[
("filter", "O"),
("subarray", "O"),
("photmjsr", "<f4"),
("uncertainty", "<f4")
],
)
fftab = datamodels.MirImgPhotomModel(phot_table=data)
self.photom_io(fftab.phot_table[0])
except AttributeError:
# No time-dependent correction is applied
log.info(" Skipping MIRI imager time correction. Extension not found in the reference file.")
self.photom_io(ftab.phot_table[row])

# MRS detectors
elif self.detector == 'MIRIFUSHORT' or self.detector == 'MIRIFULONG':

Expand Down
18 changes: 15 additions & 3 deletions jwst/photom/tests/test_photom.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ def create_input(instrument, detector, exptype,
input_model.var_flat = np.ones(shape, dtype=np.float32)
input_model.meta.subarray.name = 'SUB256' # matches 'GENERIC'
input_model.meta.target.source_type = 'POINT'
input_model.meta.exposure.mid_time = 60000.0 # Added for new PHOTOM step
input_model.meta.photometry.pixelarea_arcsecsq = 0.0025
input_model.meta.photometry.pixelarea_steradians = 0.0025 * A2_TO_SR
elif instrument == 'FGS':
Expand Down Expand Up @@ -780,7 +781,7 @@ def create_photom_miri_image(min_wl=16.5, max_wl=19.5,
"""

filter = ["F1800W", "F2100W", "F2550W"]
subarray = ["GENERIC", "GENERIC", "GENERIC"]
subarray = ["SUB256", "SUB256", "SUB256"]

nrows = len(filter)

Expand All @@ -794,7 +795,15 @@ def create_photom_miri_image(min_wl=16.5, max_wl=19.5,
('uncertainty', '<f4')])
reftab = np.array(list(zip(filter, subarray, photmjsr, uncertainty)),
dtype=dtype)
ftab = datamodels.MirImgPhotomModel(phot_table=reftab)
timecoeff_amp = np.linspace(2.1, 2.1 + (nrows - 1.) * 0.1, nrows)
timecoeff_tau = np.asarray([145, 145, 145])
timecoeff_t0 = np.asarray([59720, 59720, 59720])
dtypec = np.dtype([('amplitude', '<f4'),
('tau', '<f4'),
('t0', '<f4')])
reftabc = np.array(list(zip(timecoeff_amp, timecoeff_tau, timecoeff_t0)),
dtype=dtypec)
ftab = datamodels.MirImgPhotomModel(phot_table=reftab, timecoeff=reftabc)

return ftab

Expand Down Expand Up @@ -1415,10 +1424,13 @@ def test_miri_image():
rownum = find_row_in_ftab(save_input, ftab, ['filter'],
slitname=None, order=None)
photmjsr = ftab.phot_table['photmjsr'][rownum]
amplitude = ftab.timecoeff['amplitude'][rownum]
tau = ftab.timecoeff['tau'][rownum]
t0 = ftab.timecoeff['t0'][rownum]
shape = input.shape
ix = shape[1] // 2
iy = shape[0] // 2
compare = photmjsr
compare = photmjsr + amplitude * np.exp(-(60000 - t0)/tau) # Added for new PHOTOM step
# Compare the values at the center pixel.
ratio = output[iy, ix] / input[iy, ix]
assert np.allclose(ratio, compare, rtol=1.e-7)
Expand Down

0 comments on commit faee866

Please sign in to comment.