-
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
Handle aperture photometry when images linked by WCS for advanced cases #2154
Conversation
"axs[1].set_ylim(70, 80)\n", | ||
"axs[2].imshow(rect_grp.subsets[2].to_mask(), origin='lower')\n", | ||
"axs[2].set_xlim(105, 125)\n", | ||
"axs[2].set_ylim(70, 80);" |
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.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
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.
@larrybradley , to answer your question, if I draw a rectangle on the third image (down-sampled and rotated), the rectangle comes back warped as if I drew it on the reference image, which is what I suspected would happen.
@larrybradley and I discussed several options. The most scientifically correct way is still using sky regions (as suggested by @bmorris3). However, this does disable the plugin for any data without WCS. Hence, Larry also requested that we put in extra logic to still fall back to the old way of doing things (pixel regions) if image does not have WCS and is the reference image for the Subset. But is that the same as a viewer reference image (have to check what becomes the viewer reference image when you only display a non-reference image in the viewer; answer is still the original reference image)? While we're at it, I guess technically we can always falls back to using pixel regions if we detect the link is in pixel space whether the data of interest has WCS or not. Keep in mind that even when Imviz is asked to link by WCS and the reference data has WCS, any image without WCS still links to the reference data by pixel. And since glue-astronomy does not handle sky regions (see glue-viz/glue-astronomy#89), we would have to rely on our own region_translators.py. |
57de42c
to
2e6eb56
Compare
For completeness, Larry said photutils would ignore distortion anyway (that is, if you pass in a circular aperture and WCS with distortion, it would still be circular when extracting the data array, not a distorted circle shape) so we should not worry about distortion here. |
2e6eb56
to
08a1b27
Compare
For future me: With this, I don't need GWCS. And since I will add all these as static test data files, hopefully we never have to rerun these again. To downsample by 2w2_hdr['CRPIX1'] = 250 / 2
w2_hdr['CRPIX2'] = 150 / 2
w2_hdr['NAXIS1'] = 250
w2_hdr['NAXIS2'] = 150
w2_hdr['CDELT1'] = 2
w2_hdr['CDELT2'] = 2 Goes with: data_sm = block_reduce(data, 2) Where: data = make_100gaussians_image()
w = make_wcs(data.shape) To rotatedef rotate(wcs_in, theta):
wcs = deepcopy(wcs_in)
theta = np.deg2rad(theta)
sinq = np.sin(theta)
cosq = np.cos(theta)
mrot = np.array([[cosq, -sinq],
[sinq, cosq]])
if wcs.wcs.has_cd(): # CD matrix
newcd = np.dot(mrot, wcs.wcs.cd)
wcs.wcs.cd = newcd
wcs.wcs.set()
elif wcs.wcs.has_pc(): # PC matrix + CDELT
newpc = np.dot(mrot, wcs.wcs.get_pc())
wcs.wcs.pc = newpc
wcs.wcs.set()
else:
raise TypeError("Unsupported wcs type (need CD or PC matrix)")
return wcs Goes with: data_rot, _ = reproject_interp(image_2, w3, shape_out=data_sm.shape) |
This comment was marked as resolved.
This comment was marked as resolved.
53677ca
to
4bc18e0
Compare
f6a38a9
to
cfb3ff1
Compare
0184fe6
to
901375b
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #2154 +/- ##
==========================================
+ Coverage 90.70% 90.72% +0.02%
==========================================
Files 157 157
Lines 17969 18015 +46
==========================================
+ Hits 16299 16345 +46
Misses 1670 1670
☔ View full report in Codecov by Sentry. |
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.
Neat!
# TODO: Brett Morris might want to look at this for | ||
# https://github.com/spacetelescope/jdaviz/pull/2179 | ||
# ref_label = self.state.reference_data ??? | ||
# | ||
# The original links were created against data_collection[0], not necessarily | ||
# against the current viewer reference_data | ||
ref_label = self.session.application.data_collection[0].label |
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.
If I understand your comment correctly, you're thinking about (near-)future-proofing this by looking up the current reference data's label? If so, I'll suggest that change here.
fcb3e91
to
71738c0
Compare
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.
Thanks for the updates 👌🏻
<v-text-field v-if="item.name === 'Parent'" | ||
:label="item.name" | ||
:value="item.value" | ||
style="padding-top: 0px; margin-top: 0px" | ||
:readonly="true" | ||
hint="Subset was defined with respect to this reference data (read-only)" | ||
></v-text-field> |
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 think we'll eventually want to move this out of the subregions once reparenting is implemented (or perhaps remove entirely), but since its read-only, it doesn't hurt to have for now and could be useful for debugging.
"""Find the type of ``glue`` linking between the given | ||
data labels. A link is bi-directional. If there are | ||
more than 2 data in the collection, one of the given | ||
labels should be the reference data or look-up will fail. |
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.
@bmorris3 - does the rotation work remove some of this flexibility (by forbidding mixed linking)? If we might need to change or remove this, should we make it private in the meantime?
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 think this method is useful with or without the rotation work. It's likely the case that it will be redundant with the link type attribute after image rotation is merged and WCS-linked in Imviz, but I think it's handy for debugging.
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.
Do you think it should be public or private in the meantime?
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 don't see why it should be private. The information is so useful in the meantime that I think it should be public. If it comes a day we don't need it anymore, then we can deprecate it.
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 agree that public is fine.
There is a conflict now, I will have to rebase and let the CI run again. |
advanced aperture photometry. Add tests that will fail without fix WIP: How to actually fix this mess Remove warning from doc [ci skip] [rtd skip]
BUG: Make sure recentering works in Subset Tools WIP: What about the actual bug [ci skip] [rtd skip]
to images linked by WCS if sky projection is different
and remove outdated comment
and remove debug comment
Co-authored-by: Brett M. Morris <[email protected]>
Co-authored-by: Brett M. Morris <[email protected]>
71738c0
to
3ab15d3
Compare
Looks like a new deprecation warning from scipy over the weekend. It is unrelated.
|
Thanks, all! |
Description
This pull request is to investigate and hopefully fix the bug of aperture photometry not able to provide correct result in certain cases, e.g.:
Blocked by
TODO
Can we also fix Edit Subset plugin by translating sky region to pixel of the selected image? Would need new dropdown for the plugin.Change log entry
CHANGES.rst
? If you want to avoid merge conflicts,list the proposed change log here for review and add to
CHANGES.rst
before merge. If no, maintainershould add a
no-changelog-entry-needed
label.Checklist for package maintainer(s)
This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.
trivial
label.