8000 JP-3785: Add tangent plane transform corrections in NIRSpec spectral resampling by hayescr · Pull Request #8908 · spacetelescope/jwst · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

JP-3785: Add tangent plane transform corrections in NIRSpec spectral resampling #8908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/8908.resample_spec.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update NIRSpec spectral resampling to add a missing correction factor in resampled WCS tangent plane transformation.
73 changes: 40 additions & 33 deletions jwst/resample/resample_spec.py
AA5A
Original file line number Diff line number Diff line change
Expand Up @@ -335,32 +335,43 @@
raise ValueError("Not enough data to construct output WCS.")

# Find the spatial extent in x/y tangent
min_tan, max_tan = self._max_spatial_extent(all_wcs, undist2sky.inverse, swap_xy)
diff = np.abs(max_tan - min_tan)
if swap_xy:
pix_to_tan_slope = np.abs(pix_to_ytan.slope)
slope_sign = np.sign(pix_to_ytan.slope)
else:
pix_to_tan_slope = np.abs(pix_to_xtan.slope)
slope_sign = np.sign(pix_to_xtan.slope)
min_tan_x, max_tan_x, min_tan_y, max_tan_y = self._max_spatial_extent(
all_wcs, undist2sky.inverse)
diff_y = np.abs(max_tan_y - min_tan_y)
diff_x = np.abs(max_tan_x - min_tan_x)

pix_to_tan_slope_y = np.abs(pix_to_ytan.slope)
slope_sign_y = np.sign(pix_to_ytan.slope)
pix_to_tan_slope_x = np.abs(pix_to_xtan.slope)
slope_sign_x = np.sign(pix_to_xtan.slope)

# Image size in spatial dimension from the maximum slope
# and tangent offset span, plus one pixel to make sure
# we catch all the data
ny = int(np.ceil(diff / pix_to_tan_slope)) + 1
if swap_xy:
ny = int(np.ceil(diff_y / pix_to_tan_slope_y)) + 1
else:
ny = int(np.ceil(diff_x / pix_to_tan_slope_x)) + 1

Check warning on line 354 in jwst/resample/resample_spec.py

View check run for this annotation

Codecov / codecov/patch

jwst/resample/resample_spec.py#L354

Added line #L354 was not covered by tests

# Correct the intercept for the new minimum value.
# Also account for integer pixel size to make sure the
# data is centered in the array.
offset = ny/2 * pix_to_tan_slope - diff/2
if slope_sign > 0:
zero_value = min_tan
offset_y = ny/2 * pix_to_tan_slope_y - diff_y/2
offset_x = ny/2 * pix_to_tan_slope_x - diff_x/2

if slope_sign_y > 0:
zero_value_y = min_tan_y

Check warning on line 363 in jwst/resample/resample_spec.py

View check run for this annotation

Codecov / codecov/patch

jwst/resample/resample_spec.py#L363

Added line #L363 was not covered by tests
else:
zero_value = max_tan
if swap_xy:
pix_to_ytan.intercept = zero_value - slope_sign * offset
zero_value_y = max_tan_y

if slope_sign_x > 0:
zero_value_x = min_tan_x
else:
pix_to_xtan.intercept = zero_value - slope_sign * offset
zero_value_x = max_tan_x

Check warning on line 370 in jwst/resample/resample_spec.py

View check run for this annotation

Codecov / codecov/patch

jwst/resample/resample_spec.py#L370

Added line #L370 was not covered by tests


pix_to_ytan.intercept = zero_value_y - slope_sign_y * offset_y
pix_to_xtan.intercept = zero_value_x - slope_sign_x * offset_x

# Now set up the final transforms

Expand Down Expand Up @@ -447,12 +458,12 @@

return output_wcs

def _max_spatial_extent(self, wcs_list, transform, swap_xy):
def _max_spatial_extent(self, wcs_list, transform):
"""
Compute min & max spatial coordinates for all nods in the "virtual"
slit frame.
Compute spatial coordinate limits for all nods in the tangent plane.
"""
min_tan_all, max_tan_all = np.inf, -np.inf
limits_x = [np.inf, -np.inf]
limits_y = [np.inf, -np.inf]
for wcs in wcs_list:
x, y = wcstools.grid_from_bounding_box(wcs.bounding_box)
ra, dec, _ = wcs(x, y)
Expand All @@ -462,20 +473,16 @@
dec = dec[good]

xtan, ytan = transform(ra, dec)
if swap_xy:
tan_all = ytan
else:
tan_all = xtan

min_tan = np.min(tan_all)
max_tan = np.max(tan_all)
for tan_all, limits in zip([xtan, ytan], [limits_x, limits_y]):
min_tan = np.min(tan_all)
max_tan = np.max(tan_all)

if min_tan < min_tan_all:
min_tan_all = min_tan
if max_tan > max_tan_all:
max_tan_all = max_tan
if min_tan < limits[0]:
limits[0] = min_tan
if max_tan > limits[1]:
limits[1] = max_tan

return min_tan_all, max_tan_all
return *limits_x, *limits_y

def build_interpolated_output_wcs(self, input_models):
"""
Expand Down Expand Up @@ -944,4 +951,4 @@
fiducial = wcs(center_x, center_y)

pixel_scale = compute_scale(wcs, fiducial, disp_axis=disp_axis)
return float(pixel_scale)
return float(pixel_scale)
Loading
0