From 73c35793d5576c7b70091b025ae2879af98cfff0 Mon Sep 17 00:00:00 2001 From: Duy Nguyen Date: Tue, 21 May 2024 22:27:20 -0400 Subject: [PATCH] Autocenter coords on viewer if data present --- .../plugins/virtual_observatory/vo_plugin.py | 46 +++++++++++++++++-- .../plugins/virtual_observatory/vo_plugin.vue | 8 ++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.py b/jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.py index 67dafcb7ad..cb9f61d9e6 100644 --- a/jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.py +++ b/jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.py @@ -9,15 +9,15 @@ from requests.exceptions import ConnectionError as RequestConnectionError from traitlets import Dict, Bool, Unicode, Any, List, Int -from jdaviz.core.events import SnackbarMessage +from jdaviz.core.events import SnackbarMessage, AddDataMessage, RemoveDataMessage from jdaviz.core.registries import tray_registry -from jdaviz.core.template_mixin import PluginTemplateMixin, AddResultsMixin, TableMixin +from jdaviz.core.template_mixin import PluginTemplateMixin, AddResultsMixin, TableMixin, ViewerSelectMixin __all__ = ['VoPlugin'] @tray_registry('VoPlugin', label="Virtual Observatory") -class VoPlugin(PluginTemplateMixin, AddResultsMixin, TableMixin): +class VoPlugin(PluginTemplateMixin, AddResultsMixin, TableMixin, ViewerSelectMixin): """ Plugin to query the Virtual Observatory and load data into Imviz """ template_file = __file__, "vo_plugin.vue" @@ -52,6 +52,46 @@ def __init__(self, *args, **kwargs): self.table.show_rowselect = True self.table.item_key = "URL" + self.hub.subscribe(self, AddDataMessage, handler=self._center_on_data) + self.hub.subscribe(self, RemoveDataMessage, handler=self._center_on_data) + + self.previous_autogen_source = None + + + def _center_on_data(self, _): + """ + If data is present in the default viewer, center the plugin's coordinates on + the viewer's center WCS coordinates. + """ + # This plugin should not overwrite existing user input. + # Immediately exit if the user has entered a value + if self.source not in ('', self.previous_autogen_source): + return + + # gets the current viewer + viewer = self.viewer.selected_obj + + # nothing happens in the case there is no image in the viewer + # additionally if the data does not have WCS + if viewer.state.reference_data is None or viewer.state.reference_data.coords is None: + return + + # obtains the center point of the current image and converts the point into sky coordinates + x_center = (viewer.state.x_min + viewer.state.x_max) * 0.5 + y_center = (viewer.state.y_min + viewer.state.y_max) * 0.5 + skycoord_center = viewer.state.reference_data.coords.pixel_to_world(x_center, y_center) + + # Extract SkyCoord values as strings for plugin display + ra_deg = skycoord_center.ra.deg + dec_deg = skycoord_center.dec.deg + frame = skycoord_center.frame.name.lower() + + # Show center value in plugin + self.source = f"{ra_deg} {dec_deg}" + self.coordframe_selected = frame + self.previous_autogen_source = self.source + + def vue_waveband_selected(self,event): """ Sync waveband selected diff --git a/jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.vue b/jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.vue index 37f0427fb2..798c7a7b7a 100644 --- a/jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.vue +++ b/jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.vue @@ -4,6 +4,14 @@ :link="'https://www.ivoa.net/astronomers/index.html'" :popout_button="popout_button"> + + Survey Collections