-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix reparenting subsets between rotation orientations #2734
Conversation
You would have to also remove the xfail here:
|
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.
Need a change log.
And remove leftover debugging stuff.
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.
PEP 8
4852d55
to
6ddbb29
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2734 +/- ##
==========================================
+ Coverage 88.67% 88.92% +0.24%
==========================================
Files 108 108
Lines 15886 15930 +44
==========================================
+ Hits 14087 14165 +78
+ Misses 1799 1765 -34 ☔ View full report in Codecov by Sentry. |
p.s. Looks like I am not off the hook from #2724 since you didn't have to remove the AssertionError from these. jdaviz/jdaviz/configs/imviz/tests/test_orientation.py Lines 140 to 145 in 0e0a3b7
|
Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com>
jdaviz/app.py
Outdated
x1, y1 = pixel_to_pixel(old_parent.coords, new_parent.coords, | ||
roi.xmin, roi.ymin) | ||
x2, y2 = pixel_to_pixel(old_parent.coords, new_parent.coords, | ||
roi.xmin, roi.ymax) | ||
x3, y3 = pixel_to_pixel(old_parent.coords, new_parent.coords, | ||
roi.xmax, roi.ymax) | ||
x3, y3 = pixel_to_pixel(old_parent.coords, new_parent.coords, | ||
roi.xmax, roi.ymin) |
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.
pixel_to_pixel
can vectorize, I think, see https://docs.astropy.org/en/stable/api/astropy.wcs.utils.pixel_to_pixel.html , so you really only need one call to that function.
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.
Hmm, I tried calling it a couple different ways, and it doesn't seem like vectorizing analogously to pixel_to_world
works for pixel_to_pixel
. I did remove an extra call, realized I was setting then overwriting x3 and y3.
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.
Oh, OK, maybe the API doc is misleading then. Thanks for trying!
jdaviz/app.py
Outdated
@@ -1995,7 +2024,11 @@ def vue_data_item_remove(self, event): | |||
|
|||
data_label = event['item_name'] | |||
data = self.data_collection[data_label] | |||
self._reparent_subsets(data) | |||
if self.config == "imviz": |
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.
Also have to check link type here? You don't want this happening when linked by pixel, right? Or is the link type being handled somewhere else?
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.
The check that link type is WCS is in _reparent_subsets
.
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 we check something else other than the config? Maybe check if the orientation plugin is loaded (which could probably be done in one line to avoid building helper.plugins multiple times, or by accessing the tray_items which is probably cheaper)?
jdaviz/app.py
Outdated
@@ -1995,7 +2024,11 @@ def vue_data_item_remove(self, event): | |||
|
|||
data_label = event['item_name'] | |||
data = self.data_collection[data_label] | |||
self._reparent_subsets(data) | |||
if self.config == "imviz": |
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 we check something else other than the config? Maybe check if the orientation plugin is loaded (which could probably be done in one line to avoid building helper.plugins multiple times, or by accessing the tray_items which is probably cheaper)?
@kecnry @pllim Most of the changes today were implementing Kyle's suggestion to check for the Orientation plugin, and fixing a semi-related bug I discovered while working on this (If you created a third orientation when a second one was active, then delete the second one, the third wouldn't be linked to anything). Should be ready for re-review tomorrow, I'll ping you then. |
Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com>
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.
Code looks like code. Some minor comments.
I want to double check that the test catalog failure isn't transient or related. Gonna restart that job.
|
Nvm I see the same Catalogs failure on main. It is unrelated. |
Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com>
p.s. FWIW #2738 is to address Catalog failure (that seems to be gone 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 pushed my remaining review as a commit, mainly expanding your new test. So this LGTM now. Thanks!
@@ -152,3 +156,48 @@ def test_custom_orientation(self): | |||
lc_plugin._obj.add_orientation(rotation_angle=None, east_left=True, label=None, | |||
set_on_create=True, wrt_data=None) | |||
assert self.viewer.state.reference_data.label == "CCW 42.00 deg (E-left)" | |||
|
|||
|
|||
class TestDeleteOrientation(BaseImviz_WCS_WCS): |
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.
Note: I made this its own test class so it does not pollute the other tests.
@pytest.mark.parametrize( | ||
("angle", "sbst_theta"), | ||
[(0.5 * u.rad, 2.641593), | ||
(-0.5 * u.rad, 3.641589)]) |
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.
Is -0.5 rad a good input for "negative angle"? If not, feel free to adjust the test.
lc_plugin._obj.create_north_up_east_left(set_on_create=True) | ||
|
||
# Create rotated shape | ||
reg = klass(center=SkyCoord(ra=337.51931488, dec=-20.83187472, unit="deg"), |
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.
Providing region as input made more sense to me, so I did that change here. Also added test case for rectangle that seems to have a separate logic route. Luckily ellipse and rectangle have same inputs in regions, so we can easily parametrize them.
assert_allclose(out_reg.center.dec.deg, reg.center.dec.deg) | ||
assert_quantity_allclose(out_reg.width, reg.width) | ||
assert_quantity_allclose(out_reg.height, reg.height) | ||
# FIXME: However, sky angle has to stay the same as per regions convention. |
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 fixing this is out of scope for this PR. If you have a JIRA ticket from the "what does 0 angle mean" meeting today, please link here.
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.
Seems to work well! Changing orientation and reparenting definitely isn't fast, so there may be room for optimization either here or elsewhere in the logic, but we can handle that separately. Thanks for the fix!
jdaviz/app.py
Outdated
if old_flip != new_flip: | ||
relative_angle = 180 - new_angle - old_angle |
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 still assumes some symmetry in the subcomponent of the subset and would break if we ever introduce lasso subsets, right? Maybe just worth a comment so we don't get tripped up by it in the future if we ever add that.
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.
FWIW, there is no lasso shape support in regions nor photutils. So it would probably be turned into some polygon that has no concept of angle anyway (though you would have to rotate it properly or whatever before you turn it into polygon), so maybe also put that in comment?
Thanks for the test updates @pllim, I added a comment about irregular regions and will merge after tests pass. |
Previously, the subset reparenting didn't properly handle the rotation between two different orientations. This fixes it. I'll add test coverage tomorrow.