diff --git a/CHANGES.rst b/CHANGES.rst index b459a63079..ecfddfa97d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -83,6 +83,9 @@ Cubeviz - Fixed linking of plugin data to the reference data that was used to create it [#1412] +- Fixed coordinates display not showing the top layer information when multiple + layers are loaded into the image viewer. [#1445] + Imviz ^^^^^ diff --git a/jdaviz/configs/cubeviz/plugins/moment_maps/tests/test_moment_maps.py b/jdaviz/configs/cubeviz/plugins/moment_maps/tests/test_moment_maps.py index c501e6ce76..1344882bdf 100644 --- a/jdaviz/configs/cubeviz/plugins/moment_maps/tests/test_moment_maps.py +++ b/jdaviz/configs/cubeviz/plugins/moment_maps/tests/test_moment_maps.py @@ -10,6 +10,11 @@ def test_moment_calculation(cubeviz_helper, spectrum1d_cube, tmpdir): dc = cubeviz_helper.app.data_collection cubeviz_helper.load_data(spectrum1d_cube, data_label='test') + flux_viewer = cubeviz_helper.app.get_viewer('flux-viewer') + + # Since we are not really displaying, need this to trigger GUI stuff. + flux_viewer.shape = (100, 100) + flux_viewer.state._set_axes_aspect_ratio(1) mm = MomentMap(app=cubeviz_helper.app) mm.dataset_selected = 'test[FLUX]' @@ -33,20 +38,29 @@ def test_moment_calculation(cubeviz_helper, spectrum1d_cube, tmpdir): assert mm.results_label == 'moment 0' assert mm.results_label_overwrite is True + # Make sure coordinate display works + flux_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 0, 'y': 0}}) + assert flux_viewer.state.slices == (0, 0, 1) + assert flux_viewer.label_mouseover.pixel == 'x=00.0 y=00.0' + assert flux_viewer.label_mouseover.value == '+8.00000e+00 Jy' # Slice 0 has 8 pixels, this is Slice 1 # noqa + assert flux_viewer.label_mouseover.world_ra_deg == '204.9997755346' + assert flux_viewer.label_mouseover.world_dec_deg == '27.0000999998' + + # Make sure adding it to viewer does not crash. + cubeviz_helper.app.add_data_to_viewer('flux-viewer', 'moment 0') + result = dc[1].get_object(cls=CCDData) assert result.shape == (4, 2) # Cube shape is (2, 2, 4) # FIXME: Need spatial WCS, see https://github.com/spacetelescope/jdaviz/issues/1025 assert dc[1].coords is None - # Make sure coordinate display still works - flux_viewer = cubeviz_helper.app.get_viewer('flux-viewer') + # Make sure coordinate display now show moment map info (no WCS) flux_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 0, 'y': 0}}) - assert flux_viewer.state.slices == (0, 0, 1) assert flux_viewer.label_mouseover.pixel == 'x=00.0 y=00.0' assert flux_viewer.label_mouseover.value == '+8.00000e+00 Jy' # Slice 0 has 8 pixels, this is Slice 1 # noqa - assert flux_viewer.label_mouseover.world_ra_deg == '204.9997755346' - assert flux_viewer.label_mouseover.world_dec_deg == '27.0000999998' + assert flux_viewer.label_mouseover.world_ra_deg == '' + assert flux_viewer.label_mouseover.world_dec_deg == '' assert mm.filename == 'moment0_test_FLUX.fits' # Auto-populated on calculate. mm.filename = str(tmpdir.join(mm.filename)) # But we want it in tmpdir for testing. @@ -82,5 +96,5 @@ def test_moment_calculation(cubeviz_helper, spectrum1d_cube, tmpdir): # Coordinate display should be unaffected. assert flux_viewer.label_mouseover.pixel == 'x=00.0 y=00.0' assert flux_viewer.label_mouseover.value == '+8.00000e+00 Jy' # Slice 0 has 8 pixels, this is Slice 1 # noqa - assert flux_viewer.label_mouseover.world_ra_deg == '204.9997755346' - assert flux_viewer.label_mouseover.world_dec_deg == '27.0000999998' + assert flux_viewer.label_mouseover.world_ra_deg == '' + assert flux_viewer.label_mouseover.world_dec_deg == '' diff --git a/jdaviz/configs/cubeviz/plugins/viewers.py b/jdaviz/configs/cubeviz/plugins/viewers.py index 665fc37a36..4b1f9b1e84 100644 --- a/jdaviz/configs/cubeviz/plugins/viewers.py +++ b/jdaviz/configs/cubeviz/plugins/viewers.py @@ -65,7 +65,8 @@ def on_mouse_or_key_event(self, data): # Extract first dataset from visible layers and use this for coordinates - the choice # of dataset shouldn't matter if the datasets are linked correctly - image = visible_layers[0].layer + active_layer = visible_layers[-1] + image = active_layer.layer # Extract data coordinates - these are pixels in the reference image x = data['domain']['x'] @@ -94,8 +95,8 @@ def on_mouse_or_key_event(self, data): # Extract data values at this position. # Check if shape is [x, y, z] or [x, y] and show value accordingly. if (-0.5 < x < image.shape[0] - 0.5 and -0.5 < y < image.shape[1] - 0.5 - and hasattr(visible_layers[0], 'attribute')): - attribute = visible_layers[0].attribute + and hasattr(active_layer, 'attribute')): + attribute = active_layer.attribute if len(image.shape) == 3: value = image.get_data(attribute)[int(round(x)), int(round(y)), self.state.slices[-1]]