From 4b9a3b23d8df5ae7f961f226ed51c23100030991 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Thu, 22 Apr 2021 15:15:50 +0100 Subject: [PATCH 01/10] Move coordinates overlay to toolbar --- jdaviz/app.py | 3 ++ jdaviz/configs/imviz/imviz.yaml | 1 + jdaviz/configs/imviz/plugins/__init__.py | 1 + .../imviz/plugins/coords_info/__init__.py | 1 + .../imviz/plugins/coords_info/coords_info.py | 15 ++++++++ .../imviz/plugins/coords_info/coords_info.vue | 7 ++++ jdaviz/configs/imviz/plugins/viewers.py | 35 +++++++++++-------- 7 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 jdaviz/configs/imviz/plugins/coords_info/__init__.py create mode 100644 jdaviz/configs/imviz/plugins/coords_info/coords_info.py create mode 100644 jdaviz/configs/imviz/plugins/coords_info/coords_info.vue diff --git a/jdaviz/app.py b/jdaviz/app.py index 94f09479d7..18b8a43aeb 100644 --- a/jdaviz/app.py +++ b/jdaviz/app.py @@ -1195,6 +1195,8 @@ def compose_viewer_area(viewer_area_items): 'widget': "IPY_MODEL_" + tool.model_id }) + self._application_handler._tools[name] = tool + for name in config.get('tray', []): tray = tray_registry.members.get(name) tray_item_instance = tray.get('cls')(app=self) @@ -1210,6 +1212,7 @@ def _reset_state(self): """ Resets the application state """ self.state = ApplicationState() self.state.add_callback('stack_items', self.vue_relayout) + self._application_handler._tools = {} def get_configuration(self, path=None, section=None): """ Returns a copy of the application configuration diff --git a/jdaviz/configs/imviz/imviz.yaml b/jdaviz/configs/imviz/imviz.yaml index 0e5f5063a8..70190a28bf 100644 --- a/jdaviz/configs/imviz/imviz.yaml +++ b/jdaviz/configs/imviz/imviz.yaml @@ -15,6 +15,7 @@ toolbar: - g-data-tools - g-subset-tools - g-image-viewer-creator + - g-coords-info viewer_area: - container: col children: diff --git a/jdaviz/configs/imviz/plugins/__init__.py b/jdaviz/configs/imviz/plugins/__init__.py index 6d796de9f7..b55503e340 100644 --- a/jdaviz/configs/imviz/plugins/__init__.py +++ b/jdaviz/configs/imviz/plugins/__init__.py @@ -2,3 +2,4 @@ from .viewers import * # noqa from .image_viewer_creator import * # noqa from .parsers import * # noqa +from .coords_info import * # noqa diff --git a/jdaviz/configs/imviz/plugins/coords_info/__init__.py b/jdaviz/configs/imviz/plugins/coords_info/__init__.py new file mode 100644 index 0000000000..70e5767700 --- /dev/null +++ b/jdaviz/configs/imviz/plugins/coords_info/__init__.py @@ -0,0 +1 @@ +from .coords_info import * # noqa diff --git a/jdaviz/configs/imviz/plugins/coords_info/coords_info.py b/jdaviz/configs/imviz/plugins/coords_info/coords_info.py new file mode 100644 index 0000000000..6b18c84a4b --- /dev/null +++ b/jdaviz/configs/imviz/plugins/coords_info/coords_info.py @@ -0,0 +1,15 @@ +from traitlets import Unicode + +from jdaviz.core.registries import tool_registry +from jdaviz.core.template_mixin import TemplateMixin +from jdaviz.utils import load_template + +__all__ = ['CoordsInfo'] + + +@tool_registry('g-coords-info') +class CoordsInfo(TemplateMixin): + template = load_template("coords_info.vue", __file__).tag(sync=True) + pixel = Unicode("").tag(sync=True) + world = Unicode("").tag(sync=True) + data = Unicode("").tag(sync=True) diff --git a/jdaviz/configs/imviz/plugins/coords_info/coords_info.vue b/jdaviz/configs/imviz/plugins/coords_info/coords_info.vue new file mode 100644 index 0000000000..5ea55503a8 --- /dev/null +++ b/jdaviz/configs/imviz/plugins/coords_info/coords_info.vue @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/jdaviz/configs/imviz/plugins/viewers.py b/jdaviz/configs/imviz/plugins/viewers.py index edf8aac87d..23d7431e85 100644 --- a/jdaviz/configs/imviz/plugins/viewers.py +++ b/jdaviz/configs/imviz/plugins/viewers.py @@ -3,8 +3,6 @@ from glue.core import BaseData from glue_jupyter.bqplot.image import BqplotImageView -from bqplot import Label - from jdaviz.core.registries import viewer_registry __all__ = ['ImvizImageView'] @@ -21,9 +19,7 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.label_mouseover = Label(x=[0.05], y=[0.05], text=[''], - default_size=12, colors=['orange']) - self.figure.marks = self.figure.marks + [self.label_mouseover] + self.label_mouseover = None self.add_event_callback(self.on_mouse_or_key_event, events=['mousemove', 'keydown']) @@ -34,6 +30,12 @@ def on_mouse_or_key_event(self, data): if len(self.state.layers) == 0: return + if self.label_mouseover is None: + if 'g-coords-info' in self.session.application._tools: + self.label_mouseover = self.session.application._tools['g-coords-info'] + else: + return + if data['event'] == 'mousemove': # Display the current cursor coordinates (both pixel and world) as @@ -44,31 +46,36 @@ def on_mouse_or_key_event(self, data): x = data['domain']['x'] y = data['domain']['y'] - overlay = f'x={x:.1f} y={y:.1f}' + self.label_mouseover.pixel = f'x={x:5.1f} y={y:5.1f}' image = self.state.layers[0].layer if isinstance(image.coords, BaseHighLevelWCS): - # Convert these to a SkyCoord via WCS - note that for other datasets # we aren't actually guaranteed to get a SkyCoord out, just for images # with valid celestial WCS try: - celestial_coordinates = image.coords.pixel_to_world(x, y).icrs.to_string('hmsdms') # noqa: E501 - overlay += f' ICRS={celestial_coordinates}' + celestial_coordinates = (image.coords.pixel_to_world(x, y).icrs + .to_string('hmsdms', precision=4, pad=True)) except Exception: - overlay += ' ICRS=unknown' + self.label_mouseover.world = '' + else: + self.label_mouseover.world = f'ICRS={celestial_coordinates:32s}' + else: + self.label_mouseover.world = '' # Extract data values at this position if x > -0.5 and y > -0.5 and x < image.shape[1] - 0.5 and y < image.shape[0] - 0.5: value = image.get_data(image.main_components[0])[int(round(y)), int(round(x))] - overlay += f' data={value:.2g}' - - self.label_mouseover.text = [overlay] + self.label_mouseover.data += f'data={value:10.2g}' + else: + self.label_mouseover.data = '' elif data['event'] == 'mouseleave' or data['event'] == 'mouseenter': - self.label_mouseover.text = "" + self.label_mouseover.pixel = "" + self.label_mouseover.world = "" + self.label_mouseover.data = "" if data['event'] == 'keydown' and data['key'] == 'b': From 68ac3cef78708abf5efd0af7ed98839b75b99d60 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Thu, 22 Apr 2021 16:06:45 +0100 Subject: [PATCH 02/10] Fix layout --- jdaviz/app.vue | 2 +- .../imviz/plugins/coords_info/coords_info.py | 2 +- .../imviz/plugins/coords_info/coords_info.vue | 2 +- jdaviz/configs/imviz/plugins/viewers.py | 14 ++++++++------ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/jdaviz/app.vue b/jdaviz/app.vue index 0b8df86e7c..33b834719f 100644 --- a/jdaviz/app.vue +++ b/jdaviz/app.vue @@ -1,6 +1,6 @@ \ No newline at end of file diff --git a/jdaviz/configs/imviz/plugins/viewers.py b/jdaviz/configs/imviz/plugins/viewers.py index 23d7431e85..5c1a47c99c 100644 --- a/jdaviz/configs/imviz/plugins/viewers.py +++ b/jdaviz/configs/imviz/plugins/viewers.py @@ -21,7 +21,8 @@ def __init__(self, *args, **kwargs): self.label_mouseover = None - self.add_event_callback(self.on_mouse_or_key_event, events=['mousemove', 'keydown']) + self.add_event_callback(self.on_mouse_or_key_event, events=['mousemove', 'mouseenter', + 'mouseleave', 'keydown']) self.state.show_axes = False @@ -34,6 +35,7 @@ def on_mouse_or_key_event(self, data): if 'g-coords-info' in self.session.application._tools: self.label_mouseover = self.session.application._tools['g-coords-info'] else: + print('tool not found in ', self.session.application._tools) return if data['event'] == 'mousemove': @@ -56,26 +58,26 @@ def on_mouse_or_key_event(self, data): # with valid celestial WCS try: celestial_coordinates = (image.coords.pixel_to_world(x, y).icrs - .to_string('hmsdms', precision=4, pad=True)) + .to_string('hmsdms', precision=4, pad=True)) except Exception: self.label_mouseover.world = '' else: - self.label_mouseover.world = f'ICRS={celestial_coordinates:32s}' + self.label_mouseover.world = f'{celestial_coordinates:32s} (ICRS)' else: self.label_mouseover.world = '' # Extract data values at this position if x > -0.5 and y > -0.5 and x < image.shape[1] - 0.5 and y < image.shape[0] - 0.5: value = image.get_data(image.main_components[0])[int(round(y)), int(round(x))] - self.label_mouseover.data += f'data={value:10.2g}' + self.label_mouseover.value = f'{value:10.2g}' else: - self.label_mouseover.data = '' + self.label_mouseover.value = '' elif data['event'] == 'mouseleave' or data['event'] == 'mouseenter': self.label_mouseover.pixel = "" self.label_mouseover.world = "" - self.label_mouseover.data = "" + self.label_mouseover.value = "" if data['event'] == 'keydown' and data['key'] == 'b': From 6e393b27cf30026d747a6c22ac6b336dea8d7cd4 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Thu, 22 Apr 2021 16:12:22 +0100 Subject: [PATCH 03/10] Use default app bar height --- jdaviz/app.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdaviz/app.vue b/jdaviz/app.vue index 33b834719f..8c0df5ccf3 100644 --- a/jdaviz/app.vue +++ b/jdaviz/app.vue @@ -1,6 +1,6 @@