Skip to content
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

Backport PR 2802 to v3.9.x (BUG: Fix random flip in WCS orientation) #2804

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ Cubeviz

Imviz
^^^^^

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

- 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
Loading