Skip to content

Commit

Permalink
Merge pull request #1558 from pllim/blink-back-to-the-future
Browse files Browse the repository at this point in the history
Allow Shift+b to blink backwards
  • Loading branch information
pllim committed Aug 11, 2022
2 parents 9bf654c + a3a6518 commit feadcb9
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ Imviz

- Auto-populate simple aperture photometry values if JWST data is loaded into viewer. [#1549]

- Pressing Shift+b now blinks backwards. Right-clicking on the image while Blink tool
is active on the toolbar also blinks backwards. [#1558]

Mosviz
^^^^^^

- NIRISS parser now sorts FITS files by header instead of file name. [#819]

Specviz
Expand Down
10 changes: 8 additions & 2 deletions docs/imviz/displayimages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ Blinking
Blinking is an Imviz-specific functionality that allows a user to quickly switch
between viewing two or more images, as long as they are linked (see :ref:`imviz_pan_zoom` for
more on linking behavior). This can be done by selecting the |icon-blink| icon and
then clicking on the image. You can also blink by pressing the "b" key on your
keyboard while moused over the image.
then left-clicking on the image to blink forward; right-clicking would blink backwards.

You can also blink forward by pressing the "b" key on your keyboard while moused over the image.
If you press Shift + "b" ("B"), you may blink backwards.

From the API
------------
Expand All @@ -167,6 +169,10 @@ From the API within the Jupyter notebook::
viewer = imviz.default_viewer
viewer.blink_once()

And to blink backwards::

viewer.blink_once(reversed=True)

Contrast/Bias
=============

Expand Down
8 changes: 4 additions & 4 deletions jdaviz/configs/imviz/plugins/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@ class BlinkOnce(CheckableTool):
icon = os.path.join(ICON_DIR, 'blink.svg')
tool_id = 'jdaviz:blinkonce'
action_text = 'Go to next image'
tool_tip = ('Click on the viewer to display the next image, '
'or you can also press the "b" key anytime')
tool_tip = ('Click on the viewer or press "b" to display the next image, '
'or right-click or press "B" to display the previous')

def activate(self):
self.viewer.add_event_callback(self.on_click, events=['click'])
self.viewer.add_event_callback(self.on_click, events=['click', 'contextmenu'])

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

def on_click(self, data):
self.viewer.blink_once()
self.viewer.blink_once(reversed=data['event']=='contextmenu') # noqa: E225

# Also update the coordinates display.
data['event'] = 'mousemove'
Expand Down
12 changes: 8 additions & 4 deletions jdaviz/configs/imviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def on_mouse_or_key_event(self, data):
elif data['event'] == 'keydown':
key_pressed = data['key']

if key_pressed == 'b':
self.blink_once()
if key_pressed in ('b', 'B'):
self.blink_once(reversed=key_pressed=='B') # noqa: E225

# Also update the coordinates display.
data['event'] = 'mousemove'
Expand All @@ -171,7 +171,7 @@ def on_mouse_or_key_event(self, data):
self.line_profile_xy.selected_viewer = self.reference_id
self.line_profile_xy.vue_draw_plot()

def blink_once(self):
def blink_once(self, reversed=False):
# Simple blinking of images - this will make it so that only one
# layer is visible at a time and cycles through the layers.

Expand All @@ -198,7 +198,11 @@ def blink_once(self):
color='warning', sender=self)
self.session.hub.broadcast(msg)
elif n_visible > 0:
next_layer = valid[(valid.index(visible[-1]) + 1) % n_layers]
if not reversed:
delta = 1
else:
delta = -1
next_layer = valid[(valid.index(visible[-1]) + delta) % n_layers]
self.state.layers[next_layer].visible = True

for ilayer in (set(valid) - set([next_layer])):
Expand Down
3 changes: 2 additions & 1 deletion jdaviz/configs/imviz/tests/test_linking.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def test_wcslink_affine_with_extras(self):

# blink image through clicking with blink tool
self.viewer.toolbar_nested.active_tool_id = 'jdaviz:blinkonce'
self.viewer.toolbar_nested.active_tool.on_click({'domain': {'x': 0, 'y': 0}})
self.viewer.toolbar_nested.active_tool.on_click(
{'event': 'click', 'domain': {'x': 0, 'y': 0}})
assert self.viewer.label_mouseover.pixel == 'x=00.0 y=00.0'
assert self.viewer.label_mouseover.value == '+1.00000e+00 '
assert self.viewer.label_mouseover.world_ra_deg == '337.5202808000'
Expand Down
28 changes: 28 additions & 0 deletions jdaviz/configs/imviz/tests/test_tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import numpy as np

from jdaviz.configs.imviz.tests.utils import BaseImviz_WCS_WCS


Expand Down Expand Up @@ -32,3 +34,29 @@ def test_zoom_tools(self):
v.toolbar_nested.tools['jdaviz:prevzoom'].activate()
assert (v.state.x_min, v.state.x_max, v.state.y_min, v.state.y_max) == (1, 8, 1, 8)
assert (v2.state.x_min, v2.state.x_max, v2.state.y_min, v2.state.y_max) == (1, 8, 1, 8)


def test_blink(imviz_helper):
viewer = imviz_helper.default_viewer

for i in range(3):
imviz_helper.load_data(np.zeros((2, 2)) + i, data_label=f'image_{i}')

# Last loaded is shown first. So, blinking will take you back to the first one.
# Blink forward. The event will also initialize viewer.label_mouseover .
viewer.on_mouse_or_key_event({'event': 'keydown', 'key': 'b', 'domain': {'x': 0, 'y': 0}})
assert viewer.label_mouseover.value == '+0.00000e+00 '

# Blink forward again and update coordinates info panel.
viewer.blink_once()
viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 0, 'y': 0}})
assert viewer.label_mouseover.value == '+1.00000e+00 '

# Blink backward.
viewer.blink_once(reversed=True)
viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 0, 'y': 0}})
assert viewer.label_mouseover.value == '+0.00000e+00 '

# Blink backward again.
viewer.on_mouse_or_key_event({'event': 'keydown', 'key': 'B', 'domain': {'x': 0, 'y': 0}})
assert viewer.label_mouseover.value == '+2.00000e+00 '

0 comments on commit feadcb9

Please sign in to comment.