forked from spacetelescope/jdaviz
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request spacetelescope#2712 from pllim/this-is-not-the-gre…
…atest-test-in-the-world-no-it-is-just-a-tribute TST: Increase Imviz rotation test coverage
- Loading branch information
Showing
6 changed files
with
192 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,154 @@ | ||
import pytest | ||
|
||
from astropy.table import Table | ||
from numpy.testing import assert_allclose | ||
|
||
from jdaviz.configs.imviz.tests.utils import BaseImviz_WCS_WCS | ||
|
||
|
||
class TestLinksControl(BaseImviz_WCS_WCS): | ||
def test_plugin(self): | ||
lc_plugin = self.imviz.app.get_tray_item_from_name('imviz-orientation') | ||
class TestDefaultOrientation(BaseImviz_WCS_WCS): | ||
def test_affine_reset_and_linktype(self): | ||
lc_plugin = self.imviz.plugins['Orientation'] | ||
|
||
lc_plugin.link_type.selected = 'WCS' | ||
lc_plugin.link_type = 'WCS' | ||
lc_plugin.wcs_use_affine = False | ||
lc_plugin.link_type.selected = 'Pixels' | ||
assert self.imviz.get_link_type("Default orientation", "has_wcs_2[SCI,1]") == "wcs" | ||
|
||
# wcs_use_affine should revert/default to True | ||
# wcs_use_affine should revert/default to True when change back to Pixels. | ||
lc_plugin.link_type = 'Pixels' | ||
assert lc_plugin.wcs_use_affine is True | ||
assert self.imviz.get_link_type("has_wcs_1[SCI,1]", "has_wcs_2[SCI,1]") == "pixels" | ||
|
||
assert self.imviz.get_link_type("has_wcs_1[SCI,1]", "has_wcs_1[SCI,1]") == "self" | ||
|
||
with pytest.raises(ValueError, match=".*combo not found"): | ||
self.imviz.get_link_type("has_wcs_1[SCI,1]", "foo") | ||
|
||
# adding markers should disable changing linking from both UI and API | ||
assert lc_plugin.need_clear_astrowidget_markers is False | ||
def test_astrowidgets_markers_disable_relinking(self): | ||
lc_plugin = self.imviz.plugins['Orientation'] | ||
lc_plugin.link_type = 'Pixels' | ||
|
||
# Adding markers should disable changing linking from both UI and API. | ||
assert lc_plugin._obj.need_clear_astrowidget_markers is False | ||
tbl = Table({'x': (0, 0), 'y': (0, 1)}) | ||
self.viewer.add_markers(tbl, marker_name='xy_markers') | ||
|
||
assert lc_plugin.need_clear_astrowidget_markers is True | ||
assert lc_plugin._obj.need_clear_astrowidget_markers is True | ||
with pytest.raises(ValueError, match="cannot change linking"): | ||
lc_plugin.link_type.selected = 'WCS' | ||
assert lc_plugin.link_type.selected == 'Pixels' | ||
lc_plugin.link_type = 'WCS' | ||
assert lc_plugin.link_type == 'Pixels' | ||
|
||
lc_plugin._obj.vue_reset_astrowidget_markers() | ||
|
||
assert lc_plugin._obj.need_clear_astrowidget_markers is False | ||
lc_plugin.link_type = 'WCS' | ||
|
||
def test_markers_plugin_recompute_positions_pixels_to_wcs(self): | ||
lc_plugin = self.imviz.plugins['Orientation'] | ||
lc_plugin.link_type = 'Pixels' | ||
|
||
# Blink to second image, if we have to. | ||
if self.viewer.top_visible_data_label != "has_wcs_2[SCI,1]": | ||
self.viewer.blink_once() | ||
|
||
label_mouseover = self.imviz.app.session.application._tools['g-coords-info'] | ||
mp = self.imviz.plugins['Markers'] | ||
|
||
with mp.as_active(): | ||
# (1, 0) on second image but same sky coordinates as (0, 0) on first. | ||
label_mouseover._viewer_mouse_event( | ||
self.viewer, {'event': 'mousemove', 'domain': {'x': 1, 'y': 0}}) | ||
mp._obj._on_viewer_key_event(self.viewer, {'event': 'keydown', 'key': 'm'}) | ||
|
||
# (0, 0) on first image. | ||
self.viewer.blink_once() | ||
label_mouseover._viewer_mouse_event( | ||
self.viewer, {'event': 'mousemove', 'domain': {'x': 0, 'y': 0}}) | ||
mp._obj._on_viewer_key_event(self.viewer, {'event': 'keydown', 'key': 'm'}) | ||
|
||
lc_plugin.link_type = 'WCS' | ||
|
||
# Both marks stay the same in sky, so this means X and Y w.r.t. reference | ||
# same on both entries. | ||
# FIXME: 0.25 offset introduced by fake WCS layer (remove AssertionError). | ||
# https://jira.stsci.edu/browse/JDAT-4256 | ||
with pytest.raises(AssertionError): | ||
assert_allclose(mp._obj.marks["imviz-0"].x, 0) | ||
with pytest.raises(AssertionError): | ||
assert_allclose(mp._obj.marks["imviz-0"].y, 0) | ||
|
||
mp.clear_table() | ||
|
||
def test_markers_plugin_recompute_positions_wcs_to_pixels(self): | ||
lc_plugin = self.imviz.plugins['Orientation'] | ||
lc_plugin.link_type = 'WCS' | ||
|
||
# Blink to second image, if we have to. | ||
if self.viewer.top_visible_data_label != "has_wcs_2[SCI,1]": | ||
self.viewer.blink_once() | ||
|
||
label_mouseover = self.imviz.app.session.application._tools['g-coords-info'] | ||
mp = self.imviz.plugins['Markers'] | ||
|
||
with mp.as_active(): | ||
# (0, 0) on second image, but linked by WCS. | ||
label_mouseover._viewer_mouse_event( | ||
self.viewer, {'event': 'mousemove', 'domain': {'x': 0, 'y': 0}}) | ||
mp._obj._on_viewer_key_event(self.viewer, {'event': 'keydown', 'key': 'm'}) | ||
|
||
# (0, 0) on first image. | ||
self.viewer.blink_once() | ||
label_mouseover._viewer_mouse_event( | ||
self.viewer, {'event': 'mousemove', 'domain': {'x': 0, 'y': 0}}) | ||
mp._obj._on_viewer_key_event(self.viewer, {'event': 'keydown', 'key': 'm'}) | ||
|
||
lc_plugin.link_type = 'Pixels' | ||
|
||
# Both marks now get separated, so this means X and Y w.r.t. reference | ||
# are different on both entries. | ||
# FIXME: 0.25 offset introduced by fake WCS layer (remove AssertionError). | ||
# https://jira.stsci.edu/browse/JDAT-4256 | ||
with pytest.raises(AssertionError): | ||
assert_allclose(mp._obj.marks["imviz-0"].x, [1, 0]) | ||
with pytest.raises(AssertionError): | ||
assert_allclose(mp._obj.marks["imviz-0"].y, 0) | ||
|
||
mp.clear_table() | ||
|
||
|
||
class TestNonDefaultOrientation(BaseImviz_WCS_WCS): | ||
def test_N_up_multi_viewer(self): | ||
lc_plugin = self.imviz.plugins['Orientation'] | ||
lc_plugin.link_type = 'WCS' | ||
|
||
# Should automatically be applied as reference to first viewer. | ||
lc_plugin._obj.create_north_up_east_left(set_on_create=True) | ||
|
||
# This would set a different reference to second viewer. | ||
viewer_2 = self.imviz.create_image_viewer() | ||
self.imviz.app.add_data_to_viewer("imviz-1", "has_wcs_1[SCI,1]") | ||
lc_plugin.viewer = "imviz-1" | ||
lc_plugin._obj.create_north_up_east_right(set_on_create=True) | ||
|
||
assert self.viewer.state.reference_data.label == "North-up, East-left" | ||
assert viewer_2.state.reference_data.label == "North-up, East-right" | ||
|
||
# Both viewers should revert back to same reference when pixel-linked. | ||
lc_plugin.link_type = 'Pixels' | ||
assert self.viewer.state.reference_data.label == "has_wcs_1[SCI,1]" | ||
assert viewer_2.state.reference_data.label == "has_wcs_1[SCI,1]" | ||
|
||
lc_plugin.vue_reset_astrowidget_markers() | ||
# FIXME: spacetelescope/jdaviz#2724 (remove AssertionError) | ||
lc_plugin.link_type = 'WCS' | ||
with pytest.raises(AssertionError): | ||
assert self.viewer.state.reference_data.label == "Default orientation" | ||
with pytest.raises(AssertionError): | ||
assert viewer_2.state.reference_data.label == "Default orientation" | ||
|
||
assert lc_plugin.need_clear_astrowidget_markers is False | ||
lc_plugin.link_type.selected = 'WCS' | ||
def test_custom_orientation(self): | ||
lc_plugin = self.imviz.plugins['Orientation'] | ||
lc_plugin.link_type = 'WCS' | ||
lc_plugin.viewer = "imviz-0" | ||
lc_plugin.rotation_angle = 42 # Triggers auto-label | ||
lc_plugin._obj.add_orientation(rotation_angle=None, east_left=True, label=None, | ||
set_on_create=True, wrt_data=None) | ||
assert self.viewer.state.reference_data.label == "CCW 42.00 deg (E-left)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters