Skip to content

Commit

Permalink
Autocenter coords on viewer if data present
Browse files Browse the repository at this point in the history
  • Loading branch information
duytnguyendtn committed May 22, 2024
1 parent 118c72c commit 73c3579
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
46 changes: 43 additions & 3 deletions jdaviz/configs/default/plugins/virtual_observatory/vo_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
:link="'https://www.ivoa.net/astronomers/index.html'"
:popout_button="popout_button">

<plugin-viewer-select
:items="viewer_items"
:selected.sync="viewer_selected"
label="Viewer"
:show_if_single_entry="false"
hint="Select a viewer to search."
/>

<j-plugin-section-header>Survey Collections</j-plugin-section-header>
<v-row>
<v-select
Expand Down

0 comments on commit 73c3579

Please sign in to comment.