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

Distinguish between update_dims, extent changes, and refresh #5363

Merged
merged 6 commits into from Nov 30, 2022

Conversation

andy-sweet
Copy link
Member

@andy-sweet andy-sweet commented Nov 23, 2022

Description

This reduces the use of Layer._update_dims, which should only be used when the dimensionality of a layer (defined by the return value of Layer._get_ndim) changes. That can always happen in the data setter, but can also happen at other times in some layers.

It also introduces a simpler method (Layer._clear_extent) that can be used instead of _update_dims in many places. This method emits a new event (Layer.events.extent) that indicates a new value of the cached/derived property Layer.extent may be available (i.e. when the extent cache is cleared). This is used to clear the layer list extent cache instead of Layer.events.set_data, which I believe is intended to indicate the presence of a new slice (e.g. for vispy). This seems like a pretty solid pattern for a derived property like extent here.

Type of change

This is a refactor that attempts to clarify what Layer._update_dims does, when it should be used, and when it shouldn't.

References

This was motivated as part of the async slicing integration work in #5236 where these definitions become important.

How has this been tested?

  • all existing tests pass with my change

Final checklist:

  • My PR is the minimum possible work for the desired functionality
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • If I included new strings, I have used trans. to make them localizable.
    For more information see our translations guide.

@codecov
Copy link

codecov bot commented Nov 23, 2022

Codecov Report

Merging #5363 (f527b29) into main (1b1fb1b) will increase coverage by 1.47%.
The diff coverage is 95.65%.

@@            Coverage Diff             @@
##             main    #5363      +/-   ##
==========================================
+ Coverage   87.60%   89.08%   +1.47%     
==========================================
  Files         584      584              
  Lines       49533    49535       +2     
==========================================
+ Hits        43395    44126     +731     
+ Misses       6138     5409     -729     
Impacted Files Coverage Δ
napari/layers/surface/surface.py 86.62% <0.00%> (+1.07%) ⬆️
napari/layers/utils/_link_layers.py 96.84% <ø> (ø)
napari/components/layerlist.py 92.51% <100.00%> (ø)
napari/layers/base/base.py 91.56% <100.00%> (+0.04%) ⬆️
napari/layers/image/image.py 95.48% <100.00%> (+2.50%) ⬆️
napari/layers/labels/labels.py 95.38% <100.00%> (ø)
napari/layers/points/points.py 99.06% <100.00%> (ø)
napari/layers/shapes/shapes.py 91.19% <100.00%> (ø)
napari/layers/tracks/tracks.py 94.67% <100.00%> (+0.38%) ⬆️
napari/layers/vectors/vectors.py 97.95% <100.00%> (ø)
... and 51 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@andy-sweet
Copy link
Member Author

@Czaki : assigned you as a reviewer as you were last to change some of this code. I'm unsure if this refactor is a good idea, so feel free to push back if you don't!

@Czaki
Copy link
Collaborator

Czaki commented Nov 28, 2022

Looks ok. Is there any reason why it is WIP?

@andy-sweet
Copy link
Member Author

Looks ok. Is there any reason why it is WIP?

I was a little unsure if I liked it, so I didn't want it be merged accidentally. But looking at it again and with a little positive sentiment from you, I marked it as ready to review.

@andy-sweet andy-sweet marked this pull request as ready for review November 28, 2022 21:06
@andy-sweet andy-sweet changed the title [WIP] Distinguish between update_dims, extent changes, and refresh Distinguish between update_dims, extent changes, and refresh Nov 28, 2022
Comment on lines +726 to +727
if 'extent' in self.__dict__:
del self.extent
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this attribute treated so weirdly rather than being set to None or similar? Maybe out of scope, but I just noticed this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is how cached property works.
The whole mechanism is first to check if the name is defined in self.__dict__ and if no, then call the property and put the result in this dict.
None is the proper value, so it will not trigger a recalculation.

@andy-sweet
Copy link
Member Author

As this is a fairly small refactor/rename with some eyes on it and an approval, I'll merge this after 24 hours unless anyone objects.

@andy-sweet andy-sweet merged commit 6cd7f78 into napari:main Nov 30, 2022
@andy-sweet andy-sweet deleted the clean-update_dims branch November 30, 2022 17:00
@andy-sweet andy-sweet added this to the 0.5.0 milestone Dec 8, 2022
aganders3 pushed a commit to aganders3/napari that referenced this pull request Dec 20, 2022
…5363)

* Replace some usage of _update_dims with refresh

* Use extent event instead of set_data
melissawm pushed a commit to melissawm/napari that referenced this pull request Jan 11, 2023
…5363)

* Replace some usage of _update_dims with refresh

* Use extent event instead of set_data
@Czaki Czaki modified the milestones: 0.5.0, 0.4.18 Jun 18, 2023
@Czaki Czaki added the maintenance PR with maintance changes, label Jun 18, 2023
Czaki pushed a commit that referenced this pull request Jun 18, 2023
* Replace some usage of _update_dims with refresh

* Use extent event instead of set_data
@Czaki Czaki mentioned this pull request Jun 18, 2023
Czaki pushed a commit that referenced this pull request Jun 19, 2023
* Replace some usage of _update_dims with refresh

* Use extent event instead of set_data
Czaki pushed a commit that referenced this pull request Jun 21, 2023
* Replace some usage of _update_dims with refresh

* Use extent event instead of set_data
Czaki pushed a commit that referenced this pull request Jun 21, 2023
* Replace some usage of _update_dims with refresh

* Use extent event instead of set_data
Czaki pushed a commit that referenced this pull request Jun 21, 2023
* Replace some usage of _update_dims with refresh

* Use extent event instead of set_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance PR with maintance changes,
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants