-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix aperture photometry result for WCS linked dithered non-reference data #1524
Changes from all commits
d7c087a
8e53e89
98d20aa
12adc70
b7c85ca
4b75709
6cfe418
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -500,10 +500,6 @@ def link_image_data(app, link_type='pixels', wcs_fallback_scheme='pixels', wcs_u | |
if update_plugin and 'imviz-links-control' in [item['name'] for item in app.state.tray_items]: | ||
link_plugin = app.get_tray_item_from_name('imviz-links-control') | ||
link_plugin.linking_in_progress = True | ||
app.hub.broadcast(LinkUpdatedMessage(link_type, | ||
wcs_fallback_scheme == 'pixels', | ||
wcs_use_affine, | ||
sender=app)) | ||
else: | ||
link_plugin = None | ||
|
||
|
@@ -573,5 +569,10 @@ def link_image_data(app, link_type='pixels', wcs_fallback_scheme='pixels', wcs_u | |
'Images successfully relinked', color='success', timeout=8000, sender=app)) | ||
|
||
if link_plugin is not None: | ||
# Only broadcast after success. | ||
app.hub.broadcast(LinkUpdatedMessage(link_type, | ||
wcs_fallback_scheme == 'pixels', | ||
wcs_use_affine, | ||
sender=app)) | ||
Comment on lines
+572
to
+576
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this move should be ok since the spinner state is updated independently of the event, the only difference will be that when calling linking from the API the spinner will now start, the linking will happen, THEN the radio buttons will update and the spinner will clear (whereas before the radio buttons would switch before the linking actually started). I can see how for other uses of checking the linking (like in this PR) it is more beneficial to receive the message after the linking has been completed. |
||
# reset the progress spinner | ||
link_plugin.linking_in_progress = False |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
import warnings | ||
from datetime import datetime | ||
|
||
import astropy | ||
import bqplot | ||
import numpy as np | ||
from astropy import units as u | ||
|
@@ -12,14 +13,15 @@ | |
from astropy.time import Time | ||
from glue.core.message import SubsetUpdateMessage | ||
from ipywidgets import widget_serialization | ||
from packaging.version import Version | ||
from photutils.aperture import (ApertureStats, CircularAperture, EllipticalAperture, | ||
RectangularAperture) | ||
from regions import (CircleAnnulusPixelRegion, CirclePixelRegion, EllipsePixelRegion, | ||
RectanglePixelRegion) | ||
from traitlets import Any, Bool, List, Unicode, observe | ||
|
||
from jdaviz.core.custom_traitlets import FloatHandleEmpty | ||
from jdaviz.core.events import SnackbarMessage | ||
from jdaviz.core.events import SnackbarMessage, LinkUpdatedMessage | ||
from jdaviz.core.region_translators import regions2aperture | ||
from jdaviz.core.registries import tray_registry | ||
from jdaviz.core.template_mixin import PluginTemplateMixin, DatasetSelectMixin, SubsetSelect | ||
|
@@ -74,6 +76,7 @@ def __init__(self, *args, **kwargs): | |
self._fitted_model_name = 'phot_radial_profile' | ||
|
||
self.session.hub.subscribe(self, SubsetUpdateMessage, handler=self._on_subset_update) | ||
self.session.hub.subscribe(self, LinkUpdatedMessage, handler=self._on_link_update) | ||
|
||
def reset_results(self): | ||
self.result_available = False | ||
|
@@ -143,9 +146,20 @@ def _get_region_from_subset(self, subset): | |
if subset_grp.label == subset: | ||
for sbst in subset_grp.subsets: | ||
if sbst.data.label == self.dataset_selected: | ||
# TODO: https://github.com/glue-viz/glue-astronomy/issues/52 | ||
return sbst.data.get_selection_definition( | ||
subset_id=subset, format='astropy-regions') | ||
reg = sbst.data.get_selection_definition( | ||
subset_id=subset, 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. | ||
viewer = self.app._jdaviz_helper.default_viewer | ||
|
||
x, y, _ = viewer._get_real_xy( | ||
self.app.data_collection[self.dataset_selected], | ||
reg.center.x, reg.center.y) | ||
reg.center.x = x | ||
reg.center.y = y | ||
return reg | ||
else: | ||
raise ValueError(f'Subset "{subset}" not found') | ||
|
||
|
@@ -159,6 +173,13 @@ def _on_subset_update(self, msg): | |
elif sbst.label == self.bg_subset_selected and sbst.data.label == self.dataset_selected: | ||
self._bg_subset_selected_changed() | ||
|
||
def _on_link_update(self, msg): | ||
if self.dataset_selected == '' or self.subset_selected == '': | ||
return | ||
|
||
# Force background auto-calculation (including annulus) to update when linking has changed. | ||
self._subset_selected_changed() | ||
|
||
@observe('subset_selected') | ||
def _subset_selected_changed(self, event={}): | ||
subset_selected = event.get('new', self.subset_selected) | ||
|
@@ -396,8 +417,12 @@ def vue_do_aper_phot(self, *args, **kwargs): | |
gs = Gaussian1D(amplitude=y_max, mean=0, stddev=std, | ||
fixed={'mean': True, 'amplitude': True}, | ||
bounds={'amplitude': (y_max * 0.5, y_max)}) | ||
if Version(astropy.__version__) <= Version('5.1'): | ||
fitter_kw = {} | ||
else: | ||
fitter_kw = {'filter_non_finite': True} | ||
pllim marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The coverage will complain about this because this is tested in the dev deps job but we do not calculate coverage for dev deps. |
||
with warnings.catch_warnings(record=True) as warns: | ||
fit_model = fitter(gs, x_data, y_data) | ||
fit_model = fitter(gs, x_data, y_data, **fitter_kw) | ||
if len(warns) > 0: | ||
msg = os.linesep.join([str(w.message) for w in warns]) | ||
self.hub.broadcast(SnackbarMessage( | ||
|
@@ -485,7 +510,13 @@ def _radial_profile(radial_cutout, reg_bb, centroid, raw=False): | |
reg_ogrid = np.ogrid[reg_bb.iymin:reg_bb.iymax, reg_bb.ixmin:reg_bb.ixmax] | ||
radial_dx = reg_ogrid[1] - centroid[0] | ||
radial_dy = reg_ogrid[0] - centroid[1] | ||
radial_r = np.hypot(radial_dx, radial_dy)[~radial_cutout.mask].ravel() # pix | ||
radial_r = np.hypot(radial_dx, radial_dy) | ||
|
||
# Sometimes the mask is smaller than radial_r | ||
if radial_cutout.shape != reg_bb.shape: | ||
radial_r = radial_r[:radial_cutout.shape[0], :radial_cutout.shape[1]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @larrybradley , in my test case (10 x 10 images dithered by 1 pix with mask off-limit a little for second image when linked by WCS), ApertureStat bounding box shape can be different from the cutout shape. Is this the right way to handle it? |
||
|
||
radial_r = radial_r[~radial_cutout.mask].ravel() # pix | ||
radial_img = radial_cutout.compressed() # data unit | ||
|
||
if raw: | ||
|
@@ -495,7 +526,7 @@ def _radial_profile(radial_cutout, reg_bb, centroid, raw=False): | |
else: | ||
# This algorithm is from the imexam package, | ||
# see licenses/IMEXAM_LICENSE.txt for more details | ||
radial_r = list(radial_r) | ||
radial_r = np.rint(radial_r).astype(int) | ||
y_arr = np.bincount(radial_r, radial_img) / np.bincount(radial_r) | ||
x_arr = np.arange(y_arr.size) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be removed now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to keep it. I think it is a good recommendation regardless.