Skip to content

Commit

Permalink
Fix GUI update
Browse files Browse the repository at this point in the history
and dithered use case
  • Loading branch information
pllim committed Nov 9, 2022
1 parent be14727 commit 5a5d23a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
13 changes: 12 additions & 1 deletion jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,13 @@ def vue_recenter_subset(self, *args):
comp_data = comp.data
phot_aperstats = ApertureStats(comp_data, aperture)

self.set_center(phot_aperstats.centroid, update=False)
# Centroid was calculated in selected data, which might or might not be
# the reference data. However, Subset is always defined w.r.t.
# the reference data, so we need to convert back.
viewer = self.app._jdaviz_helper.default_viewer
x, y, _ = viewer._get_real_xy(
data, phot_aperstats.xcentroid, phot_aperstats.ycentroid, reverse=True)
self.set_center((x, y), update=False)

def get_center(self):
# Composite region cannot be edited.
Expand Down Expand Up @@ -304,6 +310,11 @@ def set_center(self, new_cen, update=False):

if update:
self.vue_update_subset()
else:
# Force UI to update on browser without changing the subset.
tmp = self.subset_definitions
self.subset_definitions = []
self.subset_definitions = tmp

# List of JSON-like dict is nice for front-end but a pain to look up,
# so we use these helper functions.
Expand Down
13 changes: 10 additions & 3 deletions jdaviz/configs/imviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,15 @@ def on_limits_change(self, *args):
return
self.set_compass(self.state.layers[i].layer)

def _get_real_xy(self, image, x, y):
def _get_real_xy(self, image, x, y, reverse=False):
"""Return real (X, Y) position and status in case of dithering.
``coords_status`` is for ``self.label_mouseover`` coords handling only.
When `True`, it sets the coords, otherwise it resets.
``reverse=True`` is only for internal roundtripping (e.g., centroiding
in Subset Tools plugin). Never use this for coordinates display panel.
"""
if data_has_valid_wcs(image):
# Convert these to a SkyCoord via WCS - note that for other datasets
Expand All @@ -235,8 +238,12 @@ def _get_real_xy(self, image, x, y):
# Convert X,Y from reference data to the one we are actually seeing.
# world_to_pixel return scalar ndarray that we need to convert to float.
if self.get_link_type(image.label) == 'wcs':
x, y = list(map(float, image.coords.world_to_pixel(
self.state.reference_data.coords.pixel_to_world(x, y))))
if not reverse:
x, y = list(map(float, image.coords.world_to_pixel(
self.state.reference_data.coords.pixel_to_world(x, y))))
else:
x, y = list(map(float, self.state.reference_data.coords.world_to_pixel(
image.coords.pixel_to_world(x, y))))
coords_status = True
except Exception:
coords_status = False
Expand Down
9 changes: 9 additions & 0 deletions notebooks/concepts/imviz_edit_subset_programmatic.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "e23ea362",
"metadata": {},
"source": [
"This concept notebook shows how you can move spatial subsets around in Imviz programmatically."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -111,6 +119,7 @@
" cur_x, cur_y = plg.get_center()\n",
" plg.set_center((cur_x + 5, cur_y), update=True)\n",
"\n",
" # We slow it down so you can see, otherwise this will complete too fast.\n",
" time.sleep(0.5)\n",
" \n",
" plg.subset_selected = 'Subset 2'\n",
Expand Down

0 comments on commit 5a5d23a

Please sign in to comment.