Skip to content

Commit

Permalink
support for Imviz blinking, glue 'bad' masks
Browse files Browse the repository at this point in the history
  • Loading branch information
bmorris3 committed Mar 19, 2024
1 parent 488c09b commit fe40115
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
10 changes: 10 additions & 0 deletions jdaviz/configs/imviz/plugins/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 192 in jdaviz/configs/imviz/plugins/parsers.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/imviz/plugins/parsers.py#L192

Added line #L192 was not covered by tests
# 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})

Check warning on line 198 in jdaviz/configs/imviz/plugins/parsers.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/imviz/plugins/parsers.py#L195-L198

Added lines #L195 - L198 were not covered by tests
app.add_data(data, data_label, parent=parent)

# Do not link image data here. We do it at the end in Imviz.load_data()
Expand Down
18 changes: 15 additions & 3 deletions jdaviz/configs/imviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion jdaviz/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit fe40115

Please sign in to comment.