From 9be2cf4305960b9af24ae48e6b40ef09ceaf2de5 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Thu, 5 Jan 2023 12:42:20 -0500 Subject: [PATCH] add cursor and pixel information to mouseover display --- docs/specviz/displaying.rst | 4 +-- .../tests/test_gaussian_smooth.py | 31 +++++++------------ .../imviz/plugins/coords_info/coords_info.py | 3 ++ .../imviz/plugins/coords_info/coords_info.vue | 2 +- .../configs/mosviz/tests/test_data_loading.py | 8 ++--- jdaviz/configs/specviz/plugins/viewers.py | 18 +++++------ jdaviz/configs/specviz/tests/test_helper.py | 24 ++++++-------- .../configs/specviz2d/tests/test_parsers.py | 6 ++-- 8 files changed, 39 insertions(+), 57 deletions(-) diff --git a/docs/specviz/displaying.rst b/docs/specviz/displaying.rst index 08bf91879b..ff417f115e 100644 --- a/docs/specviz/displaying.rst +++ b/docs/specviz/displaying.rst @@ -47,8 +47,8 @@ Cursor Information ================== By moving your cursor along the spectrum viewer, you will be able to see information on the -index, spectral axis value, and flux value of the closest data point to the cursor -(not to be confused with the actual cursor position). +cursor position as well as the spectral axis value, pixel, and flux of the closest data point +to the cursor. This information is displayed in the top bar of the UI, on the middle-right side. Home diff --git a/jdaviz/configs/default/plugins/gaussian_smooth/tests/test_gaussian_smooth.py b/jdaviz/configs/default/plugins/gaussian_smooth/tests/test_gaussian_smooth.py index be711c342a..f5b4cd7ce7 100644 --- a/jdaviz/configs/default/plugins/gaussian_smooth/tests/test_gaussian_smooth.py +++ b/jdaviz/configs/default/plugins/gaussian_smooth/tests/test_gaussian_smooth.py @@ -69,23 +69,19 @@ def test_linking_after_spectral_smooth(cubeviz_helper, spectrum1d_cube): # to another, depending on which one is closer. spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 4.6236e-7, 'y': 60}}) - assert spec_viewer.label_mouseover.pixel == 'x=01.0' + assert spec_viewer.label_mouseover.pixel == '4.62360e-07, 6.00000e+01' assert spec_viewer.label_mouseover.world_label_prefix == 'Wave' - assert spec_viewer.label_mouseover.world_ra == '4.62360e-07' - assert spec_viewer.label_mouseover.world_dec == 'm' + assert spec_viewer.label_mouseover.world_ra == '4.62360e-07 m (1 pix)' assert spec_viewer.label_mouseover.world_label_prefix_2 == 'Flux' - assert spec_viewer.label_mouseover.world_ra_deg == '9.20000e+01' - assert spec_viewer.label_mouseover.world_dec_deg == 'Jy' + assert spec_viewer.label_mouseover.world_ra_deg == '9.20000e+01 Jy' assert spec_viewer.label_mouseover.icon == 'a' spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 4.6236e-7, 'y': 20}}) - assert spec_viewer.label_mouseover.pixel == 'x=01.0' + assert spec_viewer.label_mouseover.pixel == '4.62360e-07, 2.00000e+01' assert spec_viewer.label_mouseover.world_label_prefix == 'Wave' - assert spec_viewer.label_mouseover.world_ra == '4.62360e-07' - assert spec_viewer.label_mouseover.world_dec == 'm' + assert spec_viewer.label_mouseover.world_ra == '4.62360e-07 m (1 pix)' assert spec_viewer.label_mouseover.world_label_prefix_2 == 'Flux' - assert spec_viewer.label_mouseover.world_ra_deg == '1.47943e+01' - assert spec_viewer.label_mouseover.world_dec_deg == 'Jy' + assert spec_viewer.label_mouseover.world_ra_deg == '1.47943e+01 Jy' assert spec_viewer.label_mouseover.icon == 'b' # Check mouseover behavior when we hide everything. @@ -142,23 +138,18 @@ def test_spectrum1d_smooth(specviz_helper, spectrum1d): # to another, depending on which one is closer. spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 6400, 'y': 120}}) - assert spec_viewer.label_mouseover.pixel == 'x=02.0' + assert spec_viewer.label_mouseover.pixel == '6.40000e+03, 1.20000e+02' assert spec_viewer.label_mouseover.world_label_prefix == 'Wave' - assert spec_viewer.label_mouseover.world_ra == '6.44444e+03' - assert spec_viewer.label_mouseover.world_dec == 'Angstrom' + assert spec_viewer.label_mouseover.world_ra == '6.44444e+03 Angstrom (2 pix)' assert spec_viewer.label_mouseover.world_label_prefix_2 == 'Flux' - assert spec_viewer.label_mouseover.world_ra_deg == '1.35366e+01' - assert spec_viewer.label_mouseover.world_dec_deg == 'Jy' + assert spec_viewer.label_mouseover.world_ra_deg == '1.35366e+01 Jy' assert spec_viewer.label_mouseover.icon == 'a' spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 6400, 'y': 5}}) - assert spec_viewer.label_mouseover.pixel == 'x=02.0' assert spec_viewer.label_mouseover.world_label_prefix == 'Wave' - assert spec_viewer.label_mouseover.world_ra == '6.44444e+03' - assert spec_viewer.label_mouseover.world_dec == 'Angstrom' + assert spec_viewer.label_mouseover.world_ra == '6.44444e+03 Angstrom (2 pix)' assert spec_viewer.label_mouseover.world_label_prefix_2 == 'Flux' - assert spec_viewer.label_mouseover.world_ra_deg == '5.34688e+00' - assert spec_viewer.label_mouseover.world_dec_deg == 'Jy' + assert spec_viewer.label_mouseover.world_ra_deg == '5.34688e+00 Jy' assert spec_viewer.label_mouseover.icon == 'b' # Out-of-bounds shows nothing. diff --git a/jdaviz/configs/imviz/plugins/coords_info/coords_info.py b/jdaviz/configs/imviz/plugins/coords_info/coords_info.py index 032c0c0271..bd89473260 100644 --- a/jdaviz/configs/imviz/plugins/coords_info/coords_info.py +++ b/jdaviz/configs/imviz/plugins/coords_info/coords_info.py @@ -12,6 +12,7 @@ class CoordsInfo(TemplateMixin): template_file = __file__, "coords_info.vue" icon = Unicode("").tag(sync=True) + pixel_prefix = Unicode("Pixel").tag(sync=True) pixel = Unicode("").tag(sync=True) value = Unicode("").tag(sync=True) world_label_prefix = Unicode("\u00A0").tag(sync=True) @@ -47,6 +48,7 @@ def marks(self): return self._marks def reset_coords_display(self): + self.pixel_prefix = "Pixel" self.world_label_prefix = '\u00A0' self.world_label_prefix_2 = '\u00A0' self.world_label_icrs = '\u00A0' @@ -69,6 +71,7 @@ def set_coords(self, sky, unreliable_world=False, unreliable_pixel=False): if "nan" in (world_ra, world_dec, world_ra_deg, world_dec_deg): self.reset_coords_display() else: + self.pixel_prefix = 'Pixel' self.world_label_prefix = 'World' self.world_label_icrs = '(ICRS)' self.world_label_deg = '(deg)' diff --git a/jdaviz/configs/imviz/plugins/coords_info/coords_info.vue b/jdaviz/configs/imviz/plugins/coords_info/coords_info.vue index 40f917425c..fbdc8718ab 100644 --- a/jdaviz/configs/imviz/plugins/coords_info/coords_info.vue +++ b/jdaviz/configs/imviz/plugins/coords_info/coords_info.vue @@ -7,7 +7,7 @@ diff --git a/jdaviz/configs/mosviz/tests/test_data_loading.py b/jdaviz/configs/mosviz/tests/test_data_loading.py index 9327e0c394..f3819671fe 100644 --- a/jdaviz/configs/mosviz/tests/test_data_loading.py +++ b/jdaviz/configs/mosviz/tests/test_data_loading.py @@ -214,13 +214,11 @@ def test_load_single_image_multi_spec(mosviz_helper, mos_image, spectrum1d, mos_ assert spec2d_viewer.label_mouseover.icon == 'b' spec1d_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 7000, 'y': 170}}) - assert spec1d_viewer.label_mouseover.pixel == 'x=04.0' + assert spec1d_viewer.label_mouseover.pixel == '7.00000e+03, 1.70000e+02' assert spec1d_viewer.label_mouseover.world_label_prefix == 'Wave' - assert spec1d_viewer.label_mouseover.world_ra == '6.88889e+03' - assert spec1d_viewer.label_mouseover.world_dec == 'Angstrom' + assert spec1d_viewer.label_mouseover.world_ra == '6.88889e+03 Angstrom (4 pix)' assert spec1d_viewer.label_mouseover.world_label_prefix_2 == 'Flux' - assert spec1d_viewer.label_mouseover.world_ra_deg == '1.35436e+01' - assert spec1d_viewer.label_mouseover.world_dec_deg == 'Jy' + assert spec1d_viewer.label_mouseover.world_ra_deg == '1.35436e+01 Jy' assert spec1d_viewer.label_mouseover.icon == 'c' diff --git a/jdaviz/configs/specviz/plugins/viewers.py b/jdaviz/configs/specviz/plugins/viewers.py index fd68528f43..b317dac4d3 100644 --- a/jdaviz/configs/specviz/plugins/viewers.py +++ b/jdaviz/configs/specviz/plugins/viewers.py @@ -84,7 +84,6 @@ def on_mouse_or_key_event(self, data): closest_i = None closest_wave = None closest_flux = None - closest_maxsize = 0 closest_label = '' closest_distance = None for lyr in self.state.layers: @@ -126,7 +125,6 @@ def on_mouse_or_key_event(self, data): closest_i = cur_i closest_wave = cur_wave closest_flux = cur_flux - closest_maxsize = int(np.ceil(np.log10(sp.spectral_axis.size))) + 3 closest_label = self.jdaviz_app.state.layer_icons.get(lyr.layer.label) except Exception: # nosec # Something is loaded but not the right thing @@ -142,24 +140,24 @@ def on_mouse_or_key_event(self, data): # show the locked marker/coords only if either no tool or the default tool is active locking_active = self.toolbar.active_tool_id in self.toolbar.default_tool_priority + [None] # noqa + self.label_mouseover.pixel_prefix = 'Cursor' + self.label_mouseover.pixel = f'{x:10.5e}, {y:10.5e}' if locking_active: - fmt = 'x={:0' + str(closest_maxsize) + '.1f}' - self.label_mouseover.pixel = fmt.format(closest_i) self.label_mouseover.world_label_prefix = 'Wave' - self.label_mouseover.world_ra = f'{closest_wave.value:10.5e}' - self.label_mouseover.world_dec = closest_wave.unit.to_string() + self.label_mouseover.world_ra = f'{closest_wave.value:10.5e} {closest_wave.unit.to_string()}' # noqa + if closest_wave.unit != u.pix: + self.label_mouseover.world_ra += f' ({closest_i} pix)' + self.label_mouseover.world_dec = '' self.label_mouseover.world_label_prefix_2 = 'Flux' - self.label_mouseover.world_ra_deg = f'{closest_flux.value:10.5e}' - self.label_mouseover.world_dec_deg = closest_flux.unit.to_string() + self.label_mouseover.world_ra_deg = f'{closest_flux.value:10.5e} {closest_flux.unit.to_string()}' # noqa + self.label_mouseover.world_dec_deg = '' self.label_mouseover.icon = closest_label self.label_mouseover.value = "" # Not used self.label_mouseover.marks[self._reference_id].update_xy([closest_wave.value], [closest_flux.value]) # noqa self.label_mouseover.marks[self._reference_id].visible = True else: # show exact plot coordinates (useful for drawing spectral subsets or zoom ranges) - fmt = 'x={:+10.5e} y={:+10.5e}' self.label_mouseover.icon = "" - self.label_mouseover.pixel = fmt.format(x, y) self.label_mouseover.marks[self._reference_id].visible = False elif data['event'] == 'mouseleave' or data['event'] == 'mouseenter': diff --git a/jdaviz/configs/specviz/tests/test_helper.py b/jdaviz/configs/specviz/tests/test_helper.py index dbcd138efe..f3023e6f39 100644 --- a/jdaviz/configs/specviz/tests/test_helper.py +++ b/jdaviz/configs/specviz/tests/test_helper.py @@ -225,13 +225,11 @@ def test_get_spectral_regions_unit_conversion(specviz_helper, spectrum1d): # Also check coordinates info panel. # x=0 -> 6000 A, x=1 -> 6222.222 A spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 6100, 'y': 12.5}}) - assert spec_viewer.label_mouseover.pixel == 'x=00.0' # Actual: x=00.4 + assert spec_viewer.label_mouseover.pixel == '6.10000e+03, 1.25000e+01' assert spec_viewer.label_mouseover.world_label_prefix == 'Wave' - assert spec_viewer.label_mouseover.world_ra == '6.00000e+03' - assert spec_viewer.label_mouseover.world_dec == 'Angstrom' + assert spec_viewer.label_mouseover.world_ra == '6.00000e+03 Angstrom (0 pix)' # actual: 0.4 assert spec_viewer.label_mouseover.world_label_prefix_2 == 'Flux' - assert spec_viewer.label_mouseover.world_ra_deg == '1.24967e+01' - assert spec_viewer.label_mouseover.world_dec_deg == 'Jy' + assert spec_viewer.label_mouseover.world_ra_deg == '1.24967e+01 Jy' assert spec_viewer.label_mouseover.icon == 'a' spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': None, 'y': 12.5}}) assert spec_viewer.label_mouseover.pixel == '' @@ -266,13 +264,11 @@ def test_get_spectral_regions_unit_conversion(specviz_helper, spectrum1d): # Coordinates info panel should show new unit spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 0.61, 'y': 12.5}}) - assert spec_viewer.label_mouseover.pixel == 'x=00.0' + assert spec_viewer.label_mouseover.pixel == '6.10000e-01, 1.25000e+01' assert spec_viewer.label_mouseover.world_label_prefix == 'Wave' - assert spec_viewer.label_mouseover.world_ra == '6.00000e-01' - assert spec_viewer.label_mouseover.world_dec == 'micron' + assert spec_viewer.label_mouseover.world_ra == '6.00000e-01 micron (0 pix)' assert spec_viewer.label_mouseover.world_label_prefix_2 == 'Flux' - assert spec_viewer.label_mouseover.world_ra_deg == '1.24967e+01' - assert spec_viewer.label_mouseover.world_dec_deg == 'Jy' + assert spec_viewer.label_mouseover.world_ra_deg == '1.24967e+01 Jy' assert spec_viewer.label_mouseover.icon == 'b' spec_viewer.on_mouse_or_key_event({'event': 'mouseleave'}) assert spec_viewer.label_mouseover.pixel == '' @@ -401,11 +397,9 @@ def test_spectra_partial_overlap(specviz_helper): # Test mouseover outside of left but in range for right. # Should show right spectrum even when mouse is near left flux. spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 7022, 'y': 1000}}) - assert spec_viewer.label_mouseover.pixel == 'x=02.0' + assert spec_viewer.label_mouseover.pixel == '7.02200e+03, 1.00000e+03' assert spec_viewer.label_mouseover.world_label_prefix == 'Wave' - assert spec_viewer.label_mouseover.world_ra == '7.02222e+03' - assert spec_viewer.label_mouseover.world_dec == 'Angstrom' + assert spec_viewer.label_mouseover.world_ra == '7.02222e+03 Angstrom (2 pix)' assert spec_viewer.label_mouseover.world_label_prefix_2 == 'Flux' - assert spec_viewer.label_mouseover.world_ra_deg == '6.00000e+01' - assert spec_viewer.label_mouseover.world_dec_deg == 'nJy' + assert spec_viewer.label_mouseover.world_ra_deg == '6.00000e+01 nJy' assert spec_viewer.label_mouseover.icon == 'b' diff --git a/jdaviz/configs/specviz2d/tests/test_parsers.py b/jdaviz/configs/specviz2d/tests/test_parsers.py index 90b8fe147f..4c078b39e2 100644 --- a/jdaviz/configs/specviz2d/tests/test_parsers.py +++ b/jdaviz/configs/specviz2d/tests/test_parsers.py @@ -80,13 +80,11 @@ def test_2d_parser_no_unit(specviz2d_helper, mos_spectrum2d): viewer_1d = specviz2d_helper.app.get_viewer('spectrum-viewer') viewer_1d.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 6.5, 'y': 3}}) - assert viewer_1d.label_mouseover.pixel == 'x=006.0' + assert viewer_1d.label_mouseover.pixel == '6.50000e+00, 3.00000e+00' assert viewer_1d.label_mouseover.world_label_prefix == 'Wave' - assert viewer_1d.label_mouseover.world_ra == '6.00000e+00' - assert viewer_1d.label_mouseover.world_dec == 'pix' + assert viewer_1d.label_mouseover.world_ra == '6.00000e+00 pix' assert viewer_1d.label_mouseover.world_label_prefix_2 == 'Flux' assert viewer_1d.label_mouseover.world_ra_deg == '-3.59571e+00' - assert viewer_1d.label_mouseover.world_dec_deg == '' assert viewer_1d.label_mouseover.icon == 'b'
- Pixel {{ pixel }}   + {{ pixel_prefix }} {{ pixel }}   Value {{ value }}