Skip to content

Commit

Permalink
Make the WCS match tool into a pan/zoom with WCS matching tool
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog authored and pllim committed Jun 4, 2021
1 parent 2dc49f1 commit 37cd8c8
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 26 deletions.
59 changes: 35 additions & 24 deletions jdaviz/configs/imviz/plugins/tools.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import time
import os

from echo import delay_callback

from glue.config import viewer_tool
from glue.core import BaseData
from glue_jupyter.bqplot.common.tools import Tool
from glue.viewers.common.tool import CheckableTool
from glue.plugins.wcs_autolinking.wcs_autolinking import wcs_autolink, WCSLink
from glue_jupyter.bqplot.common.tools import BqplotPanZoomMode

__all__ = []

ICON_DIR = os.path.join(os.path.dirname(__file__), '..', '..', '..', 'data', 'icons')


@viewer_tool
class BlinkOnce(Tool):
Expand All @@ -25,22 +31,23 @@ def activate(self):


@viewer_tool
class BqplotMatchWCS(CheckableTool):

icon = 'glue_link'
tool_id = 'bqplot:matchwcs'
action_text = 'Match WCS between images'
tool_tip = 'Click on image to have the other image viewer show the same coordinates'
class BqplotMatchWCS(BqplotPanZoomMode):

def __init__(self, viewer, **kwargs):

super().__init__(viewer, **kwargs)
icon = os.path.join(ICON_DIR, 'pan_wcs.png')
tool_id = 'bqplot:panzoomwcs'
action_text = 'Pan, matching WCS between viwers'
tool_tip = 'Pan and Zoom in this viewer to see the same regions in other viewers'

def activate(self):

self.viewer.add_event_callback(self.on_mouse_or_key_event, events=['click'])
super().activate()

self.viewer.state.add_callback('x_min', self.on_limits_change)
self.viewer.state.add_callback('x_max', self.on_limits_change)
self.viewer.state.add_callback('y_min', self.on_limits_change)
self.viewer.state.add_callback('y_max', self.on_limits_change)

# For now clickling this will automatically set up links between datasets. We
# For now clicking this will automatically set up links between datasets. We
# do this when activating this tool so that this ends up being 'opt-in' only
# when the user wants to match WCS.

Expand All @@ -55,7 +62,6 @@ def activate(self):
if (link.data1 is existing_link.data1
and link.data2 is existing_link.data2):
exists = True
break
if not exists:
self.viewer.session.data_collection.add_link(link)

Expand All @@ -72,21 +78,26 @@ def activate(self):
break
viewer.state.reference_data = self.viewer.state.reference_data

# Trigger a sync so the initial limits match
self.on_limits_change()

def deactivate(self):
self.viewer.remove_event_callback(self.on_mouse_or_key_event)

def on_mouse_or_key_event(self, data):
if data['event'] == 'click':
x = data['domain']['x']
y = data['domain']['y']
dx = self.viewer.state.x_max - self.viewer.state.x_min
dy = self.viewer.state.y_max - self.viewer.state.y_min
for viewer in self.viewer.session.application.viewers:
self.viewer.state.remove_callback('x_min', self.on_limits_change)
self.viewer.state.remove_callback('x_max', self.on_limits_change)
self.viewer.state.remove_callback('y_min', self.on_limits_change)
self.viewer.state.remove_callback('y_max', self.on_limits_change)

super().deactivate()

def on_limits_change(self, *args):
for viewer in self.viewer.session.application.viewers:
if viewer is not self.viewer:
with delay_callback(viewer.state, 'x_min', 'x_max', 'y_min', 'y_max'):
viewer.state.x_min = x - dx / 2
viewer.state.x_max = x + dx / 2
viewer.state.y_min = y - dy / 2
viewer.state.y_max = y + dy / 2
viewer.state.x_min = self.viewer.state.x_min
viewer.state.x_max = self.viewer.state.x_max
viewer.state.y_min = self.viewer.state.y_min
viewer.state.y_max = self.viewer.state.y_max


@viewer_tool
Expand Down
10 changes: 8 additions & 2 deletions jdaviz/configs/imviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@
@viewer_registry("imviz-image-viewer", label="Image 2D (Imviz)")
class ImvizImageView(BqplotImageView):

tools = ['bqplot:panzoom', 'bqplot:contrastbias', 'bqplot:blinkonce', 'bqplot:rectangle',
'bqplot:circle', 'bqplot:matchwcs']
# Whether to inherit tools from glue-jupyter automatically. Set this to
# False to have full control here over which tools are shown in case new
# ones are added in glue-jupyter in future that we don't want here.
inherit_tools = False

tools = ['bqplot:home', 'bqplot:panzoom', 'bqplot:panzoomwcs',
'bqplot:contrastbias', 'bqplot:blinkonce',
'bqplot:rectangle', 'bqplot:circle']
default_class = None

def __init__(self, *args, **kwargs):
Expand Down
Binary file added jdaviz/data/icons/pan_wcs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
211 changes: 211 additions & 0 deletions jdaviz/data/icons/pan_wcs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 37cd8c8

Please sign in to comment.