Skip to content

Commit

Permalink
WIP: How to actually fix this mess
Browse files Browse the repository at this point in the history
[ci skip] [rtd skip]
  • Loading branch information
pllim committed Apr 21, 2023
1 parent dfaa0e4 commit 53677ca
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
6 changes: 5 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ Cubeviz
Imviz
^^^^^

* Do not hide previous results in aperture photometry when there is a failure, but rather show
- 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]

- Do not hide previous results in aperture photometry when there is a failure, but rather show
the failure message within the plugin UI to indicate the shown results are "out of date". [#2112]

Mosviz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def vue_recenter_subset(self, *args):
data = self.dataset.selected_dc_item
comp = data.get_component(data.main_components[0])
comp_data = comp.data
phot_aperstats = ApertureStats(comp_data, aperture)
phot_aperstats = ApertureStats(comp_data, aperture, wcs=data.coords)

# Centroid was calculated in selected data, which might or might not be
# the reference data. However, Subset is always defined w.r.t.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

__all__ = ['SimpleAperturePhotometry']

# TODO: This plugin needs to show params wrt ref data because that is how glue
# defined it, but then it needs to do internal calculation using region
# that took account of the dither.


@tray_registry('imviz-aper-phot-simple', label="Imviz Simple Aperture Photometry")
class SimpleAperturePhotometry(PluginTemplateMixin, DatasetSelectMixin, TableMixin):
Expand Down
35 changes: 13 additions & 22 deletions jdaviz/core/region_translators.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _get_region_from_spatial_subset(plugin_obj, subset_label):
The plugin is assumed to have a special setup that gives
it access to these attributes: ``app`` and ``dataset_selected``.
The ``app._jdaviz_helper.default_viewer`` attribute must also
exist and point to an image viewer that has a ``_get_real_xy``
exist and point to an image viewer that has a ``get_link_type``
method.
subset_label : str
Expand All @@ -41,7 +41,8 @@ def _get_region_from_spatial_subset(plugin_obj, subset_label):
Returns
-------
reg : `regions.Region`
An equivalent ``regions`` shape.
An equivalent ``regions`` shape. This can be a pixel or sky
region, so the plugin needs to be able to deal with both.
Raises
------
Expand All @@ -57,31 +58,21 @@ def _get_region_from_spatial_subset(plugin_obj, subset_label):
if subset_grp.label == subset_label:
for sbst in subset_grp.subsets:
if sbst.data.label == plugin_obj.dataset_selected:

# TODO:
# If dataset_selected is not viewer.state.reference_data
# and they are linked by WCS.
# sky_reg = pix_region.to_sky(wcs)
# and no need for viewer._get_real_xy()
# but we still need the old way for subset_plugin.py.
# Should update docstring above.
# Should update aper phot user docs and tests.
# Turn concept notebook into a new test.

reg = sbst.data.get_selection_definition(
subset_id=subset_label, format='astropy-regions')

# Works around https://github.com/glue-viz/glue-astronomy/issues/52
# Assume it is always pixel region, not sky region. 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.
# 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)

x, y, _, _ = viewer._get_real_xy(
plugin_obj.app.data_collection[plugin_obj.dataset_selected],
reg.center.x, reg.center.y)
reg.center.x = x
reg.center.y = y
return reg
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')

Expand Down

0 comments on commit 53677ca

Please sign in to comment.