Skip to content

Commit

Permalink
update internal calls to default_viewer
Browse files Browse the repository at this point in the history
* to use public API where possible, and otherwise go through ._obj
  • Loading branch information
kecnry committed Nov 27, 2023
1 parent b20f73a commit 28118cf
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 29 deletions.
2 changes: 1 addition & 1 deletion jdaviz/configs/cubeviz/plugins/tests/test_export_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == ""
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/configs/cubeviz/plugins/tests/test_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 2 additions & 0 deletions jdaviz/configs/imviz/tests/test_footprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]


Expand Down
12 changes: 6 additions & 6 deletions jdaviz/configs/imviz/tests/test_linking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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')
8 changes: 4 additions & 4 deletions jdaviz/configs/imviz/tests/test_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -212,15 +212,15 @@ 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
assert imviz_helper.get_interactive_regions() == {}
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)
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/configs/imviz/tests/test_simple_aper_phot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'), [
Expand Down
8 changes: 4 additions & 4 deletions jdaviz/configs/imviz/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]')

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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}')
Expand Down Expand Up @@ -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']

Expand Down
8 changes: 4 additions & 4 deletions jdaviz/configs/imviz/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions jdaviz/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion jdaviz/tests/test_subsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion notebooks/concepts/imviz_color_display.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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()"
]
Expand Down
2 changes: 1 addition & 1 deletion notebooks/concepts/imviz_dithered_gwcs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"outputs": [],
"source": [
"# Home button\n",
"imviz.default_viewer.state.reset_limits()"
"imviz.default_viewer.reset_limits()"
]
},
{
Expand Down

0 comments on commit 28118cf

Please sign in to comment.