From fe40115396c23658a8a931cf3d484eeed1c60674 Mon Sep 17 00:00:00 2001 From: "Brett M. Morris" Date: Tue, 19 Mar 2024 15:10:15 -0400 Subject: [PATCH] support for Imviz blinking, glue 'bad' masks --- jdaviz/configs/imviz/plugins/parsers.py | 10 ++++++++++ jdaviz/configs/imviz/plugins/viewers.py | 18 +++++++++++++++--- jdaviz/tests/test_app.py | 1 - 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/jdaviz/configs/imviz/plugins/parsers.py b/jdaviz/configs/imviz/plugins/parsers.py index 97558ed568..06cbb44263 100644 --- a/jdaviz/configs/imviz/plugins/parsers.py +++ b/jdaviz/configs/imviz/plugins/parsers.py @@ -186,6 +186,16 @@ def _parse_image(app, file_obj, data_label, ext=None, parent=None): data.coords.bounding_box = None if not data.meta.get(_wcs_only_label, False): data_label = app.return_data_label(data_label, alt_name="image_data") + + # TODO: generalize/centralize this for use in other configs too + if parent is not None and ext == 'DQ': + print('data', data.main_components) + # nans are used to mark "good" flags in the DQ colormap, so + # convert DQ array to float to support nans: + cid = data.get_component("DQ") + data_arr = np.float32(cid.data) + data_arr[data_arr == 0] = np.nan + data.update_components({cid: data_arr}) app.add_data(data, data_label, parent=parent) # Do not link image data here. We do it at the end in Imviz.load_data() diff --git a/jdaviz/configs/imviz/plugins/viewers.py b/jdaviz/configs/imviz/plugins/viewers.py index 285d801b77..788ae57fef 100644 --- a/jdaviz/configs/imviz/plugins/viewers.py +++ b/jdaviz/configs/imviz/plugins/viewers.py @@ -86,9 +86,16 @@ def blink_once(self, reversed=False): # Simple blinking of images - this will make it so that only one # layer is visible at a time and cycles through the layers. - # Exclude Subsets: They are global + # Exclude Subsets (they are global) and children via associated data + + def is_parent(data): + return self.session.jdaviz_app._get_assoc_data_parent(data.label) is None + valid = [ilayer for ilayer, layer in enumerate(self.state.layers) - if layer_is_image_data(layer.layer)] + if layer_is_image_data(layer.layer) and is_parent(layer.layer)] + children = [ilayer for ilayer, layer in enumerate(self.state.layers) + if layer_is_image_data(layer.layer) and not is_parent(layer.layer)] + n_layers = len(valid) if n_layers == 1: @@ -116,7 +123,12 @@ def blink_once(self, reversed=False): next_layer = valid[(valid.index(visible[-1]) + delta) % n_layers] self.state.layers[next_layer].visible = True - for ilayer in (set(valid) - set([next_layer])): + # make invisible all parent layers other than the next layer: + layers_to_set_not_visible = set(valid) - set([next_layer]) + # no child layers are visible by default: + layers_to_set_not_visible.update(set(children)) + + for ilayer in layers_to_set_not_visible: self.state.layers[ilayer].visible = False # We can display the active data label in Compass plugin. diff --git a/jdaviz/tests/test_app.py b/jdaviz/tests/test_app.py index 2658568d35..9179af4350 100644 --- a/jdaviz/tests/test_app.py +++ b/jdaviz/tests/test_app.py @@ -184,4 +184,3 @@ def test_data_associations(imviz_helper): assert imviz_helper.app._get_assoc_data_children('parent_data') == ['child_data'] assert imviz_helper.app._get_assoc_data_parent('child_data') == 'parent_data' -