Skip to content

Commit

Permalink
Improve performance of orientation rerendering (#3452)
Browse files Browse the repository at this point in the history
* delay_callback on viewer limits change when changing orientation
* simplify logic when changing link_type to avoid iterating through internal viewer
  • Loading branch information
kecnry authored Feb 19, 2025
1 parent 881ff2b commit e6548c4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ Cubeviz
Imviz
^^^^^

- Improve performance of re-rendering during orientation change. [#3452]

Mosviz
^^^^^^

Expand Down
38 changes: 21 additions & 17 deletions jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from astropy.nddata import NDData, NDDataArray
from astropy.io import fits
from astropy.time import Time
from echo import CallbackProperty, DictCallbackProperty, ListCallbackProperty
from echo import (CallbackProperty, DictCallbackProperty,
ListCallbackProperty, delay_callback)
from ipygoldenlayout import GoldenLayout
from ipysplitpanes import SplitPanes
import numpy as np
Expand Down Expand Up @@ -695,23 +696,26 @@ def _change_reference_data(self, new_refdata_label, viewer_id=None):
old=old_refdata,
sender=self))

if (
all('_WCS_ONLY' in refdata.meta for refdata in [old_refdata, new_refdata]) and
viewer.shape is not None
):
# adjust zoom to account for new refdata if both the
# old and new refdata are WCS-only layers
# (which also ensures zoom_level is already determined):
fov_sky_final = viewer._get_fov()
viewer.zoom(
float(fov_sky_final / fov_sky_init)
)
with delay_callback(viewer.state, 'x_min', 'x_max',
'y_min', 'y_max',
'zoom_center_x', 'zoom_center_y', 'zoom_radius'):
if (
all('_WCS_ONLY' in refdata.meta for refdata in [old_refdata, new_refdata]) and
viewer.shape is not None
):
# adjust zoom to account for new refdata if both the
# old and new refdata are WCS-only layers
# (which also ensures zoom_level is already determined):
fov_sky_final = viewer._get_fov()
viewer.zoom(
float(fov_sky_final / fov_sky_init)
)

# only re-center the viewer if all data layers have WCS:
has_wcs_per_data = [data_has_valid_wcs(d) for d in viewer.data()]
if all(has_wcs_per_data):
# re-center the viewer on previous location.
viewer.center_on(sky_cen)
# only re-center the viewer if all data layers have WCS:
has_wcs_per_data = [data_has_valid_wcs(d) for d in viewer.data()]
if all(has_wcs_per_data):
# re-center the viewer on previous location.
viewer.center_on(sky_cen)

def _link_new_data(self, reference_data=None, data_to_be_linked=None):
"""
Expand Down
7 changes: 3 additions & 4 deletions jdaviz/configs/imviz/plugins/orientation/orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ def _update_link(self, msg={}):
if self.align_by.selected == 'Pixels':
self.wcs_fast_approximation = True

self.linking_in_progress = False
self._link_image_data()
# NOTE: _link_image_data will reset linking_in_progress to False

# load data into the viewer that are now compatible with the
# new link type, remove data from the viewer that are now
Expand Down Expand Up @@ -418,8 +418,7 @@ def _send_wcs_layers_to_all_viewers(self, *args, **kwargs):
'viewers_to_update', self.app._viewer_store.keys()
)
for viewer_ref in viewers_to_update:
self.viewer.selected = viewer_ref
self.orientation.update_wcs_only_filter(wcs_only=self.align_by_selected == 'WCS')
viewer_dm = self.app._jdaviz_helper.viewers.get(viewer_ref).data_menu
for wcs_layer in wcs_only_layers:
if wcs_layer not in self.viewer.selected_obj.layers:
self.app.add_data_to_viewer(viewer_ref, wcs_layer)
Expand All @@ -428,7 +427,7 @@ def _send_wcs_layers_to_all_viewers(self, *args, **kwargs):
wcs_only_layers and
self.align_by_selected == 'WCS'
):
self.orientation.selected = base_wcs_layer_label
viewer_dm.orientation.selected = base_wcs_layer_label

def _on_data_add_to_viewer(self, msg):
all_wcs_only_layers = all(
Expand Down

0 comments on commit e6548c4

Please sign in to comment.