diff --git a/glue_wwt/viewer/table_layer.py b/glue_wwt/viewer/table_layer.py index faea5783..a8593ee4 100644 --- a/glue_wwt/viewer/table_layer.py +++ b/glue_wwt/viewer/table_layer.py @@ -19,6 +19,8 @@ from astropy.coordinates import SkyCoord from astropy.table import Table +from numpy import size + import pywwt from pywwt.layers import TableLayer from distutils.version import LooseVersion @@ -267,8 +269,13 @@ def _update_presentation(self, force=False, **kwargs): try: coord = SkyCoord(lon, lat, unit=u.deg, frame=self._viewer_state.frame.lower()).icrs - except Exception as exc: - self.disable(str(exc)) + except Exception: + if size(lat) < 5: + angle_info = f"{lat}" + else: + angle_info = f"{lat.min()} deg <= angle <= {lat.max()} deg" + disable_msg = f"Latitude angle(s) must be within -90 deg <= angle <= 90 deg, got {angle_info}" + self.disable(disable_msg) return lon = coord.spherical.lon.degree diff --git a/glue_wwt/viewer/tests/test_utils.py b/glue_wwt/viewer/tests/test_utils.py index 92301dc6..2cdd67cb 100644 --- a/glue_wwt/viewer/tests/test_utils.py +++ b/glue_wwt/viewer/tests/test_utils.py @@ -30,3 +30,7 @@ def test_center_fov_non_finite(): assert_allclose(lon_c, 3) assert_allclose(lat_c, 2) assert_allclose(fov, 1) + + +def create_disabled_message(reason): + return "Cannot visualize this layer: %s" % reason diff --git a/glue_wwt/viewer/tests/test_wwt_widget.py b/glue_wwt/viewer/tests/test_wwt_widget.py index 3464b9cc..14c36caf 100644 --- a/glue_wwt/viewer/tests/test_wwt_widget.py +++ b/glue_wwt/viewer/tests/test_wwt_widget.py @@ -14,6 +14,7 @@ from glue_qt.app import GlueApplication from ..qt_data_viewer import WWTQtViewer +from .test_utils import create_disabled_message DATA = os.path.join(os.path.dirname(__file__), 'data') @@ -29,9 +30,13 @@ class TestWWTDataViewer(object): def setup_method(self, method): self.d = Data(x=[1, 2, 3], y=[2, 3, 4], z=[4, 5, 6]) + self.bad_data_short = Data(x=[-100, 100], y=[-10, 10]) + self.bad_data_long = Data(x=[-100, -90, -80, 80, 90, 100], y=[-10, -7, -3, 3, 7, 10]) self.application = GlueApplication() self.dc = self.application.data_collection self.dc.append(self.d) + self.dc.append(self.bad_data_short) + self.dc.append(self.bad_data_long) self.hub = self.dc.hub self.session = self.application.session self.viewer = self.application.new_data_viewer(WWTQtViewerBlocking) @@ -176,6 +181,26 @@ def test_load_session_back_compat(self): assert viewer_state.lat_att.label == 'b' assert viewer_state.frame == 'Galactic' + def test_skycoord_exception_message_short(self): + self.viewer.add_data(self.bad_data_short) + self.viewer.state.lat_att = self.bad_data_short.id['x'] + layer = self.viewer.layers[-1] + assert not layer.enabled + disabled_reason = "Latitude angle(s) must be within -90 deg <= angle <= 90 deg, " \ + f"got {self.bad_data_short['x']}" + disabled_message = create_disabled_message(disabled_reason) + assert layer.disabled_message == disabled_message + + def test_skycoord_exception_message_long(self): + self.viewer.add_data(self.bad_data_long) + self.viewer.state.lat_att = self.bad_data_long.id['x'] + layer = self.viewer.layers[-1] + assert not layer.enabled + disabled_reason = "Latitude angle(s) must be within -90 deg <= angle <= 90 deg, " \ + "got -100 deg <= angle <= 100 deg" + disabled_message = create_disabled_message(disabled_reason) + assert layer.disabled_message == disabled_message + # TODO: determine if the following test is the desired behavior # def test_subsets_not_live_added_if_data_not_present(self): # self.register()