Skip to content

Commit

Permalink
BUG: Fix random flip in WCS orientation (spacetelescope#2802)
Browse files Browse the repository at this point in the history
* BUG: Fix random flip in WCS orientation

* TST: Update test results
  • Loading branch information
pllim authored and rosteen committed Apr 18, 2024
1 parent 03d9377 commit 9c8e1f1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ Cubeviz

Imviz
^^^^^

- Fix a bug where footprints did not overlay when created via API. [#2790]

- Improved behavior when orientations are created or selected without having data loaded in the viewer. [#2789]

- Fixed a bug in the Orientation plugin where a WCS orientation could sometimes be flipped. [#2802]

Mosviz
^^^^^^

Expand Down
21 changes: 13 additions & 8 deletions jdaviz/configs/imviz/tests/test_linking.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,21 @@ def test_wcslink_rotated(self):
self.imviz.app.data_collection['fits_wcs[DATA]'])
gwcs_zoom_limits = self.viewer._get_zoom_limits(
self.imviz.app.data_collection['gwcs[DATA]'])

# x_min, y_min
# x_min, y_max
# x_max, y_max
# x_max, y_min
assert_allclose(fits_wcs_zoom_limits,
[[-1.590838, -0.423662],
[-1.826862, 9.896219],
[8.590838, 9.423662],
[8.826862, -0.896219]], rtol=1e-5)
[[-2.406711, -1.588057],
[-2.697746, 11.137127],
[10.148055, 10.554429],
[10.439091, -2.170755]], rtol=1e-5)
assert_allclose(gwcs_zoom_limits,
[[3.186753, 11.337468],
[11.895862, 5.072343],
[6.158421, -3.145985],
[-2.550688, 3.119141]], rtol=1e-5)
[[2.636299, 12.732915],
[13.375281, 5.007547],
[6.300587, -5.126264],
[-4.438394, 2.599103]], rtol=1e-5)

# Also check the coordinates display: Last loaded is on top.
# Cycle order: GWCS, FITS WCS
Expand Down
19 changes: 12 additions & 7 deletions jdaviz/core/freezable_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,18 @@ def _get_reset_limits(self, return_as_world=False):
y_min = min(y_min, world_bottom_left.dec.value)
y_max = max(y_max, world_top_right.dec.value)
else:
pixel_bottom_left = self.reference_data.coords.world_to_pixel(world_bottom_left)
pixel_top_right = self.reference_data.coords.world_to_pixel(world_top_right)

x_min = min(x_min, pixel_bottom_left[0] - 0.5)
x_max = max(x_max, pixel_top_right[0] + 0.5)
y_min = min(y_min, pixel_bottom_left[1] - 0.5)
y_max = max(y_max, pixel_top_right[1] + 0.5)
x_bl, y_bl = self.reference_data.coords.world_to_pixel(world_bottom_left)
x_tr, y_tr = self.reference_data.coords.world_to_pixel(world_top_right)

x_pix_min = min(x_bl, x_tr)
x_pix_max = max(x_bl, x_tr)
y_pix_min = min(y_bl, y_tr)
y_pix_max = max(y_bl, y_tr)

x_min = min(x_min, x_pix_min - 0.5)
x_max = max(x_max, x_pix_max + 0.5)
y_min = min(y_min, y_pix_min - 0.5)
y_max = max(y_max, y_pix_max + 0.5)
wcs_success = True

if not wcs_success:
Expand Down

0 comments on commit 9c8e1f1

Please sign in to comment.