From 2e6155362e1c51a04fa574642c979a782c5bc467 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Fri, 10 Feb 2023 21:05:10 -0500 Subject: [PATCH] log info from coords_info mouseover display --- .../default/plugins/markers/markers.py | 41 +++++++------------ .../imviz/plugins/coords_info/coords_info.py | 21 ++++++++++ 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/jdaviz/configs/default/plugins/markers/markers.py b/jdaviz/configs/default/plugins/markers/markers.py index e0691f1301..5d1c5d5e15 100644 --- a/jdaviz/configs/default/plugins/markers/markers.py +++ b/jdaviz/configs/default/plugins/markers/markers.py @@ -33,10 +33,19 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) headers = ['x', 'y'] - if self.config in ['imviz', 'cubeviz', 'mosviz', 'specviz2d']: - headers += ['viewer'] - if self.config in ['imviz', 'cubeviz']: - headers += ['data_label'] + if self.config in ['imviz', 'cubeviz', 'mosviz']: + # image viewers + headers += ['RA (ICRS)', 'DEC (ICRS)', + 'RA (deg)', 'DEC (deg)', + 'Value', 'viewer'] + if self.config in ['specviz', 'specviz2d', 'mosviz']: + # 1d spectrum viewers + headers += ['Spectral Axis', 'Pixel', 'Flux'] + if self.config in ['specviz2d', 'mosviz']: + # 2d spectrum viewers + headers += [] + + headers += ['data_label'] self.table.headers_avail = headers self.table.headers_visible = headers @@ -77,34 +86,14 @@ def _on_viewer_key_event(self, viewer, data): # TODO: refactor to share code with mouseover display if PR#1976 merged # TODO: merge with mouseover display entirely and show mouseover info in table - x = data['domain']['x'] - y = data['domain']['y'] - - if x is None or y is None: # Out of bounds - return - - row_info = {'x': x, 'y': y} + row_info = self.app.session.application._tools['g-coords-info'].as_dict() if 'viewer' in self.table.headers_avail: row_info['viewer'] = viewer.reference_id - if isinstance(viewer, BqplotImageView): - # TODO: access viewer.active_image_layer if PR#1976 merged - visible_layers = [layer for layer in viewer.state.layers - if (layer.visible and (layer_is_image_data(layer.layer) or layer_is_cube_image_data(layer.layer)))] # noqa - - if len(visible_layers) == 0: - return - - active_layer = visible_layers[-1] - - row_info['data_label'] = active_layer.layer.label - elif 'data_label' in self.table.headers_avail: - row_info['data_label'] = '' - self.table.add_item(row_info) - self._get_mark(viewer).append_xy(x, y) + self._get_mark(viewer).append_xy(row_info['x'], row_info['y']) def clear_table(self): """ diff --git a/jdaviz/configs/imviz/plugins/coords_info/coords_info.py b/jdaviz/configs/imviz/plugins/coords_info/coords_info.py index 51d79af308..cafac23087 100644 --- a/jdaviz/configs/imviz/plugins/coords_info/coords_info.py +++ b/jdaviz/configs/imviz/plugins/coords_info/coords_info.py @@ -42,6 +42,7 @@ class CoordsInfo(TemplateMixin): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._marks = {} + self._dict = {} # dictionary representation of current mouseover info self._x, self._y = None, None # latest known cursor positions # subscribe/unsubscribe to mouse events across all existing viewers @@ -90,6 +91,9 @@ def as_text(self): f"{self.row2_title} {self.row2_text}".strip(), f"{self.row3_title} {self.row3_text}".strip()) + def as_dict(self): + return self._dict + def reset_coords_display(self): self.row1a_title = '\u00A0' # to force empty line if no other content self.row1a_text = "" @@ -106,6 +110,7 @@ def reset_coords_display(self): self.row3_unreliable = False self.icon = "" + self._dict = {} def _viewer_mouse_clear_event(self, viewer, data=None): self.reset_coords_display() @@ -166,9 +171,13 @@ def _image_viewer_update(self, viewer, x, y): image = active_layer.layer self.icon = self.app.state.layer_icons.get(image.label, '') # noqa + self._dict['data_label'] = image.label unreliable_pixel, unreliable_world = False, False + self._dict['x'] = x + self._dict['y'] = y + # separate logic for each viewer type, ultimately needs to result in extracting sky coords if isinstance(viewer, ImvizImageView): x, y, coords_status, (unreliable_world, unreliable_pixel) = viewer._get_real_xy(image, x, y) # noqa @@ -235,6 +244,10 @@ def _image_viewer_update(self, viewer, x, y): self.row3_title = '' self.row3_text = f'{world_ra_deg} {world_dec_deg} (deg)' self.row3_unreliable = unreliable_world + self._dict['RA (ICRS)'] = world_ra + self._dict['DEC (ICRS)'] = world_dec + self._dict['RA (deg)'] = float(world_ra_deg) + self._dict['DEC (deg)'] = float(world_dec_deg) else: self.row2_title = '\u00A0' self.row2_text = "" @@ -281,6 +294,7 @@ def _image_viewer_update(self, viewer, x, y): value = arr[int(round(y)), int(round(x))] self.row1b_title = 'Value' self.row1b_text = f'{value:+10.5e} {unit}' + self._dict['Value'] = value * u.Unit(unit) else: self.row1b_title = '' self.row1b_text = '' @@ -289,6 +303,9 @@ def _spectrum_viewer_update(self, viewer, x, y): self.row1a_title = 'Cursor' self.row1a_text = f'{x:10.5e}, {y:10.5e}' + self._dict['x'] = x + self._dict['y'] = y + # show the locked marker/coords only if either no tool or the default tool is active locking_active = viewer.toolbar.active_tool_id in viewer.toolbar.default_tool_priority + [None] # noqa if not locking_active: @@ -346,6 +363,7 @@ def _spectrum_viewer_update(self, viewer, x, y): closest_wave = cur_wave closest_flux = cur_flux closest_icon = self.app.state.layer_icons.get(lyr.layer.label) + self._dict['data_label'] = lyr.layer.label except Exception: # nosec # Something is loaded but not the right thing continue @@ -356,11 +374,14 @@ def _spectrum_viewer_update(self, viewer, x, y): self.row2_title = 'Wave' self.row2_text = f'{closest_wave.value:10.5e} {closest_wave.unit.to_string()}' + self._dict['Spectral Axis'] = closest_wave if closest_wave.unit != u.pix: self.row2_text += f' ({int(closest_i)} pix)' + self._dict['Pixel'] = closest_i self.row3_title = 'Flux' self.row3_text = f'{closest_flux.value:10.5e} {closest_flux.unit.to_string()}' + self._dict['Flux'] = closest_flux self.icon = closest_icon