From 215048fe2a969b6f0714d3775bd81a2c0b0e5e13 Mon Sep 17 00:00:00 2001 From: Jonathan Carifio Date: Fri, 17 Feb 2023 21:42:31 -0500 Subject: [PATCH 1/6] Add camera parameters to glue state of viewer. --- glue_wwt/viewer/data_viewer.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/glue_wwt/viewer/data_viewer.py b/glue_wwt/viewer/data_viewer.py index 28e24b9d..0fbaeef6 100644 --- a/glue_wwt/viewer/data_viewer.py +++ b/glue_wwt/viewer/data_viewer.py @@ -2,6 +2,8 @@ from __future__ import absolute_import, division, print_function +from astropy.coordinates import SkyCoord +import astropy.units as u from glue.core.coordinates import WCSCoordinates from .image_layer import WWTImageLayerArtist @@ -84,3 +86,26 @@ def get_data_layer_artist(self, layer=None, layer_state=None): def get_subset_layer_artist(self, layer=None, layer_state=None): # At some point maybe we'll use different classes for this? return self.get_data_layer_artist(layer=layer, layer_state=layer_state) + + def __gluestate__(self, context): + state = super(WWTDataViewerBase, self).__gluestate__(context) + + center = self._wwt.get_center() + state["camera"] = { + "ra": center.ra.deg, + "dec": center.dec.deg, + "fov": self._wwt.get_fov().value + } + return state + + @classmethod + def __setgluestate__(cls, rec, context): + viewer = super(WWTDataViewerBase, cls).__setgluestate__(rec, context) + if "camera" in rec: + camera = rec["camera"] + ra = camera.get("ra", 0) + dec = camera.get("dec", 0) + fov = camera.get("fov", 60) + viewer._wwt.center_on_coordinates(SkyCoord(ra, dec, unit=u.deg), fov=fov * u.deg, instant=True) + return viewer + From 60b8ed5f7851607cd0710d52ec51af247cb94948 Mon Sep 17 00:00:00 2001 From: Jonathan Carifio Date: Sun, 19 Feb 2023 18:15:02 -0500 Subject: [PATCH 2/6] Only set sky-relevant parameters when in sky mode. --- glue_wwt/viewer/data_viewer.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/glue_wwt/viewer/data_viewer.py b/glue_wwt/viewer/data_viewer.py index 0fbaeef6..8d3da8c3 100644 --- a/glue_wwt/viewer/data_viewer.py +++ b/glue_wwt/viewer/data_viewer.py @@ -27,7 +27,6 @@ class WWTDataViewerBase(object): } _UPDATE_SETTINGS = [ - "foreground", "background", "foreground_opacity", "galactic", "equatorial_grid", "equatorial_grid_color", "equatorial_text", "ecliptic_grid", "ecliptic_grid_color", "ecliptic_text", "alt_az_grid", "alt_az_grid_color", "alt_az_text", @@ -39,6 +38,8 @@ class WWTDataViewerBase(object): "precession_chart_color" ] + _IMAGERY_UPDATE_SETTINGS = ["foreground", "background", "foreground_opacity", "galactic"] + def __init__(self): self._initialize_wwt() self._wwt.actual_planet_scale = True @@ -57,6 +58,7 @@ def _update_wwt(self, force=False, **kwargs): self._wwt.solar_system.cosmos = self.state.mode == 'Universe' # Only show local stars when not in Universe or Milky Way mode self._wwt.solar_system.stars = self.state.mode not in ['Universe', 'Milky Way'] + force = True if force or 'constellation_boundaries' in kwargs: self._wwt.constellation_boundaries = self.state.constellation_boundaries != 'None' @@ -66,6 +68,12 @@ def _update_wwt(self, force=False, **kwargs): if force or setting in kwargs: wwt_attr = self._GLUE_TO_WWT_ATTR_MAP.get(setting, setting) setattr(self._wwt, wwt_attr, getattr(self.state, setting, None)) + + show_imagery = self.state.mode == 'Sky' + if show_imagery: + for setting in self._IMAGERY_UPDATE_SETTINGS: + if force or setting in kwargs: + setattr(self._wwt, setting, getattr(self.state, setting, None)) def get_layer_artist(self, cls, **kwargs): "In this package, we must override to append the wwt_client argument." @@ -108,4 +116,3 @@ def __setgluestate__(cls, rec, context): fov = camera.get("fov", 60) viewer._wwt.center_on_coordinates(SkyCoord(ra, dec, unit=u.deg), fov=fov * u.deg, instant=True) return viewer - From b35e708f724343b4738d52baaea2b24fcfa50bcf Mon Sep 17 00:00:00 2001 From: Jonathan Carifio Date: Wed, 8 Mar 2023 00:48:59 -0500 Subject: [PATCH 3/6] Catch a possible error from the WWT viewer not responding during serialization. --- glue_wwt/viewer/data_viewer.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/glue_wwt/viewer/data_viewer.py b/glue_wwt/viewer/data_viewer.py index 8d3da8c3..44f346ca 100644 --- a/glue_wwt/viewer/data_viewer.py +++ b/glue_wwt/viewer/data_viewer.py @@ -5,6 +5,7 @@ from astropy.coordinates import SkyCoord import astropy.units as u from glue.core.coordinates import WCSCoordinates +from pywwt import ViewerNotAvailableError from .image_layer import WWTImageLayerArtist from .table_layer import WWTTableLayerArtist @@ -97,13 +98,16 @@ def get_subset_layer_artist(self, layer=None, layer_state=None): def __gluestate__(self, context): state = super(WWTDataViewerBase, self).__gluestate__(context) - - center = self._wwt.get_center() - state["camera"] = { - "ra": center.ra.deg, - "dec": center.dec.deg, - "fov": self._wwt.get_fov().value - } + try: + center = self._wwt.get_center() + camera = { + "ra": center.ra.deg, + "dec": center.dec.deg, + "fov": self._wwt.get_fov().value + } + state["camera"] = camera + except ViewerNotAvailableError: + pass return state @classmethod From 98e4373b3fc3e2dc6106704f5e8a132e274ef6c8 Mon Sep 17 00:00:00 2001 From: Jon Carifio Date: Wed, 8 Mar 2023 12:30:26 -0500 Subject: [PATCH 4/6] If the camera serialization fails, log a message rather than being silent. --- glue_wwt/viewer/data_viewer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/glue_wwt/viewer/data_viewer.py b/glue_wwt/viewer/data_viewer.py index 44f346ca..1ade8390 100644 --- a/glue_wwt/viewer/data_viewer.py +++ b/glue_wwt/viewer/data_viewer.py @@ -5,6 +5,7 @@ from astropy.coordinates import SkyCoord import astropy.units as u from glue.core.coordinates import WCSCoordinates +from glue.logger import logger from pywwt import ViewerNotAvailableError from .image_layer import WWTImageLayerArtist @@ -107,7 +108,7 @@ def __gluestate__(self, context): } state["camera"] = camera except ViewerNotAvailableError: - pass + logger.error("Unable to export camera parameters as WWT viewer is not responding.") return state @classmethod From 079e093ba5bf6beb2c5f75b690cdf033484604d0 Mon Sep 17 00:00:00 2001 From: Jon Carifio Date: Wed, 8 Mar 2023 14:40:50 -0500 Subject: [PATCH 5/6] Support roll angle functionality in future versions of pywwt. --- glue_wwt/viewer/data_viewer.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/glue_wwt/viewer/data_viewer.py b/glue_wwt/viewer/data_viewer.py index 1ade8390..15957c2b 100644 --- a/glue_wwt/viewer/data_viewer.py +++ b/glue_wwt/viewer/data_viewer.py @@ -106,6 +106,8 @@ def __gluestate__(self, context): "dec": center.dec.deg, "fov": self._wwt.get_fov().value } + if hasattr(self._wwt, 'get_roll'): + camera["roll"] = self._wwt.get_roll().value state["camera"] = camera except ViewerNotAvailableError: logger.error("Unable to export camera parameters as WWT viewer is not responding.") @@ -119,5 +121,9 @@ def __setgluestate__(cls, rec, context): ra = camera.get("ra", 0) dec = camera.get("dec", 0) fov = camera.get("fov", 60) - viewer._wwt.center_on_coordinates(SkyCoord(ra, dec, unit=u.deg), fov=fov * u.deg, instant=True) + roll = camera.get("roll", None) + camera_kwargs = dict(fov=fov * u.deg, instant=True) + if hasattr(viewer._wwt, 'get_roll') and roll is not None: + camera_kwargs["roll"] = roll * u.deg + viewer._wwt.center_on_coordinates(SkyCoord(ra, dec, unit=u.deg), **camera_kwargs) return viewer From 2580aade548c1d6dfe4cc043ecf5b027598a56d1 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Thu, 30 Nov 2023 17:10:46 -0500 Subject: [PATCH 6/6] Codestyle fixes. --- glue_wwt/viewer/data_viewer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glue_wwt/viewer/data_viewer.py b/glue_wwt/viewer/data_viewer.py index 15957c2b..30ca01c5 100644 --- a/glue_wwt/viewer/data_viewer.py +++ b/glue_wwt/viewer/data_viewer.py @@ -70,7 +70,7 @@ def _update_wwt(self, force=False, **kwargs): if force or setting in kwargs: wwt_attr = self._GLUE_TO_WWT_ATTR_MAP.get(setting, setting) setattr(self._wwt, wwt_attr, getattr(self.state, setting, None)) - + show_imagery = self.state.mode == 'Sky' if show_imagery: for setting in self._IMAGERY_UPDATE_SETTINGS: