From bcea12f3865900f9ee77a2325b9ced55b532b66f Mon Sep 17 00:00:00 2001 From: "Brett M. Morris" Date: Mon, 6 May 2024 16:36:30 -0400 Subject: [PATCH] prevent composite array calls on subsets --- CHANGES.rst | 3 ++ .../plugins/data_quality/data_quality.py | 6 ++-- .../data_quality/tests/test_data_quality.py | 33 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 2d291f6c0e..f9135d649c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -127,6 +127,9 @@ Bug Fixes Cubeviz ^^^^^^^ +- Fix Data Quality plugin bug that attempted to apply array compositing logic to + spatial subsets. [#2854] + Imviz ^^^^^ diff --git a/jdaviz/configs/default/plugins/data_quality/data_quality.py b/jdaviz/configs/default/plugins/data_quality/data_quality.py index b79122c944..5e348c172e 100644 --- a/jdaviz/configs/default/plugins/data_quality/data_quality.py +++ b/jdaviz/configs/default/plugins/data_quality/data_quality.py @@ -197,8 +197,10 @@ def init_decoding(self, event={}, viewers=None): self.app._jdaviz_helper._default_uncert_viewer_reference_name ) for layer in uncert_viewer.layers: - layer.composite._allow_bad_alpha = True - layer.force_update() + # allow bad alpha for image layers, not subsets: + if not hasattr(layer, 'subset_array'): + layer.composite._allow_bad_alpha = True + layer.force_update() flag_bits = np.array([flag['flag'] for flag in self.decoded_flags]) diff --git a/jdaviz/configs/default/plugins/data_quality/tests/test_data_quality.py b/jdaviz/configs/default/plugins/data_quality/tests/test_data_quality.py index 403d6aefbc..c8f007b0e7 100644 --- a/jdaviz/configs/default/plugins/data_quality/tests/test_data_quality.py +++ b/jdaviz/configs/default/plugins/data_quality/tests/test_data_quality.py @@ -5,6 +5,7 @@ import numpy as np from astroquery.mast import Observations from stdatamodels.jwst.datamodels.dqflags import pixel as pixel_jwst +from glue.core.subset import RectangularROI from jdaviz.configs.imviz.plugins.parsers import HAS_ROMAN_DATAMODELS from jdaviz.configs.default.plugins.data_quality.dq_utils import ( @@ -212,3 +213,35 @@ def test_data_quality_plugin_hst_acs(imviz_helper, tmp_path): flag_map_selected[0]['description'] == 'Reed-Solomon decoding error; e.g. data lost during compression.' ) + + +@pytest.mark.remote_data +def test_cubeviz_layer_visibility_bug(cubeviz_helper, tmp_path): + # regression test for bug: + uri = "mast:JWST/product/jw02732-o004_t004_miri_ch1-shortmediumlong_s3d.fits" + download_path = str(tmp_path / Path(uri).name) + Observations.download_file(uri, local_path=download_path) + + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + cubeviz_helper.load_data(download_path) + + # create a moment map: + mm = cubeviz_helper.plugins['Moment Maps'] + mm.n_moment = 1 + mm.reference_wavelength = 6 + mm._obj.add_to_viewer_selected = 'uncert-viewer' + mm.calculate_moment() + + # add the moment map to the flux viewer + dc = cubeviz_helper.app.data_collection + viewer = cubeviz_helper.app.get_viewer('flux-viewer') + viewer.add_data(dc[-1]) + + # create a spatial subset in the flux-viewer + roi = RectangularROI(22, 27, 22, 30) + viewer.apply_roi(roi) + + # toggle layer visibility, this used to trigger an AttributeError: + cubeviz_helper.app.set_data_visibility('flux-viewer', dc[-1].label) + cubeviz_helper.app.set_data_visibility('flux-viewer', dc[0].label)