Skip to content

Commit

Permalink
Merge pull request #92 from Carifio24/exception-length
Browse files Browse the repository at this point in the history
Truncate SkyCoord exception if too long
  • Loading branch information
Carifio24 authored Oct 14, 2023
2 parents 2390814 + 075263f commit ee4d1dd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
11 changes: 9 additions & 2 deletions glue_wwt/viewer/table_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions glue_wwt/viewer/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 25 additions & 0 deletions glue_wwt/viewer/tests/test_wwt_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ee4d1dd

Please sign in to comment.