Skip to content

Commit

Permalink
Warn users about potentially misaligned data if WCS linking isn't ena…
Browse files Browse the repository at this point in the history
…bled
  • Loading branch information
duytnguyendtn committed Jul 31, 2024
1 parent c250c1f commit 10d712d
Show file tree
Hide file tree
Showing 3 changed files with 819 additions and 771 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

from jdaviz.configs.imviz.tests.utils import BaseImviz_WCS_WCS
from jdaviz.configs.default.plugins.virtual_observatory.vo_plugin import vo_plugin_label
from jdaviz.configs.imviz.plugins.orientation.orientation import (
orientation_plugin_label,
)


class fake_siaresult:
Expand Down Expand Up @@ -233,7 +236,11 @@ def test_coverage_toggle(self, imviz_helper):
@pytest.mark.filterwarnings("ignore::astropy.wcs.wcs.FITSFixedWarning")
@pytest.mark.filterwarnings("ignore:Some non-standard WCS keywords were excluded")
def test_HSTM51_load_data(self, imviz_helper):
"""Test the full plugin by filling out the form and loading a data product into Imviz"""
"""
Test the full plugin by filling out the form and loading a data product into Imviz.
Also test if the plugin warns user about potentially misaligned data layers
when loading data and WCS linking is not enabled.
"""
# Set Common Args
vo_plugin = self._init_voplugin_M51(imviz_helper)

Expand All @@ -248,12 +255,39 @@ def test_HSTM51_load_data(self, imviz_helper):
vo_plugin.vue_query_resource()
assert len(vo_plugin.table.items) > 0

# Load first data product:
# Load first data product
vo_plugin.table.selected_rows = [vo_plugin.table.items[0]] # Select first entry
vo_plugin.vue_load_selected_data()
assert len(imviz_helper.app.data_collection) == 1
assert "M51_HST.M51" in imviz_helper.data_labels[0]

# Load second data product
imviz_helper.app.state.snackbar_history = [] # Clear snackbar warnings
# User should be warned about misaligned data if WCS linking isn't set
# and there's already data in the data collection
assert (
imviz_helper.plugins[orientation_plugin_label].link_type.selected_item["label"]
== "Pixels"
)
vo_plugin.table.selected_rows = [vo_plugin.table.items[0]] # Select first entry
vo_plugin.vue_load_selected_data()
assert any(
"WCS linking is not enabled; data layers may not be aligned" in d["text"]
for d in imviz_helper.app.state.snackbar_history
)

# Load third data product
imviz_helper.app.state.snackbar_history = [] # Clear snackbar warnings
# If we switch to WCS linking, we shouldn't get a warning anymore
# since the data will be aligned
imviz_helper.plugins[orientation_plugin_label].link_type = "WCS"
vo_plugin.table.selected_rows = [vo_plugin.table.items[0]] # Select first entry
vo_plugin.vue_load_selected_data()
assert all(
"WCS linking is not enabled; data layers may not be aligned" not in d["text"]
for d in imviz_helper.app.state.snackbar_history
)

def test_target_lookup_warnings(self, imviz_helper):
"""
Tests that appropriate errors and guardrails protect the user
Expand Down
21 changes: 17 additions & 4 deletions jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from requests.exceptions import ConnectionError as RequestConnectionError
from traitlets import Bool, Unicode, Any, List, Int, observe

from jdaviz.configs.imviz.plugins.orientation.orientation import (
orientation_plugin_label,
)
from jdaviz.core.events import SnackbarMessage, AddDataMessage, RemoveDataMessage
from jdaviz.core.registries import tray_registry
from jdaviz.core.template_mixin import (
Expand Down Expand Up @@ -94,7 +97,7 @@ def _center_on_data(self, _=None):
viewer.state.reference_data is None
or viewer.state.reference_data.coords is None
):
self.source = ''
self.source = ""
return

# Obtain center point of the current image and convert into sky coordinates
Expand Down Expand Up @@ -127,7 +130,7 @@ def vue_query_registry_resources(self, _=None):

# Can't filter by coverage if we don't have a source to filter on
if self.resource_filter_coverage and not self.source:
errormsg = (
error_msg = (
"Source is required for registry querying when coverage filtering is enabled. "
+ (
"Please enter your coordinates above "
Expand All @@ -136,8 +139,8 @@ def vue_query_registry_resources(self, _=None):
)
+ "or disable coverage filtering."
)
self.hub.broadcast(SnackbarMessage(errormsg, sender=self, color="error"))
raise ValueError(errormsg)
self.hub.broadcast(SnackbarMessage(error_msg, sender=self, color="error"))
raise ValueError(error_msg)

# Clear existing resources list
self.resources = []
Expand Down Expand Up @@ -323,6 +326,16 @@ def _populate_table(

def vue_load_selected_data(self, _=None):
"""Load the files selected by the user in the table"""
if (
self.app._jdaviz_helper.plugins[orientation_plugin_label].link_type != "WCS"
and len(self.app.data_collection) > 0
):
error_msg = (
"WCS linking is not enabled; data layers may not be aligned. To align, "
f"switch link type to WCS in the {orientation_plugin_label} plugin"
)
self.hub.broadcast(SnackbarMessage(error_msg, sender=self, color="warning"))

self.data_loading = True # Start loading spinner
for entry in self.table.selected_rows:
try:
Expand Down
Loading

0 comments on commit 10d712d

Please sign in to comment.