From 415a805361e837aec84ba9eafb9a8ca8b5c76fbc Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Wed, 16 Jan 2019 09:52:04 +0000 Subject: [PATCH] Added a workaround to use kpc as a valid unit and make sure non-ICRS frames work properly in 3D mode. In addition, set the far_side_visible option appropriately depending on the viewing mode. --- glue_wwt/viewer/layer_artist.py | 31 +++++++++++++++++++++++++------ glue_wwt/viewer/state.py | 2 +- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/glue_wwt/viewer/layer_artist.py b/glue_wwt/viewer/layer_artist.py index c706846..a305e17 100644 --- a/glue_wwt/viewer/layer_artist.py +++ b/glue_wwt/viewer/layer_artist.py @@ -66,7 +66,12 @@ class WWTLayer(LayerArtist): self._coords = [], [] force = True - if force or 'mode' in kwargs or 'frame' in kwargs or 'lon_att' in kwargs or 'lat_att' in kwargs or 'alt_att' in kwargs: + # FIXME: kpc isn't yet a valid unit in WWT/PyWWT: + # https://github.com/WorldWideTelescope/wwt-web-client/pull/197 + # for now we set unit to pc and scale values accordingly, so if the + # unit changes we need to refresh the data just in case + + if force or 'mode' in kwargs or 'frame' in kwargs or 'lon_att' in kwargs or 'lat_att' in kwargs or 'alt_att' in kwargs or 'alt_unit' in kwargs: try: lon = self.layer[self._viewer_state.lon_att] @@ -94,16 +99,20 @@ class WWTLayer(LayerArtist): if len(lon) > 0: - if self._viewer_state.mode == 'Sky': + if self._viewer_state.mode in MODES_3D: + ref_frame = 'Sky' coord = SkyCoord(lon, lat, unit=u.deg, frame=self._viewer_state.frame.lower()).icrs lon = coord.spherical.lon.degree lat = coord.spherical.lat.degree - - if self._viewer_state.mode in MODES_3D: - ref_frame = 'Sky' else: ref_frame = self._viewer_state.mode + # FIXME: kpc isn't yet a valid unit in WWT/PyWWT: + # https://github.com/WorldWideTelescope/wwt-web-client/pull/197 + # for now we set unit to pc and scale values accordingly + if self._viewer_state.alt_unit == 'kpc': + alt = alt * 1000 + tab = Table() tab['lon'] = lon * u.degree tab['lat'] = lat * u.degree @@ -117,13 +126,23 @@ class WWTLayer(LayerArtist): self.wwt_layer = self.wwt_client.layers.add_data_layer(tab, frame=ref_frame, lon_att='lon', lat_att='lat', **alt_att) + self.wwt_layer.far_side_visible = self._viewer_state.mode in MODES_3D + self._coords = lon, lat + force = True + else: return if force or 'alt_unit' in kwargs: - self.wwt_layer.alt_unit = self._viewer_state.alt_unit + # FIXME: kpc isn't yet a valid unit in WWT/PyWWT: + # https://github.com/WorldWideTelescope/wwt-web-client/pull/197 + # for now we set unit to pc and scale values accordingly + if self._viewer_state.alt_unit == 'kpc': + self.wwt_layer.alt_unit = u.pc + else: + self.wwt_layer.alt_unit = self._viewer_state.alt_unit if force or 'alt_type' in kwargs: self.wwt_layer.alt_type = self._viewer_state.alt_type.lower() diff --git a/glue_wwt/viewer/state.py b/glue_wwt/viewer/state.py index 299cb2f..80839ff 100644 --- a/glue_wwt/viewer/state.py +++ b/glue_wwt/viewer/state.py @@ -17,7 +17,7 @@ MODES_BODIES = ['Sun', 'Mercury', 'Venus', 'Earth', 'Moon', 'Mars', MODES_3D = ['Solar System', 'Milky Way', 'Universe'] -ALT_UNITS = [u.m, u.km, u.AU, u.lyr, u.pc, u.Mpc, +ALT_UNITS = [u.m, u.km, u.AU, u.lyr, u.pc, u.kpc, u.Mpc, u.imperial.ft, u.imperial.inch, u.imperial.mi] ALT_TYPES = ['Altitude', 'Depth', 'Distance']