From 28118cf33bb3408dd22003aa5bebf6e97bcdfdd5 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Mon, 27 Nov 2023 14:32:40 -0500 Subject: [PATCH] update internal calls to default_viewer * to use public API where possible, and otherwise go through ._obj --- .../cubeviz/plugins/tests/test_export_plots.py | 2 +- jdaviz/configs/cubeviz/plugins/tests/test_regions.py | 2 +- jdaviz/configs/imviz/tests/test_footprints.py | 2 ++ jdaviz/configs/imviz/tests/test_linking.py | 12 ++++++------ jdaviz/configs/imviz/tests/test_regions.py | 8 ++++---- jdaviz/configs/imviz/tests/test_simple_aper_phot.py | 2 +- jdaviz/configs/imviz/tests/test_tools.py | 8 ++++---- jdaviz/configs/imviz/tests/utils.py | 8 ++++---- jdaviz/core/helpers.py | 8 ++++---- jdaviz/tests/test_app.py | 2 +- jdaviz/tests/test_subsets.py | 2 +- notebooks/concepts/imviz_color_display.ipynb | 2 +- notebooks/concepts/imviz_dithered_gwcs.ipynb | 2 +- 13 files changed, 31 insertions(+), 29 deletions(-) diff --git a/jdaviz/configs/cubeviz/plugins/tests/test_export_plots.py b/jdaviz/configs/cubeviz/plugins/tests/test_export_plots.py index 377a628d87..2c4d3ebf28 100644 --- a/jdaviz/configs/cubeviz/plugins/tests/test_export_plots.py +++ b/jdaviz/configs/cubeviz/plugins/tests/test_export_plots.py @@ -48,7 +48,7 @@ def test_export_movie_not_cubeviz(imviz_helper): @pytest.mark.skipif(not HAS_OPENCV, reason="opencv-python is not installed") def test_export_movie_cubeviz_exceptions(cubeviz_helper, spectrum1d_cube): cubeviz_helper.load_data(spectrum1d_cube, data_label="test") - cubeviz_helper.default_viewer.shape = (100, 100) + cubeviz_helper.default_viewer._obj.shape = (100, 100) cubeviz_helper.app.get_viewer("uncert-viewer").shape = (100, 100) plugin = cubeviz_helper.plugins["Export Plot"] assert plugin._obj.movie_msg == "" diff --git a/jdaviz/configs/cubeviz/plugins/tests/test_regions.py b/jdaviz/configs/cubeviz/plugins/tests/test_regions.py index c1a862eee4..dbb5364e47 100644 --- a/jdaviz/configs/cubeviz/plugins/tests/test_regions.py +++ b/jdaviz/configs/cubeviz/plugins/tests/test_regions.py @@ -18,7 +18,7 @@ class TestLoadRegions(BaseRegionHandler): def setup_class(self, cubeviz_helper, image_cube_hdu_obj_microns): cubeviz_helper.load_data(image_cube_hdu_obj_microns, data_label='has_microns') self.cubeviz = cubeviz_helper - self.viewer = cubeviz_helper.default_viewer # This is used in BaseRegionHandler + self.viewer = cubeviz_helper.default_viewer._obj # This is used in BaseRegionHandler self.spectrum_viewer = cubeviz_helper.app.get_viewer( cubeviz_helper._default_spectrum_viewer_reference_name ) diff --git a/jdaviz/configs/imviz/tests/test_footprints.py b/jdaviz/configs/imviz/tests/test_footprints.py index b480bd9303..c9ef88051d 100644 --- a/jdaviz/configs/imviz/tests/test_footprints.py +++ b/jdaviz/configs/imviz/tests/test_footprints.py @@ -12,6 +12,8 @@ def _get_markers_from_viewer(viewer): + if hasattr(viewer, '_obj'): + viewer = viewer._obj return [m for m in viewer.figure.marks if isinstance(m, FootprintOverlay)] diff --git a/jdaviz/configs/imviz/tests/test_linking.py b/jdaviz/configs/imviz/tests/test_linking.py index 94dd8b6ee9..8e8bd11e1a 100644 --- a/jdaviz/configs/imviz/tests/test_linking.py +++ b/jdaviz/configs/imviz/tests/test_linking.py @@ -24,10 +24,10 @@ def test_pixel_linking(self): @property def default_viewer_limits(self): - return (self.imviz.default_viewer.state.x_min, - self.imviz.default_viewer.state.x_max, - self.imviz.default_viewer.state.y_min, - self.imviz.default_viewer.state.y_max) + return (self.imviz.default_viewer._obj.state.x_min, + self.imviz.default_viewer._obj.state.x_max, + self.imviz.default_viewer._obj.state.y_min, + self.imviz.default_viewer._obj.state.y_max) class TestLink_WCS_NoWCS(BaseImviz_WCS_NoWCS, BaseLinkHandler): @@ -104,7 +104,7 @@ def test_wcslink_affine_with_extras(self): # linking should not change axes limits, but should when resetting assert_allclose(self.default_viewer_limits, orig_pixel_limits) - self.imviz.default_viewer.state.reset_limits() + self.imviz.default_viewer.reset_limits() assert_allclose(self.default_viewer_limits, (-1.5, 9.5, -1, 10)) # Customize display on second image (last loaded). @@ -370,4 +370,4 @@ def test_imviz_no_data(imviz_helper): assert len(links) == 0 with pytest.raises(ValueError, match='No reference data for link look-up'): - imviz_helper.default_viewer.get_link_type('foo') + imviz_helper.default_viewer._obj.get_link_type('foo') diff --git a/jdaviz/configs/imviz/tests/test_regions.py b/jdaviz/configs/imviz/tests/test_regions.py index bd5603e04d..83fbadceb8 100644 --- a/jdaviz/configs/imviz/tests/test_regions.py +++ b/jdaviz/configs/imviz/tests/test_regions.py @@ -188,7 +188,7 @@ def test_ds9_load_all(self, imviz_helper): with pytest.raises(ValueError, match="Cannot load regions without data"): imviz_helper.load_data(self.region_file) - self.viewer = imviz_helper.default_viewer + self.viewer = imviz_helper.default_viewer._obj imviz_helper.load_data(self.arr, data_label='my_image') bad_regions = imviz_helper.load_regions_from_file(self.region_file, return_bad_regions=True) assert len(bad_regions) == 1 @@ -202,7 +202,7 @@ def test_ds9_load_all(self, imviz_helper): self.verify_region_loaded('MaskedSubset 1', count=1) def test_ds9_load_two_good(self, imviz_helper): - self.viewer = imviz_helper.default_viewer + self.viewer = imviz_helper.default_viewer._obj imviz_helper.load_data(self.arr, data_label='my_image') bad_regions = imviz_helper.load_regions_from_file( self.region_file, max_num_regions=2, return_bad_regions=True) @@ -212,7 +212,7 @@ def test_ds9_load_two_good(self, imviz_helper): self.verify_region_loaded('MaskedSubset 1', count=0) def test_ds9_load_one_bad(self, imviz_helper): - self.viewer = imviz_helper.default_viewer + self.viewer = imviz_helper.default_viewer._obj imviz_helper.load_data(self.arr, data_label='my_image') bad_regions = imviz_helper.load_regions(self.raw_regions[6], return_bad_regions=True) assert len(bad_regions) == 1 @@ -220,7 +220,7 @@ def test_ds9_load_one_bad(self, imviz_helper): self.verify_region_loaded('MaskedSubset 1', count=0) def test_ds9_load_one_good_one_bad(self, imviz_helper): - self.viewer = imviz_helper.default_viewer + self.viewer = imviz_helper.default_viewer._obj imviz_helper.load_data(self.arr, data_label='my_image') bad_regions = imviz_helper.load_regions( [self.raw_regions[3], self.raw_regions[6]], return_bad_regions=True) diff --git a/jdaviz/configs/imviz/tests/test_simple_aper_phot.py b/jdaviz/configs/imviz/tests/test_simple_aper_phot.py index c029ad19cf..3e1bc29772 100644 --- a/jdaviz/configs/imviz/tests/test_simple_aper_phot.py +++ b/jdaviz/configs/imviz/tests/test_simple_aper_phot.py @@ -280,7 +280,7 @@ def setup_class(self, imviz_helper): imviz_helper.load_regions(regions) self.imviz = imviz_helper - self.viewer = imviz_helper.default_viewer + self.viewer = imviz_helper.default_viewer._obj self.phot_plugin = imviz_helper.plugins["Aperture Photometry"]._obj @pytest.mark.parametrize(('data_label', 'local_bkg'), [ diff --git a/jdaviz/configs/imviz/tests/test_tools.py b/jdaviz/configs/imviz/tests/test_tools.py index a96150013a..8a4b97d5bd 100644 --- a/jdaviz/configs/imviz/tests/test_tools.py +++ b/jdaviz/configs/imviz/tests/test_tools.py @@ -7,7 +7,7 @@ class TestPanZoomTools(BaseImviz_WCS_WCS): def test_panzoom_tools(self): - v = self.imviz.default_viewer + v = self.imviz.default_viewer._obj v2 = self.imviz.create_image_viewer() self.imviz.app.add_data_to_viewer('imviz-1', 'has_wcs_1[SCI,1]') @@ -70,7 +70,7 @@ class TestSinglePixelRegion(BaseImviz_WCS_WCS): def test_singlepixelregion(self): self.imviz.link_data(link_type='wcs') - t = self.imviz.default_viewer.toolbar.tools['jdaviz:singlepixelregion'] + t = self.imviz.default_viewer._obj.toolbar.tools['jdaviz:singlepixelregion'] t.activate() # Create a region while viewing reference data. @@ -103,7 +103,7 @@ def test_singlepixelregion(self): def test_blink(imviz_helper): - viewer = imviz_helper.default_viewer + viewer = imviz_helper.default_viewer._obj for i in range(3): imviz_helper.load_data(np.zeros((2, 2)) + i, data_label=f'image_{i}') @@ -142,7 +142,7 @@ def test_compass_open_while_load(imviz_helper): def test_tool_visibility(imviz_helper): imviz_helper.load_data(np.ones((2, 2))) - tb = imviz_helper.default_viewer.toolbar + tb = imviz_helper.default_viewer._obj.toolbar assert not tb.tools_data['jdaviz:boxzoommatch']['visible'] diff --git a/jdaviz/configs/imviz/tests/utils.py b/jdaviz/configs/imviz/tests/utils.py index 8ff48d90e4..7988a8d88e 100644 --- a/jdaviz/configs/imviz/tests/utils.py +++ b/jdaviz/configs/imviz/tests/utils.py @@ -41,7 +41,7 @@ def setup_class(self, imviz_helper): self.wcs = WCS(hdu.header) self.imviz = imviz_helper - self.viewer = imviz_helper.default_viewer + self.viewer = imviz_helper.default_viewer._obj # Since we are not really displaying, need this to test zoom. self.viewer.shape = (100, 100) @@ -88,7 +88,7 @@ def setup_class(self, imviz_helper): self.wcs_1 = WCS(hdu1.header) self.wcs_2 = WCS(hdu2.header) self.imviz = imviz_helper - self.viewer = imviz_helper.default_viewer + self.viewer = imviz_helper.default_viewer._obj # Since we are not really displaying, need this to test zoom. self.viewer.shape = (100, 100) @@ -146,7 +146,7 @@ def setup_class(self, imviz_helper): self.wcs_1 = w_fits self.wcs_2 = w_gwcs self.imviz = imviz_helper - self.viewer = imviz_helper.default_viewer + self.viewer = imviz_helper.default_viewer._obj # Since we are not really displaying, need this to test zoom. self.viewer.shape = (100, 100) @@ -196,7 +196,7 @@ def setup_class(self, imviz_helper): self.wcs_1 = w_gwcs_1 self.wcs_2 = w_gwcs_2 self.imviz = imviz_helper - self.viewer = imviz_helper.default_viewer + self.viewer = imviz_helper.default_viewer._obj # Since we are not really displaying, need this to test zoom. self.viewer.shape = (100, 100) diff --git a/jdaviz/core/helpers.py b/jdaviz/core/helpers.py index 30bfd4ce91..d3b2dddd13 100644 --- a/jdaviz/core/helpers.py +++ b/jdaviz/core/helpers.py @@ -742,7 +742,7 @@ def load_regions(self, regions, max_num_regions=None, refdata_label=None, # Subset is global but reference data is viewer-dependent. if refdata_label is None: - data = self.default_viewer.state.reference_data + data = self.default_viewer._obj.state.reference_data else: data = self.app.data_collection[refdata_label] @@ -776,7 +776,7 @@ def load_regions(self, regions, max_num_regions=None, refdata_label=None, # TODO: Do we want user to specify viewer? Does it matter? self.app.session.edit_subset_mode._mode = NewMode - self.default_viewer.apply_roi(state) + self.default_viewer._obj.apply_roi(state) self.app.session.edit_subset_mode.edit_subset = None # No overwrite next iteration # noqa # Last resort: Masked Subset that is static (if data is not a cube) @@ -855,7 +855,7 @@ def get_interactive_regions(self): failed_regs = set() # Subset is global, so we just use default viewer. - for lyr in self.default_viewer.layers: + for lyr in self.default_viewer._obj.layers: if (not hasattr(lyr, 'layer') or not isinstance(lyr.layer, Subset) or lyr.layer.ndim not in (2, 3)): continue @@ -889,7 +889,7 @@ def _apply_interactive_region(self, toolname, from_pix, to_pix): This is for internal testing only. """ self.app.session.edit_subset_mode._mode = NewMode - tool = self.default_viewer.toolbar.tools[toolname] + tool = self.default_viewer._obj.toolbar.tools[toolname] tool.activate() tool.interact.brushing = True tool.interact.selected = [from_pix, to_pix] diff --git a/jdaviz/tests/test_app.py b/jdaviz/tests/test_app.py index 89d9413eca..3b0166f032 100644 --- a/jdaviz/tests/test_app.py +++ b/jdaviz/tests/test_app.py @@ -6,7 +6,7 @@ # This applies to all viz but testing with Imviz should be enough. def test_viewer_calling_app(imviz_helper): - viewer = imviz_helper.default_viewer + viewer = imviz_helper.default_viewer._obj assert viewer.session.jdaviz_app is imviz_helper.app diff --git a/jdaviz/tests/test_subsets.py b/jdaviz/tests/test_subsets.py index d43ed794b8..c2244ff31c 100644 --- a/jdaviz/tests/test_subsets.py +++ b/jdaviz/tests/test_subsets.py @@ -489,7 +489,7 @@ def test_composite_region_with_imviz(imviz_helper, image_2d_wcs): arr = np.ones((10, 10)) data_label = 'image-data' - viewer = imviz_helper.default_viewer + viewer = imviz_helper.default_viewer._obj imviz_helper.load_data(arr, data_label=data_label, show_in_viewer=True) viewer.apply_roi(CircularROI(xc=5, yc=5, radius=2)) reg = imviz_helper.app.get_subsets("Subset 1") diff --git a/notebooks/concepts/imviz_color_display.ipynb b/notebooks/concepts/imviz_color_display.ipynb index 6072f3b052..fd82b3cb1c 100644 --- a/notebooks/concepts/imviz_color_display.ipynb +++ b/notebooks/concepts/imviz_color_display.ipynb @@ -92,7 +92,7 @@ "imviz.load_data(im_g, data_label='Green')\n", "imviz.load_data(im_b, data_label='Blue')\n", "\n", - "viewer = imviz.default_viewer\n", + "viewer = imviz.default_viewer._obj\n", "\n", "imviz.show()" ] diff --git a/notebooks/concepts/imviz_dithered_gwcs.ipynb b/notebooks/concepts/imviz_dithered_gwcs.ipynb index a058215f82..7e716ef3bf 100644 --- a/notebooks/concepts/imviz_dithered_gwcs.ipynb +++ b/notebooks/concepts/imviz_dithered_gwcs.ipynb @@ -124,7 +124,7 @@ "outputs": [], "source": [ "# Home button\n", - "imviz.default_viewer.state.reset_limits()" + "imviz.default_viewer.reset_limits()" ] }, {