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

Fix bug with not display points close to given layer #2289

Merged
merged 2 commits into from Feb 26, 2021

Conversation

Czaki
Copy link
Collaborator

@Czaki Czaki commented Feb 19, 2021

Description

Partially solve a problem described in #2288 which comes from float == comparison

Type of change

  • Bug-fix (non-breaking change which fixes an issue)

References

How has this been tested?

  • example: the test suite for my feature covers cases x, y, and z
  • example: all tests pass with my change

Comment on lines 1519 to 1520
distance = np.abs(data - indices[not_disp])
matches = np.all(distance < 1e-5, axis=1)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I chose tolerance by random. I think that 10^(-5) ok, but I'm open.

Copy link
Contributor

Choose a reason for hiding this comment

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

you could use https://numpy.org/doc/stable/reference/generated/numpy.allclose.html instead which has a default tolerance of 10^-8. Probably will be faster as i suspect they return as soon as they find something not close

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As i check allclose documentation thereis no axis argumen and allclose return single boolean operator.

I think that you mean isclose, but isclose need to allocate arrays of size equal to points, because here right value is single row.

This is why i use a manual way of comparision.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah ok, that's fair. not sure if @jni knows an alternative approach, otherwise your approach is fine

@codecov
Copy link

codecov bot commented Feb 19, 2021

Codecov Report

Merging #2289 (35de85c) into master (d588f45) will increase coverage by 0.29%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2289      +/-   ##
==========================================
+ Coverage   67.02%   67.32%   +0.29%     
==========================================
  Files         402      408       +6     
  Lines       33760    34057     +297     
==========================================
+ Hits        22629    22929     +300     
+ Misses      11131    11128       -3     
Impacted Files Coverage Δ
napari/layers/points/_tests/test_points.py 100.00% <100.00%> (ø)
napari/layers/points/points.py 78.79% <100.00%> (+0.02%) ⬆️
.../_vendor/experimental/cachetools/cachetools/abc.py 41.93% <0.00%> (-2.07%) ⬇️
napari/utils/events/containers/_typed.py 58.16% <0.00%> (-0.60%) ⬇️
napari/utils/events/__init__.py 0.00% <0.00%> (ø)
napari/utils/colormaps/vendored/colors.py 0.00% <0.00%> (ø)
napari/utils/events/containers/__init__.py 0.00% <0.00%> (ø)
...ari/_vispy/experimental/vispy_tiled_image_layer.py 0.00% <0.00%> (ø)
napari/utils/tree/_tests/test_tree_model.py 100.00% <0.00%> (ø)
napari/utils/tree/group.py 100.00% <0.00%> (ø)
... and 20 more

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 d588f45...35de85c. Read the comment docs.

Copy link
Contributor

@sofroniewn sofroniewn left a comment

Choose a reason for hiding this comment

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

Change, looks good, I suggested using a builtin numpy function instead.

Can you look to see if we have a similar line of code in the shapes and vectors layer which should not use == too.

Also do you mind adding a test, then I think this will be good to go! Thanks for the quick fix

@sofroniewn sofroniewn added this to the 0.4.6 milestone Feb 19, 2021
@sofroniewn sofroniewn added the bug Something isn't working label Feb 19, 2021
@jni
Copy link
Member

jni commented Feb 19, 2021

I think this implementation is fine for now. (eventually we'll want to do something more clever like cKDTree, but that's an existing problem.) @Czaki could you add a test with the failure that motivated this PR?

@Czaki
Copy link
Collaborator Author

Czaki commented Feb 19, 2021

@Czaki could you add a test with the failure that motivated this PR?

I will do this tomorrow

fix name of variable
@Czaki
Copy link
Collaborator Author

Czaki commented Feb 21, 2021

One strong disclaimer. n current napari implementation the slider step is calculated basing only on scale parameters. This causes that event with this PR point with z coordinate 10.1 will not be displayed on any layer in 2D view.

I see two solutions:

  1. Use np.round
  2. Modify Points to calculate the real step base also on data coordinates. This may produce thousands of steps in slider.

Copy link
Contributor

@sofroniewn sofroniewn left a comment

Choose a reason for hiding this comment

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

Let's go with this now as it does fix a bug, but agreed, we likely still have more work to do to improve this. Thanks for the contribution @Czaki!

@sofroniewn sofroniewn merged commit a2e826b into napari:master Feb 26, 2021
@Czaki Czaki deleted the bugfix/points_visibility branch June 7, 2023 11:12
Czaki added a commit that referenced this pull request Feb 5, 2024
…dinates (#6629)

# References and relevant issues

This PR is created as result of debug
#6627 (comment)
As 0.4.19 branch has fewer problems than #6628 is created for 0.4.19. 

# Description

Fix logic for selecting of visible shapes based on idea from #2289. It
is lucky that we do not hit this earlier.

Removes scaling of width of markers border (this is same like in #6628)

To improve readability, this update `ShapesVisual` to have named
subvisuals.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants