-
Notifications
You must be signed in to change notification settings - Fork 76
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
Imviz: astrowidget API for center_on and offset_to #687
Imviz: astrowidget API for center_on and offset_to #687
Conversation
Codecov Report
@@ Coverage Diff @@
## main #687 +/- ##
==========================================
+ Coverage 60.13% 60.80% +0.66%
==========================================
Files 65 65
Lines 4099 4156 +57
==========================================
+ Hits 2465 2527 +62
+ Misses 1634 1629 -5
Continue to review full report at Codecov.
|
30f1543
to
e1e8906
Compare
@@ -2,13 +2,15 @@ | |||
"cells": [ | |||
{ | |||
"cell_type": "markdown", | |||
"id": "17b4af6f", |
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 isn't me. Jupyter did this after I upgraded. 🤷
e1e8906
to
a96032d
Compare
new_sky_cen = sky_cen.__class__( | ||
SkyOffsetFrame(dx, dy, origin=sky_cen.frame).transform_to(sky_cen)) | ||
else: | ||
new_sky_cen = sky_cen.spherical_offsets_by(dx, dy) |
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: This was added in astropy/astropy#11635
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from astropy.utils.data import download_file\n", | ||
"\n", | ||
"gc_2mass_j = download_file('https://www.astropy.org/astropy-data/galactic_center/gc_2mass_j.fits', cache=True)\n", | ||
"gc_msx_e = download_file('https://www.astropy.org/astropy-data/galactic_center/gc_msx_e.fits', cache=True)" | ||
"acs_47tuc_1 = download_file('https://mast.stsci.edu/api/v0.1/Download/file?uri=mast:HST/product/jbqf03gjq_flc.fits', cache=True)\n", |
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.
For my sanity, I am replacing the example images with real HST/ACS data. Everyone loves 47 Tuc, right? Or is it just calibration team? 😉
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"viewer.state.layers[0].percentile = 99" | ||
"viewer.state.layers[0].percentile = 95" |
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 for my sanity. Things are easier to see with 95th percentile.
a96032d
to
c910d1d
Compare
|
||
class TestAstrowidgetsAPI: | ||
@pytest.fixture(autouse=True) | ||
def setup_class(self, imviz_app): |
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: This is basically the same test setup in #630 . When we get back to the other PR, will have to see how to consolidate this to avoid code duplication.
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.
Just a couple of comments but looks good otherwise!
|
||
if isinstance(point, SkyCoord): | ||
i_top = get_top_layer_index(viewer) | ||
image = viewer.layers[i_top].layer |
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 you should probably use image = viewer.reference_data as that is the one which is used to define the pixel space
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.
Your suggestion does not seem to work: AttributeError: 'ImvizImageView' object has no attribute 'reference_data'
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.
viewer.state.reference_data
exists but it causes my test to fail:
# Blink to the one without WCS
self.viewer.blink_once()
with pytest.raises(AttributeError, match='does not have a valid WCS'):
> self.imviz.center_on(sky)
E Failed: DID NOT RAISE <class 'AttributeError'>
jdaviz/configs/imviz/tests/test_astrowidgets_api.py:83: Failed
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.
It appears reference_data
does not keep track of which layer is actually visible to the user after blinking.
|
||
if skycoord_offset: | ||
i_top = get_top_layer_index(viewer) | ||
image = viewer.layers[i_top].layer |
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.
as above
Looks pretty good, the only thing I think might be good to add is some checking to see if the
Perhaps it would be useful to check whether the sky coordinates input are within the image bounds, and if not raise a more informative/concise error that you can't center on sky coordinates outside the image. |
That's with |
Ah, yes. FLC is not corrected for distortion. 😬 |
c910d1d
to
2650711
Compare
@rosteen , is this better? |
I like capturing it that way much better than the long stack trace in the notebook. Approving, since making this work with more viewers needs to happen after some other work. |
Just did. No more error printouts, but the viewer still whites out and trying to recenter on an in-image location doesn't have a visible effect. |
d077314
to
7039327
Compare
Added one more check. Is this a satisfactory solution to the error you encounter, @ojustino ? |
The CI failure smells like upstream problem in Actions:
|
@pllim With this commit, It is not blocking SkyCoords that are off-screen and off-image, and that case still causes the white out and does not trigger the dropdown message. |
@ojustino , at this point... please point me to that image you are using, and provide me with the calls that (1) block execution, and (2) white out. Thanks for the very thorough checks! |
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 was able to run the demo notebook and exercise all cells that have the centering and offseting operations. The image seemed to behave in the way we expect.
Perhaps the problems are with my environment, then? In any case, these are my images:
This is the offending code:
I also tried the notebook's original 47 Tuc images and get the same unintended blocking behavior in the "off-screen, on-image" case, though the "off-screen, off-image" case is blocked as intended. I should also note that anything "on-screen and on-image" has been working fine. |
What does "off-screen, on-image" mean? |
A set of coordinates that has data in the image but is not currently visible in the viewer. An example would be if I'm zoomed in at one corner and want to center on a location on the opposite side of the image. |
Oh... In this case, perhaps changing x/y_min/max of the layer does not actually load the data that is currently not displayed. If you know how to force data loading, please let me know. Otherwise, here is my proposal:
|
That's an answer I don't know.
|
@astrofrog , if you feel strongly about using |
Post-hoc review: this looks great, except for one thing: I think it should be |
Implement some of #631 and #632.
delay_callback
is very important...)SkyCoord
implementation can be trivial. (Yes)Out of scope: Unable to use this API on a tiled viewers; i.e., it only works on the first viewer that the app opened. See #643