Skip to content

Commit

Permalink
Backport PR #2624: helper.viewers dict to better generalize reference…
Browse files Browse the repository at this point in the history
… vs id (#2633)

Co-authored-by: Kyle Conroy <[email protected]>
  • Loading branch information
meeseeksmachine and kecnry authored Dec 21, 2023
1 parent 8d25306 commit e8c211f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Imviz
- Stretch histogram now represents mixed state for any of the inputs (when multiple viewers are
selected) with an overlay appropriately. [#2606]

- Fixes viewer keys in ``viz.viewers`` for additionally created viewers. [#2624]

Mosviz
^^^^^^

Expand Down
7 changes: 7 additions & 0 deletions jdaviz/configs/default/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ def reference_id(self):
def reference(self):
return self.jdaviz_app._viewer_item_by_id(self.reference_id).get('reference')

@property
def _ref_or_id(self):
reference = self.reference
if reference is not None:
return reference
return self.reference_id

def set_plot_axes(self):
# individual viewers can override to set custom axes labels/ticks/styling
return
4 changes: 2 additions & 2 deletions jdaviz/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def viewers(self):
viewers : dict
dict of viewer objects
"""
return {getattr(viewer, 'reference', k): viewer.user_api
for k, viewer in self.app._viewer_store.items()}
return {viewer._ref_or_id: viewer.user_api
for viewer in self.app._viewer_store.values()}

@property
def fitted_models(self):
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/core/user_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ def __init__(self, viewer, expose=[], readonly=[]):
super().__init__(viewer, expose, readonly)

def __repr__(self):
return f'<{self._obj.reference} API>'
return f'<{self._obj._ref_or_id} API>'
7 changes: 7 additions & 0 deletions jdaviz/tests/test_user_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ def test_imviz_zoom_level(self):
assert v._obj.state.x_min == 1.5
assert v._obj.state.x_max == 6.5

def test_imviz_viewers(self):
self.imviz.create_image_viewer()
self.imviz.create_image_viewer()

# regression test for https://github.com/spacetelescope/jdaviz/pull/2624
assert len(self.imviz.viewers) == 3


def test_specviz_zoom_level(specviz_helper):
v = specviz_helper.viewers['spectrum-viewer']
Expand Down

0 comments on commit e8c211f

Please sign in to comment.