Skip to content

Commit

Permalink
data-menu: handle associated data layer logic (#3370)
Browse files Browse the repository at this point in the history
* logic to connect visibilities of child/parent layers from data-menu
* test coverage
  • Loading branch information
kecnry authored Dec 20, 2024
1 parent 57848c2 commit 5cd23a8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
9 changes: 9 additions & 0 deletions jdaviz/configs/default/plugins/data_menu/data_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
28 changes: 28 additions & 0 deletions jdaviz/configs/default/tests/test_data_menu.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from astropy.io import fits
import pytest
import numpy as np
from specutils import SpectralRegion
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5cd23a8

Please sign in to comment.