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

expose zoom_to_selected in catalogs plugin api, fix default zoom level #3369

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

cshanahan1
Copy link
Contributor

@cshanahan1 cshanahan1 commented Dec 20, 2024

This PR exposes 'zoom_to_selected' in the catalogs plugin, and adds test coverage for this functionality.

This also fixes an issue where 'zoom_to_selected' was using a fixed default value of 50 pixels around the source(s), which is inappropriate for small images (including when wcs linked and the image is 10x10 pixels). The default is now to use 2% of the total image size around the bounding box containing the selected points, which felt like a good size in my testing. The 'padding' parameter, which refers to the fraction of the image size to use as the zoom level around sources, is now exposed in 'zoom_to_selected' as well so it can be adjusted if needed.

@github-actions github-actions bot added imviz plugin Label for plugins common to multiple configurations labels Dec 20, 2024
@cshanahan1 cshanahan1 added this to the 4.1 milestone Dec 20, 2024
Copy link

codecov bot commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 3 lines in your changes missing coverage. Please review.

Project coverage is 88.11%. Comparing base (a0d77f5) to head (7d0b728).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
jdaviz/configs/imviz/plugins/catalogs/catalogs.py 83.33% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3369      +/-   ##
==========================================
- Coverage   88.76%   88.11%   -0.65%     
==========================================
  Files         125      127       +2     
  Lines       19248    19543     +295     
==========================================
+ Hits        17086    17221     +135     
- Misses       2162     2322     +160     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cshanahan1 cshanahan1 changed the title expose zoom_to_selected in catalogs plugin api expose zoom_to_selected in catalogs plugin api, fix default zoom level Dec 20, 2024
@cshanahan1 cshanahan1 requested review from pllim and kecnry December 20, 2024 20:08
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.

Just a few small comments, otherwise looks good to me - thanks!

x = [float(coord['x_coord']) for coord in selected_rows]
y = [float(coord['y_coord']) for coord in selected_rows]

limits = viewer.state._get_reset_limits()
Copy link
Contributor

@gibsongreen gibsongreen Dec 20, 2024

Choose a reason for hiding this comment

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

What if the viewer and the image have different dimensions?

I was testing the default Imviz notebook and one case I noticed was the viewer limits were dependent on my browser instance and how I defined the width but the image keeps the same aspect ratio in the viewer when I resize the browser.

Screen.Recording.2024-12-20.at.4.31.48.PM.mov

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'm honestly not sure what the answer to this is

Copy link
Contributor

Choose a reason for hiding this comment

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

You can reproduce where this case causes and issue with the zoom with the following:

catalog = imviz.plugins['Catalog Search']._obj
catalog.open_in_tray()
catalog.catalog.selected = 'Gaia'
catalog.search()

catalog.table.selected_rows = catalog.table.items[:2]
catalog.zoom_to_selected()

Copy link
Member

Choose a reason for hiding this comment

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

Is the concern just about reproducibility? Or is it somehow failing to zoom to include all selected sources?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get the limits from the selected_rows instead of the viewer?

Copy link
Member

Choose a reason for hiding this comment

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

can you see what is being used as padding? And the output of viewer.state._get_reset_limits() (maybe this is a bug there)? My other idea is that this is just an issue with providing x/y limits as opposed to center and radius, since the rectangle of limits we pass is not exactly what ends up adopted.

Copy link
Member

Choose a reason for hiding this comment

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

I'd still say this is an improvement over the previous behavior and maybe we get it in as is so that its in for the demos and make a tech-debt ticket to make more general in the future? If we're worried, we can hide padding from the user API until then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok i was able to reproduce the issue, very weird.

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 would say this is still an improvement, because the same zoom scenario on main in the example doesn't work at all and the image is totally zoomed out. This is at least in the right area of the image now when it fails after resizing your browser window. We should look into what is happening though.

Copy link
Contributor

@gibsongreen gibsongreen Dec 20, 2024

Choose a reason for hiding this comment

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

After each step inside zoom_to_selected:
limits:
(-0.5, 4733.5, -0.5, 4718.5)
max_dim:
4734.0
padding:
94.68
before applying padding (x_min, x_max) (y_min, y_max)
2202.56701 2589.79442
2243.31321 2716.02305
after applying padding (x_min, x_max) (y_min, y_max)
2107.8870100000004 2684.47442
2148.63321 2810.7030499999996

After Zooming:

viewer.get_limits()
(2156.4823647015282, 2635.8790652984726, 2365.1348456839964, 2594.2014143160036)

viewer.state._get_reset_limits()
(-0.5, 4733.5, -0.5, 4718.5)

(x_1, x_2) (y_1, y_2) of sources:
(2202.56701,2589.79442) (2243.31321, 2716.02305)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
imviz plugin Label for plugins common to multiple configurations Ready for final review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants