8000 Add Grid Mode Spacing to change distance between layers by TimMonko · Pull Request #7597 · napari/napari · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add Grid Mode Spacing to change distance between layers #7597

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

Merged
merged 15 commits into from
Feb 16, 2025

Conversation

TimMonko
Copy link
Contributor
@TimMonko TimMonko commented Feb 11, 2025

References and relevant issues

#7587 includes the desire for the ability to add spacing between layers in Grid mode. At the Feb 5/6 meeting, we discussed adding this ability, and frequent grid mode proponents @DragaDoncila and @psobolewskiPhD may be especially interested in this PR. This spacing especially helps quick export of figures, and no longer having to precisely crop panels 😄

Description

python_kcX7tXeNAw

  1. Adds proportional spacing between layers in grid mode. Distance is calculated as the average of the horizontal and vertical layer extent during the creation of the subplot. float between [-1, 1]. By using the float value the user is less likely to confuse a larger % value (like 80) as pixels vs percent
  2. Accounts for spacing in viewer.reset_view() to properly center camera
  3. Adds spacing value to Grid GUI widget. Inherits preference value initially. Step size is 0.05 (aka 5%).
  4. Adds spacing value, by default 0, to preferences. Personally, I'm going to set this to 0.1, because I really enjoy the breathing room between layers. I propose to also make this the default value, but that would greatly change things for people!
  5. Adds custom type confloat from pydantic that accepts step size. This is then used to allow a 0.05 step size value for the preferences widget. Type usable for future float widgets!
  6. Adds tests to ensure GridCanvas properly set up and that the spacing of the layers is properly calculated (in test_viewer_model)

Notes:

  • I don't see a place where viewer.reset_view() is tested, which would be good to ensure camera centering is correct. I have validated by hand that it works AND it works properly with viewer.export_figure(), so does not break anything as far as I can tell
  • Currently, allows setting a negative spacing value, which would result in overlap. I think this could be useful in some circumstances, but it may also make sense to set the spacing values as [0,1]. One use case I can think of is display the same image with a variety of convolutions, that is like 20 different layers, and have them be much closer in space to compare the overlaps, especially if grid stride one and blending is translucent
  • Fixed with custom confloat typeThe preference setting jumps by 1.0 increments, I would prefer also to have the 0.05 step size as used by the GUI widget, but can't figure out how to do this (only validating, not stepping)
  • Added, for the first time, .. versionadded:: to a docstring in the napari repo lol. It does seem to apply, but no one has previously used it. We will find out if docs build it nicely on release. I don't know if this applies in the Final Checklist - I don't see this in code docstrings, so is it just changed in napari/docs? I thought the api docs were auto created:
    • If an API has been modified, I have added a .. versionadded:: or .. versionchanged::
      directive to the appropriate docstring (For more information see
      the Sphinx documentation).

@github-actions github-actions bot added tests Something related to our tests qt Relates to qt preferences labels Feb 11, 2025
Copy link
codecov bot commented Feb 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.84%. Comparing base (aafd25e) to head (fb668a1).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7597      +/-   ##
==========================================
- Coverage   92.87%   92.84%   -0.04%     
==========================================
  Files         629      629              
  Lines       58839    58898      +59     
==========================================
+ Hits        54649    54685      +36     
- Misses       4190     4213      +23     

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

Copy link
Collaborator
@Czaki Czaki left a comment

Choose a reason for hiding this comment

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

looks good for me

@Czaki Czaki added this to the 0.6.0 milestone Feb 11, 2025
@Czaki Czaki added the feature New feature or request label Feb 11, 2025
@psobolewskiPhD
Copy link
Member
@psobolewskiPhD psobolewskiPhD left a comment

Choose a reason for hiding this comment

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

As noted in my comment, I think getting the Preferences step size to work is important.
I can't make a suggestion or PR to the fork 😢

@TimMonko
Copy link
Contributor Author

@psobolewskiPhD thanks for the review and suggestion -- very helpful!

I'm guessing you are normally able to submit PRs to forks? I'll check through my settings, but I don't ever remember changing anything.

@psobolewskiPhD
Copy link
Member
psobolewskiPhD commented Feb 12, 2025

A fork is just a repo with branches so should be able to open PRs on it.
Maybe I messed something up on my end.

(Note: i can't suggest the change here in review because that part (in fact the whole file) isn't touched.)

Edit: what's weird is when in the Open PR page I do compare across forks, I don't see @Czaki either, when I know I've made a PR to his fork before. So could be something else a-foot.

@TimMonko
Copy link
Contributor Author

@psobolewskiPhD @Czaki I made a pretty big change. It's stretching my knowledge a bit, so make sure I set up all the custom classes and inheritances correctly.

  1. Added a custom confloat type with a custom step size
  2. Used this custom step size in the create widget form, to add singleStep to the custom DoubleSpinBoxes

My goal was to make this extensible in the future, and propagate changes into other parts (like using for the grid_spacing widget button) and allow any future floats in the schema to specify step size.

Copy link
Member
@psobolewskiPhD psobolewskiPhD left a comment

Choose a reason for hiding this comment

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

I like this a lot!
Both the functionality and implementation.
Your way of handling the step size in Preferences is much better than what I suggested.

Comment on lines 406 to 410
# total spacing accounts for the distance between layers, results in 0 if not grid mode (grid_size = [1, 1] - 1)
total_spacing = np.multiply(
scene_size, self.grid.spacing * (np.array(grid_size) - 1)
)
size = np.multiply(scene_size, grid_size) + total_spacing
Copy link
Member

Choose a reason for hiding this comment

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

Noted in the community meeting:
Currently if you have a non-square layer, you will get uneven spacing between the layers.
Probably best to have a consistent "border" zone computed from just one of the dimensions -- the smallest?

@TimMonko
Copy link
Contributor Author
TimMonko commented Feb 13, 2025

At the community meeting today, we discussed how the spacing was not the same in both the horizontal and vertical dimension, as shown with the top image, and an identical adjustment should be made. @Czaki and @psobolewskiPhD I think this is ready for review. I only minimally updated the tooltip in settings, I could add the equivalent info that shows in the Grid widget, but then think we should move all that to appearance settings? This now uses the average of the layer size to calculate, to produce symmetrical spacing.

With a 16:9 aspect ratio (common for microscope cameras), I think a case can be made for any of the calculations. However, once the aspect ratio becomes even less symmetrical (like 32:9, as would be a 2x1 tiled image), I think the most intuitive starts to become the average difference. Regardless, if a user is working with an unusual aspect ratio, this spacing is modifiable. However, this does mean values of 1 won't move the 1x the extent anymore, but rather the average, again, I think this is fine because who would actually want their images that far apart?

16 x 9 Aspect Ratio

Before (uneven), 0.1:
image

This commit, Average, 0.1:
image

32 x 9 Aspect Ratio

Mean, 0.1:
image

Min, 0.1:
image

Optical Illusion

Just for fun, clearly an optical illusion ... the distance between the layers does not appear symmetrical, but I can assure you that it is!

image

@jni jni added the highlight PR that should be mentioned in next release notes label Feb 13, 2025
@willingc
Copy link
Collaborator

Folks, what is the next step on this PR? 1) Review and merge as is. or 2) Add more functionality and then review?

@Czaki
Copy link
Collaborator
Czaki commented Feb 13, 2025

Folks, what is the next step on this PR? 1) Review and merge as is. or 2) Add more functionality and then review?

review and merge

Copy link
Collaborator
@Czaki Czaki left a comment

Choose a reason for hiding this comment

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

For me, it is good to go. I prefer to solve blending problem in separate PR.

@psobolewskiPhD psobolewskiPhD added the ready to merge Last chance for comments! Will be merged in ~24h label Feb 15, 2025
@psobolewskiPhD
Copy link
Member

I updated the doc string to reflect the averaging of the height and width and marked as ready to merge!
@TimMonko if you get a chance, can you update the first post, PR description? It's used as the commit message. Otherwise, whoever merges: please update it!

@TimMonko
Copy link
Contributor Author

I updated the doc string to reflect the averaging of the height and width and marked as ready to merge!
Looks great! Thanks!

@TimMonko if you get a chance, can you update the first post, PR description? It's used as the commit message. Otherwise, whoever merges: please update it!

Can you describe this a bit more?
Just all the text in the first post is stuck into the commit, or a certain part?

@psobolewskiPhD
Copy link
Member

@TimMonko by default the whole PR description (the opening post). So we like those to be updated to reflect the final state of the PR. So some of those questions/issues that have been addressed can be removed.
The merger can edit it of course, but it's nice if the contributor gets to describe their own work!

@willingc
Copy link
Collaborator

Question @psobolewskiPhD: I like adding a paragraph at the top of the first post with a description of the final PR (perhaps with a horizontal line underneath as the divider). Do napari folks typically delete historical data from the first post?

@psobolewskiPhD
Copy link
Member

@willingc i think it varies, but at the end of the day we like the commit message to give a description of what was merged. One thing I think is helpful is to indicate/remove any TODO/issues that have actually been done. They can give some future contributor the wrong picture.

@TimMonko
Copy link
Contributor Author

Updated PR description. Thanks for all the help!

@jni jni merged commit 9891e00 into napari:main Feb 16, 2025
37 checks passed
@github-actions github-actions bot removed the ready to merge Last chance for comments! Will be merged in ~24h label Feb 16, 2025
@jni
Copy link
Member
jni commented Feb 16, 2025

I like adding a paragraph at the top of the first post with a description of the final PR (perhaps with a horizontal line underneath as the divider). Do napari folks typically delete historical data from the first post?

This is a good point, I do think many times we have deleted the earlier post, and it's potentially confusing, if one wants to revisit the whole conversation. Definitely something to discuss and document in our review guidelines. I would probably support moving to maintaining an "initial PR description" section under the edits that is considered immutable.

jni pushed a commit to napari/docs that referenced this pull request Feb 18, 2025
# References and relevant issues
Depends on napari/napari#7597
Part of #568

# Description
Updates the copy in the viewer tutorial to mention the new spacing
parameter.

---------

Co-authored-by: TimMonko <47310455+TimMonko@users.noreply.github.com>
Co-authored-by: Melissa Weber Mendonça <melissawm@gmail.com>
@imagesc-bot
Copy link

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/napari-0-6-0-released/112147/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request highlight PR that should be mentioned in next release notes preferences qt Relates to qt tests Something related to our tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0