diff --git a/CHANGES.rst b/CHANGES.rst index cf2c16493d..16eeebab34 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,7 @@ New Features ------------ -- New design for viewer legend and data-menu. [#3220, #3254, #3263, #3264, #3271, #3272, #3274, #3289, #3310] +- New design for viewer legend and future data-menu. [#3220, #3254, #3263, #3264, #3271, #3272, #3274, #3289, #3310, #3370] - Improve performance while importing multiple regions. [#3321] diff --git a/jdaviz/configs/default/plugins/data_menu/data_menu.py b/jdaviz/configs/default/plugins/data_menu/data_menu.py index d1a2abcb5f..d7cab1f748 100644 --- a/jdaviz/configs/default/plugins/data_menu/data_menu.py +++ b/jdaviz/configs/default/plugins/data_menu/data_menu.py @@ -358,6 +358,15 @@ def set_layer_visibility(self, layer_label, visible=True): layer.visible = visible elif hasattr(layer.layer, 'data') and layer.layer.data.label == layer_label: layer.visible = layer.layer.label in self.visible_layers + if not visible and self.app._get_assoc_data_parent(layer.layer.label) == layer_label: + # then this is a child-layer of a parent-layer that is being hidden + # so also hide the child-layer + layer.visible = False + + if visible and (parent_label := self.app._get_assoc_data_parent(layer_label)): + # ensure the parent layer is also visible + self.set_layer_visibility(parent_label, visible=True) + return self.visible_layers def toggle_layer_visibility(self, layer_label): diff --git a/jdaviz/configs/default/tests/test_data_menu.py b/jdaviz/configs/default/tests/test_data_menu.py index 8d83ff4427..ad952aed70 100644 --- a/jdaviz/configs/default/tests/test_data_menu.py +++ b/jdaviz/configs/default/tests/test_data_menu.py @@ -1,3 +1,4 @@ +from astropy.io import fits import pytest import numpy as np from specutils import SpectralRegion @@ -146,6 +147,33 @@ def test_data_menu_remove_subset(specviz_helper, spectrum1d): # assert dm.layer.choices == ['test', 'test2', 'Subset 2'] +def test_data_menu_dq_layers(imviz_helper): + hdu_data = fits.ImageHDU(np.zeros(shape=(2, 2))) + hdu_data.name = 'SCI' + hdu_dq = fits.ImageHDU(np.zeros(shape=(2, 2), dtype=np.int32)) + hdu_dq.name = 'DQ' + data = fits.HDUList([fits.PrimaryHDU(), hdu_data, hdu_dq]) + + imviz_helper.load_data(data, data_label="image", ext=('SCI', 'DQ'), show_in_viewer=True) + + dm = imviz_helper.viewers['imviz-0']._obj.data_menu + assert dm.layer.choices == ['image[DQ,1]', 'image[SCI,1]'] + assert len(dm._obj.visible_layers) == 2 + + # turning off image (parent) data-layer should also turn off DQ + dm.set_layer_visibility('image[SCI,1]', False) + assert len(dm._obj.visible_layers) == 0 + + # turning on image (parent) should leave DQ off + dm.set_layer_visibility('image[SCI,1]', True) + assert len(dm._obj.visible_layers) == 1 + + # turning on DQ (child, when parent off) should show parent + dm.set_layer_visibility('image[SCI,1]', False) + dm.set_layer_visibility('image[DQ,1]', True) + assert len(dm._obj.visible_layers) == 2 + + @pytest.mark.skip(reason="known issue") def test_data_menu_subset_appearance(specviz_helper, spectrum1d): # NOTE: this test is similar to above - the subset is appearing in time IF there