Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imviz: Make the WCS match tool into a pan/zoom with WCS matching tool #613

Merged
merged 3 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 35 additions & 26 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 @@ -17,30 +23,28 @@ class BlinkOnce(Tool):
tool_tip = ('Click on this button to display the next image, '
'or you can also press the "b" key anytime')

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

def activate(self):
self.viewer.blink_once()


@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'

def __init__(self, viewer, **kwargs):
class BqplotMatchWCS(BqplotPanZoomMode):

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 Down Expand Up @@ -72,21 +76,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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pllim - just FYI this is why the home button was inherited by default before. I think we don't actually want the inheritance here because who knows what tools will get added in glue-jupyter in future so I have disabled it for imviz. We should perhaps do this for other jdaviz apps but this is beyond the scope of this PR.


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.
2 changes: 1 addition & 1 deletion notebooks/ImvizExample.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
"metadata": {},
"outputs": [],
"source": [
"data = imviz.app.get_data_from_viewer('viewer-1', 'gc_2mass_j')"
"data = imviz.app.get_data_from_viewer('viewer-1', 'gc_2mass_j[PRIMARY,1]')"
]
},
{
Expand Down