Skip to content

Commit 4bd6549

Browse files
JP-3628: Revise coron3 alignment step (#8643)
2 parents c728859 + 0dae781 commit 4bd6549

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
1.15.2 (unreleased)
22
===================
33

4+
align_refs
5+
----------
6+
7+
- Compute alignment shifts from the first integration of the science exposure only. [#8643]
48
ami_average
59
-----------
610

docs/jwst/align_refs/description.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ The ``align_refs`` step is one of the coronagraphic-specific steps in the ``coro
88
sub-package that is part of Stage 3 :ref:`calwebb_coron3 <calwebb_coron3>` processing.
99
It computes offsets between science target
1010
images and reference PSF images, and shifts the PSF images into
11-
alignment. This is performed on a per-integration basis for both the science target
12-
data and the reference PSF data. Each integration contained in the stacked PSF data
11+
alignment. The alignment shifts are computed from the first integration and applied to all the
12+
subsequent ones for both the science target data and the reference PSF data.
13+
Each integration contained in the stacked PSF data
1314
(the result of the :ref:`stack_refs <stack_refs_step>`) step is
14-
aligned to each integration within a given science target exposure.
15+
aligned to the first integration within a given science target exposure.
1516
This results in a new product for each science target exposure that contains a stack
16-
of individual PSF images that have been aligned to each integration in the science
17+
of individual PSF images that have been aligned to the first integration in the science
1718
target exposure.
1819

20+
Note that aligning to the first science integration is sufficient because flight data
21+
shows that there are minimal drifts during an observation in line-of-sight pointing, or in PSF
22+
properties.
23+
1924
Shifts between each PSF and target image are computed using the
2025
``scipy.optimize.leastsq`` function. A 2D mask, supplied via a PSFMASK reference file,
2126
is used to indicate pixels to ignore when performing the minimization in the

jwst/coron/imageregistration.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def fourier_imshift(image, shift):
127127
return offset
128128

129129

130-
def align_array(reference, target, mask=None):
130+
def align_array(reference, target, mask=None, return_aligned=True):
131131
"""
132132
Computes shifts between target image (or image "slices") and the reference
133133
image and re-aligns input images to the target.
@@ -160,21 +160,26 @@ def align_array(reference, target, mask=None):
160160

161161
if len(target.shape) == 2:
162162
shifts = align_fourierLSQ(reference, target, mask=mask)
163-
aligned = fourier_imshift(target, -shifts)
163+
if return_aligned:
164+
aligned = fourier_imshift(target, -shifts)
164165

165166
elif len(target.shape) == 3:
166167
nslices = target.shape[0]
167168
shifts = np.empty((nslices, 3), dtype=float)
168-
aligned = np.empty_like(target)
169+
if return_aligned:
170+
aligned = np.empty_like(target)
169171

170172
for m in range(nslices):
171173
sh = align_fourierLSQ(reference, target[m], mask=mask)
172174
shifts[m, :] = sh
173-
aligned[m, :, :] = fourier_imshift(target[m], -sh)
175+
if return_aligned:
176+
aligned[m, :, :] = fourier_imshift(target[m], -sh)
174177

175178
else:
176179
raise ValueError("Input target image must be either a 2D or 3D array.")
177180

181+
if not return_aligned:
182+
return shifts
178183
return aligned, shifts
179184

180185

@@ -216,17 +221,20 @@ def align_models(reference, target, mask):
216221
output_model = QuadModel(quad_shape)
217222
output_model.update(target)
218223

224+
# Compute the shifts of the PSF ("target") images relative to
225+
# the science ("reference") image in the first integration
226+
shifts = align_array(
227+
reference.data[0].astype(np.float64),
228+
target.data.astype(np.float64),
229+
mask=mask.data, return_aligned=False)
230+
219231
# Loop over all integrations of the science exposure
220232
for k in range(nrefslices):
221233

222-
# Compute the shifts of the PSF ("target") images relative to
223-
# the science ("reference") image in this integration, and apply
224-
# the shifts to the PSF images
225-
d, shifts = align_array(
226-
reference.data[k].astype(np.float64),
234+
# Apply the shifts to the PSF images
235+
output_model.data[k] = fourier_imshift(
227236
target.data.astype(np.float64),
228-
mask.data)
229-
output_model.data[k] = d
237+
-shifts)
230238

231239
# Apply the same shifts to the PSF error arrays, if they exist
232240
if target.err is not None:
@@ -237,5 +245,4 @@ def align_models(reference, target, mask):
237245
# TODO: in the future we need to add shifts and other info (such as
238246
# slice ID from the reference image to which target was aligned)
239247
# to output cube metadata (or property).
240-
241248
return output_model

jwst/coron/tests/test_coron.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ def test_align_models():
183183
truth_results_sub = np.array(
184184
[
185185
[[10.0, 11.7, 12.0], [10.036278, 11.138131, 10.180669]],
186-
[[10.053974, 11.1953335, 11.993213], [10.36224, 10.805556, 10.274276]],
187-
[[9.988604, 11.33026, 11.968155], [10.024722, 10.971058, 10.108071]],
186+
[[10.0, 11.7, 12.0], [10.036278, 11.138131, 10.180669]],
187+
[[10.0, 11.7, 12.0], [10.036278, 11.138131, 10.180669]],
188188
]
189189
)
190190

0 commit comments

Comments
 (0)