Skip to content

Commit

Permalink
FEAT: Add parent info to ROI subset
Browse files Browse the repository at this point in the history
BUG: Make sure recentering works in Subset Tools

WIP: What about the actual bug

[ci skip] [rtd skip]
  • Loading branch information
pllim committed Aug 10, 2023
1 parent 0c4318a commit f1d2ca7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 47 deletions.
13 changes: 9 additions & 4 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ New Features

- Improved design of Launcher and pass filepath arg from cli when no config specified. [#2311]

- Subset Tools plugin now displays the parent data of a spatial (ROI) subset. [#2154]

Cubeviz
^^^^^^^

Expand All @@ -32,6 +34,13 @@ Cubeviz
Imviz
^^^^^

- Fixed Subset Tools unable to re-center non-composite spatial subset on an image
that is not the reference data when linked by WCS. [#2154]

- Fixed inaccurate results when aperture photometry is performed on non-reference data
that are of a different pixel scale or are rotated w.r.t. the reference data when
linked by WCS. [#2154]

Mosviz
^^^^^^

Expand All @@ -50,10 +59,6 @@ Cubeviz
Imviz
^^^^^

- Fixed inaccurate results when aperture photometry is performed on non-reference data
that are of a different pixel scale or are rotated w.r.t. the reference data when
linked by WCS. [#2154]

Mosviz
^^^^^^

Expand Down
41 changes: 18 additions & 23 deletions jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,10 @@ def _sync_selected_from_ui(self, change):
if m != self.session.edit_subset_mode.edit_subset:
self.session.edit_subset_mode.edit_subset = m

'''
# This will be needed once we use a dropdown instead of the actual
# g-subset-mode component
@observe("mode_selected")
def _mode_selected_changed(self, event={}):
if self.session.edit_subset_mode != self.mode_selected:
self.session.edit_subset_mode = self.mode_selected
'''

def _unpack_get_subsets_for_ui(self):
"""
Convert what app.get_subsets returns into something the UI of this plugin
can display.
Returns
-------
"""
subset_information = self.app.get_subsets(self.subset_selected, simplify_spectral=False,
use_display_units=True)
Expand All @@ -164,12 +151,17 @@ def _unpack_get_subsets_for_ui(self):
subset_state = spec["subset_state"]
glue_state = spec["glue_state"]
if isinstance(subset_state, RoiSubsetState):
subset_definition.append({
"name": "Parent", "att": "parent",
"value": subset_state.xatt.parent.label,
"orig": subset_state.xatt.parent.label})

if isinstance(subset_state.roi, CircularROI):
x, y = subset_state.roi.center()
r = subset_state.roi.radius
subset_definition = [{"name": "X Center", "att": "xc", "value": x, "orig": x},
{"name": "Y Center", "att": "yc", "value": y, "orig": y},
{"name": "Radius", "att": "radius", "value": r, "orig": r}]
subset_definition += [{"name": "X Center", "att": "xc", "value": x, "orig": x},
{"name": "Y Center", "att": "yc", "value": y, "orig": y},
{"name": "Radius", "att": "radius", "value": r, "orig": r}]

elif isinstance(subset_state.roi, RectangularROI):
for att in ("Xmin", "Xmax", "Ymin", "Ymax"):
Expand All @@ -186,7 +178,7 @@ def _unpack_get_subsets_for_ui(self):
rx = subset_state.roi.radius_x
ry = subset_state.roi.radius_y
theta = np.around(np.degrees(subset_state.roi.theta), decimals=_around_decimals)
subset_definition = [
subset_definition += [
{"name": "X Center", "att": "xc", "value": xc, "orig": xc},
{"name": "Y Center", "att": "yc", "value": yc, "orig": yc},
{"name": "X Radius", "att": "radius_x", "value": rx, "orig": rx},
Expand All @@ -197,12 +189,12 @@ def _unpack_get_subsets_for_ui(self):
x, y = subset_state.roi.center()
inner_r = subset_state.roi.inner_radius
outer_r = subset_state.roi.outer_radius
subset_definition = [{"name": "X Center", "att": "xc", "value": x, "orig": x},
{"name": "Y Center", "att": "yc", "value": y, "orig": y},
{"name": "Inner radius", "att": "inner_radius",
"value": inner_r, "orig": inner_r},
{"name": "Outer radius", "att": "outer_radius",
"value": outer_r, "orig": outer_r}]
subset_definition += [{"name": "X Center", "att": "xc", "value": x, "orig": x},
{"name": "Y Center", "att": "yc", "value": y, "orig": y},
{"name": "Inner radius", "att": "inner_radius",
"value": inner_r, "orig": inner_r},
{"name": "Outer radius", "att": "outer_radius",
"value": outer_r, "orig": outer_r}]

subset_type = subset_state.roi.__class__.__name__

Expand Down Expand Up @@ -282,6 +274,9 @@ def vue_update_subset(self, *args):
return
sub_states = self.subset_states[index]
for d_att in sub:
if d_att["att"] == 'parent': # Read-only
continue

if d_att["att"] == 'theta': # Humans use degrees but glue uses radians
d_val = np.radians(d_att["value"])
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@
</v-row>

<v-row v-for="(item, index2) in region" class="row-no-outside-padding">
<v-text-field
<v-text-field v-if="item.name === 'Parent'"
:label="item.name"
:value="item.value"
style="padding-top: 0px; margin-top: 0px"
:readonly="true"
></v-text-field>
<v-text-field v-if="item.name !== 'Parent'"
:label="item.name"
v-model.number="item.value"
type="number"
Expand Down
38 changes: 19 additions & 19 deletions jdaviz/core/region_translators.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,27 @@ def _get_region_from_spatial_subset(plugin_obj, subset_label):
regions2roi
"""
from glue_astronomy.translators.regions import roi_subset_state_to_region

for subset_grp in plugin_obj.app.data_collection.subset_groups:
if subset_grp.label == subset_label:
for sbst in subset_grp.subsets:
if sbst.data.label == plugin_obj.dataset_selected:
reg = sbst.data.get_selection_definition(
subset_id=subset_label, format='astropy-regions')

# Works around https://github.com/glue-viz/glue-astronomy/issues/52
# Even with multiple viewers, they all seem to share the same
# reference image even when it is not loaded in all the viewers,
# so use default viewer.
viewer = plugin_obj.app._jdaviz_helper.default_viewer
link_type = viewer.get_link_type(plugin_obj.dataset_selected)

if link_type == 'wcs':
return reg.to_sky(
plugin_obj.app.data_collection[plugin_obj.dataset_selected].coords)
else: # pixels or self
return reg
else:
raise ValueError(f'Subset "{subset_label}" not found')
sbst = subset_grp.subset_state

# Works around https://github.com/glue-viz/glue-astronomy/issues/52
# Even with multiple viewers, they all seem to share the same
# reference image even when it is not loaded in all the viewers,
# so use default viewer.
viewer = plugin_obj.app._jdaviz_helper.default_viewer
link_type = viewer.get_link_type(plugin_obj.dataset_selected)

if link_type == 'wcs':
to_sky = True
else:
to_sky = False

return roi_subset_state_to_region(sbst, to_sky=to_sky)

raise ValueError(f'Subset "{subset_label}" not found')


def regions2roi(region_shape, wcs=None):
Expand Down

0 comments on commit f1d2ca7

Please sign in to comment.