Skip to content

Commit

Permalink
log info from coords_info mouseover display
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Feb 11, 2023
1 parent 00c8333 commit 2e61553
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
41 changes: 15 additions & 26 deletions jdaviz/configs/default/plugins/markers/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
21 changes: 21 additions & 0 deletions jdaviz/configs/imviz/plugins/coords_info/coords_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = ""
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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 = ''
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 2e61553

Please sign in to comment.