Skip to content
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

Merged
merged 17 commits into from
Mar 6, 2024

Conversation

rosteen
Copy link
Collaborator

@rosteen rosteen commented Feb 27, 2024

Previously, the subset reparenting didn't properly handle the rotation between two different orientations. This fixes it. I'll add test coverage tomorrow.

@rosteen rosteen added bug Something isn't working imviz labels Feb 27, 2024
@rosteen rosteen added this to the 3.9 milestone Feb 27, 2024
@pllim
Copy link
Contributor

pllim commented Feb 27, 2024

You would have to also remove the xfail here:

@pytest.mark.xfail(reason="FIXME: JDAT-3958")

Copy link
Contributor

@pllim pllim left a 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.

jdaviz/app.py Outdated Show resolved Hide resolved
jdaviz/app.py Outdated Show resolved Hide resolved
Copy link
Contributor

@pllim pllim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP 8

jdaviz/app.py Outdated Show resolved Hide resolved
jdaviz/app.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Feb 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.92%. Comparing base (0336005) to head (65f3e10).
Report is 7 commits behind head on main.

❗ Current head 65f3e10 differs from pull request most recent head b01b2a6. Consider uploading reports for the commit b01b2a6 to get more accurate results

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.
📢 Have feedback on the report? Share it here.

@rosteen rosteen marked this pull request as ready for review February 29, 2024 14:46
@pllim
Copy link
Contributor

pllim commented Feb 29, 2024

p.s. Looks like I am not off the hook from #2724 since you didn't have to remove the AssertionError from these.

# FIXME: spacetelescope/jdaviz#2724 (remove AssertionError)
lc_plugin.link_type = 'WCS'
with pytest.raises(AssertionError):
assert self.viewer.state.reference_data.label == "Default orientation"
with pytest.raises(AssertionError):
assert viewer_2.state.reference_data.label == "Default orientation"

Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com>
jdaviz/app.py Outdated
Comment on lines 1833 to 1840
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)
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

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":
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Member

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 Show resolved Hide resolved
jdaviz/app.py Show resolved Hide resolved
jdaviz/app.py Outdated Show resolved Hide resolved
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":
Copy link
Member

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)?

@rosteen
Copy link
Collaborator Author

rosteen commented Mar 4, 2024

@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.

rosteen and others added 3 commits March 5, 2024 10:47
Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com>
@rosteen
Copy link
Collaborator Author

rosteen commented Mar 5, 2024

@kecnry @pllim This is ready for another look.

Copy link
Contributor

@pllim pllim left a 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.

jdaviz/app.py Outdated Show resolved Hide resolved
jdaviz/app.py Outdated Show resolved Hide resolved
@pllim
Copy link
Contributor

pllim commented Mar 5, 2024

I want to double check that the test catalog failure isn't transient or related. Gonna restart that job.

>       assert catalogs_plugin.number_of_results > 500
E       AssertionError: assert 0 > 500
E        +  where 0 = Catalogs...

jdaviz/configs/imviz/tests/test_catalogs.py:104: AssertionError

@pllim
Copy link
Contributor

pllim commented Mar 5, 2024

Nvm I see the same Catalogs failure on main. It is unrelated.

Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com>
@pllim
Copy link
Contributor

pllim commented Mar 5, 2024

p.s. FWIW #2738 is to address Catalog failure (that seems to be gone now).

Copy link
Contributor

@pllim pllim left a 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):
Copy link
Contributor

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)])
Copy link
Contributor

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"),
Copy link
Contributor

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.
Copy link
Contributor

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.

Copy link
Member

@kecnry kecnry left a 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
Comment on lines 1804 to 1805
if old_flip != new_flip:
relative_angle = 180 - new_angle - old_angle
Copy link
Member

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.

Copy link
Contributor

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?

jdaviz/app.py Show resolved Hide resolved
@rosteen
Copy link
Collaborator Author

rosteen commented Mar 6, 2024

Thanks for the test updates @pllim, I added a comment about irregular regions and will merge after tests pass.

@rosteen rosteen merged commit 4433d39 into spacetelescope:main Mar 6, 2024
14 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants