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

Bugfix: IndexError slicing Surface with higher-dimensional vertex_values #5635

Merged
merged 5 commits into from
Apr 3, 2023

Conversation

aganders3
Copy link
Contributor

Description

This fixes an off-by-one error on Surface layers extent data, which was causing an IndexError slicing that dimension.

Type of change

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

References

closes #5620
Disussed in community meeting on 2023-03-15

How has this been tested?

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.

@github-actions github-actions bot added the tests Something related to our tests label Mar 15, 2023
@psobolewskiPhD psobolewskiPhD added the bugfix PR with bugfix label Mar 15, 2023
@brisvag
Copy link
Contributor

brisvag commented Mar 15, 2023

Actually, one thing I haven't checked: how does it behave with higher dimensional vertex data, if at all?

@aganders3
Copy link
Contributor Author

The limits for the slider for the vertex data are calculated separately (just above this) and appended. So I think it just works? I have tested and it seemed okay to me but again I'm not too familiar with this code and want to make sure it is working as expected with multiple layers.

@codecov
Copy link

codecov bot commented Mar 15, 2023

Codecov Report

Merging #5635 (b5a7caf) into main (8a793b9) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #5635   +/-   ##
=======================================
  Coverage   89.85%   89.86%           
=======================================
  Files         611      611           
  Lines       51669    51669           
=======================================
+ Hits        46428    46432    +4     
+ Misses       5241     5237    -4     
Impacted Files Coverage Δ
napari/layers/surface/_tests/test_surface.py 100.00% <100.00%> (ø)
napari/layers/surface/surface.py 87.19% <100.00%> (ø)

... and 3 files with indirect coverage changes

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

@aganders3
Copy link
Contributor Author

Hmm - even on main I can't get a 4D Surface to behave as I thought it would. I'm going to convert this to draft while I play with that.

@aganders3 aganders3 marked this pull request as draft March 15, 2023 18:43
@aganders3 aganders3 marked this pull request as ready for review March 15, 2023 23:32
@aganders3
Copy link
Contributor Author

aganders3 commented Mar 15, 2023

Okay I spent some time and understand the extra dims on the vertices a bit more. I think this is ready for review.

Here's some sample code that will split a cow in half and assign (3, 3) random sets of vertex_values:

from vispy.io import imread, load_data_file, read_mesh

import numpy as np

mesh_path = load_data_file('spot/spot.obj.gz')
vertices, faces, *_ = read_mesh(mesh_path)

v = np.pad(vertices, ((0, 0), (2, 0)))
v[np.where(vertices[:, 0] < 0), 0] = 1
values = np.random.random((3, 3, len(v)))
viewer.add_surface((v, faces, values))

So in this screenshot slider 2 is the extra dim on the vertices, and sliders 1 and 0 are the extra dims on the values.
Screenshot 2023-03-15 at 7 34 21 PM

Edit: #4334 I think would be really useful here

Copy link
Contributor

@brisvag brisvag 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 to me then :) pity that black is doing one of its weird refactors :/

@aganders3
Copy link
Contributor Author

Yes I was tempted to reformat that, but oh well :/

@brisvag
Copy link
Contributor

brisvag commented Mar 29, 2023

Sorry @aganders3 , forgot about this one. Failures may be unrelated, but I'm not sure. Rerunning tests.

@psobolewskiPhD
Copy link
Member

This one (pyside6, 3.10 ubuntu)
https://github.com/napari/napari/actions/runs/4545923589/jobs/8027552735?pr=5635#step:8:270
is this issue: #5657
So unrelated. the other one is the random dims hang?

@brisvag
Copy link
Contributor

brisvag commented Mar 29, 2023

Thanks @psobolewskiPhD for checking; let's mark as ready to merge then :)

@brisvag brisvag added the ready to merge Last chance for comments! Will be merged in ~24h label Mar 29, 2023
@aganders3
Copy link
Contributor Author

Thanks to both of you for following up!

@brisvag brisvag merged commit 3bf7bd3 into napari:main Apr 3, 2023
@brisvag brisvag removed the ready to merge Last chance for comments! Will be merged in ~24h label Apr 3, 2023
kcpevey pushed a commit to kcpevey/napari that referenced this pull request Apr 6, 2023
…ues (napari#5635)

# Description
This fixes an off-by-one error on Surface layers extent data, which was
causing an IndexError slicing that dimension.

## Type of change
- [x] Bug-fix (non-breaking change which fixes an issue)

# References
closes napari#5620
Disussed in [community meeting on
2023-03-15](https://hackmd.io/BXWDZ3i8Q6OAEASrkaSNIQ?view#2023-03-15)

# How has this been tested?
- [x] all tests pass with my change (though I had to change two of them)
- [x] thanks to @brisvag who [tested to make sure the mesh was in the
correct spot wrt an
image](napari#5620 (comment))

## Final checklist:
- [x] My PR is the minimum possible work for the desired functionality
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] If I included new strings, I have used `trans.` to make them
localizable.
For more information see our [translations
guide](https://napari.org/developers/translations.html).

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@Czaki Czaki mentioned this pull request Jun 7, 2023
@psobolewskiPhD psobolewskiPhD added this to the 0.4.18 milestone Jun 8, 2023
@psobolewskiPhD psobolewskiPhD added the triaged-0.4.18 To mark PR that is triaged in 0.4.18 release process label Jun 8, 2023
Czaki pushed a commit that referenced this pull request Jun 19, 2023
…ues (#5635)

# Description
This fixes an off-by-one error on Surface layers extent data, which was
causing an IndexError slicing that dimension.

## Type of change
- [x] Bug-fix (non-breaking change which fixes an issue)

# References
closes #5620
Disussed in [community meeting on
2023-03-15](https://hackmd.io/BXWDZ3i8Q6OAEASrkaSNIQ?view#2023-03-15)

# How has this been tested?
- [x] all tests pass with my change (though I had to change two of them)
- [x] thanks to @brisvag who [tested to make sure the mesh was in the
correct spot wrt an
image](#5620 (comment))

## Final checklist:
- [x] My PR is the minimum possible work for the desired functionality
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] If I included new strings, I have used `trans.` to make them
localizable.
For more information see our [translations
guide](https://napari.org/developers/translations.html).

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Czaki pushed a commit that referenced this pull request Jun 21, 2023
…ues (#5635)

# Description
This fixes an off-by-one error on Surface layers extent data, which was
causing an IndexError slicing that dimension.

## Type of change
- [x] Bug-fix (non-breaking change which fixes an issue)

# References
closes #5620
Disussed in [community meeting on
2023-03-15](https://hackmd.io/BXWDZ3i8Q6OAEASrkaSNIQ?view#2023-03-15)

# How has this been tested?
- [x] all tests pass with my change (though I had to change two of them)
- [x] thanks to @brisvag who [tested to make sure the mesh was in the
correct spot wrt an
image](#5620 (comment))

## Final checklist:
- [x] My PR is the minimum possible work for the desired functionality
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] If I included new strings, I have used `trans.` to make them
localizable.
For more information see our [translations
guide](https://napari.org/developers/translations.html).

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Czaki pushed a commit that referenced this pull request Jun 21, 2023
…ues (#5635)

# Description
This fixes an off-by-one error on Surface layers extent data, which was
causing an IndexError slicing that dimension.

## Type of change
- [x] Bug-fix (non-breaking change which fixes an issue)

# References
closes #5620
Disussed in [community meeting on
2023-03-15](https://hackmd.io/BXWDZ3i8Q6OAEASrkaSNIQ?view#2023-03-15)

# How has this been tested?
- [x] all tests pass with my change (though I had to change two of them)
- [x] thanks to @brisvag who [tested to make sure the mesh was in the
correct spot wrt an
image](#5620 (comment))

## Final checklist:
- [x] My PR is the minimum possible work for the desired functionality
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] If I included new strings, I have used `trans.` to make them
localizable.
For more information see our [translations
guide](https://napari.org/developers/translations.html).

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Czaki pushed a commit that referenced this pull request Jun 21, 2023
…ues (#5635)

# Description
This fixes an off-by-one error on Surface layers extent data, which was
causing an IndexError slicing that dimension.

## Type of change
- [x] Bug-fix (non-breaking change which fixes an issue)

# References
closes #5620
Disussed in [community meeting on
2023-03-15](https://hackmd.io/BXWDZ3i8Q6OAEASrkaSNIQ?view#2023-03-15)

# How has this been tested?
- [x] all tests pass with my change (though I had to change two of them)
- [x] thanks to @brisvag who [tested to make sure the mesh was in the
correct spot wrt an
image](#5620 (comment))

## Final checklist:
- [x] My PR is the minimum possible work for the desired functionality
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] If I included new strings, I have used `trans.` to make them
localizable.
For more information see our [translations
guide](https://napari.org/developers/translations.html).

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix PR with bugfix tests Something related to our tests triaged-0.4.18 To mark PR that is triaged in 0.4.18 release process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IndexError slicing Surface with higher-dimensional vertex_values
3 participants