Skip to content
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: Add zoom and zoom_level API #744

Merged
merged 5 commits into from
Aug 2, 2021

Conversation

pllim
Copy link
Contributor

@pllim pllim commented Jul 22, 2021

Fix #715

TODO

  • Maybe use reference image?
  • Clarify "fit" more.
  • Fix "real pixel size" logic. How to grab pixel width from figure viewer? viewer.shape
  • Add tests. Remember to test the different combos and zooming on off-center.

@pllim pllim added this to the Imviz 1.0 milestone Jul 22, 2021
@github-actions github-actions bot added documentation Explanation of code and concepts imviz labels Jul 22, 2021
jdaviz/configs/imviz/helper.py Outdated Show resolved Hide resolved
@pllim pllim force-pushed the imviz-zoom-not-the-meeting branch from 912923b to ced8ee0 Compare July 23, 2021 19:04
@pllim pllim force-pushed the imviz-zoom-not-the-meeting branch from ced8ee0 to a39b66a Compare July 26, 2021 22:14
@codecov
Copy link

codecov bot commented Jul 26, 2021

Codecov Report

Merging #744 (d3c7f37) into main (e29b827) will increase coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #744      +/-   ##
==========================================
+ Coverage   63.00%   63.09%   +0.08%     
==========================================
  Files          65       65              
  Lines        4290     4319      +29     
==========================================
+ Hits         2703     2725      +22     
- Misses       1587     1594       +7     
Impacted Files Coverage Δ
jdaviz/configs/imviz/helper.py 98.68% <100.00%> (-0.32%) ⬇️
...configs/default/plugins/data_tools/file_chooser.py 65.71% <0.00%> (-3.43%) ⬇️
jdaviz/configs/specviz/plugins/viewers.py 60.94% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e29b827...d3c7f37. Read the comment docs.

@pllim pllim force-pushed the imviz-zoom-not-the-meeting branch from fa852b0 to d3c7f37 Compare July 27, 2021 21:42
@pllim pllim marked this pull request as ready for review July 27, 2021 21:44

# NOTE: Not sure why X/Y min/max not exactly the same as aspect ratio 1
self.imviz.zoom_level = 1
self.assert_zoom_results(1, -46, 54, -45.5, 54.5, dpix)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does seem weird some x/y min/max not matching exactly for square data and display at aspect ratio one, but that adjustment is deep within glue core and I don't feel like digging no more. If @astrofrog has ideas, then great. Otherwise, I'll just leave it be.

# in the unit test when off-center. Works in notebook though.
if not is_offcenter:
self.imviz.zoom_level = 'fit'
self.assert_zoom_results(10, -0.5, 9.5, -0.5, 9.5, 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the off-center case, local testing showed that y_min and y_max was -5. , 5. instead of -0.5, 9.5 like X. Something not triggering here in the way I set up or hack around the viewer for unit testing. I swear to you it works properly in a notebook. If @astrofrog has ideas, then great. If not, I'll just leave this untested for the off-center case.

Copy link
Collaborator

@rosteen rosteen left a comment

Choose a reason for hiding this comment

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

Made one change request, although I haven't been part of the astrowidgets API discussion so maybe there was a reason for not making zoom have the input option I suggested there. Other than that I think this looks good - I don't have any insight into why your test cases are weird for Y, but it seems to be working as I would expect in the notebook.

"""
if not isinstance(val, (int, float)):
raise ValueError(f"zoom only accepts int or float but got '{val}'")
self.zoom_level = self.zoom_level * val
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is simply a method to set the zoom_level, it would would be nice to accept "fit" as input here as well as when setting zoom_level directly. That was one of the first things I tried and I was surprised that it didn't work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would go against the current astrowidgets API upstream though...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

zoom() was supposed to be relative zoom, so "fit" does not really fit (pun?) in that paradigm.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I see, that's the context I was missing, I guess. I didn't fully appreciate that zoom_level is setting the absolute zoom relative to the image, whereas zoom is setting the zoom relative to the current display.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't blame you. I didn't either until astropy/astrowidgets#144

Copy link
Collaborator

@rosteen rosteen left a comment

Choose a reason for hiding this comment

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

Approving this as "successfully implements the current Astrowidgets API". I can take any gripes with how that API works to astrowidgets directly...

@pllim
Copy link
Contributor Author

pllim commented Aug 2, 2021

Re: gripes -- Will be happy to get your feedback over at astropy/astrowidgets#142

@pllim
Copy link
Contributor Author

pllim commented Aug 2, 2021

I didn't hear any crying or objections during sprint review. Does that mean we can merge this?

@rosteen
Copy link
Collaborator

rosteen commented Aug 2, 2021

I think I consider a live demo with general approval as a second thumbs up. Merging.

@rosteen rosteen merged commit fbccc86 into spacetelescope:main Aug 2, 2021
@pllim pllim deleted the imviz-zoom-not-the-meeting branch August 2, 2021 17:15
@pllim pllim mentioned this pull request Jan 9, 2024
15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Explanation of code and concepts imviz Ready for final review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Imviz astrowidgets API MVP: zoom_level, zoom
4 participants