8000 Bump to vispy 0.15 and update Colormap model by brisvag · Pull Request #7846 · napari/napari · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Bump to vispy 0.15 and update Colormap model #7846

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 28 commits into from
May 13, 2025
Merged

Conversation

brisvag
Copy link
Contributor
@brisvag brisvag commented Apr 22, 2025

Description

Bump vispy to the latest version. This brings in a few bugfixes and performance improvements, as well as some new features that will be usable in napari. Changelog: https://github.com/vispy/vispy/releases/tag/v0.15.0

Notable changes:

  • Colormaps now have 3 new parameters: bad_color, low_color and high_color. These allow to set respectively the mapping for NaN, values <=0 and values >= 1. This PR updates the napari Colormap objects to match (closes HiLO LUT #6878 by introducing a HiLo colormap, and also adds a bad colormap for NaN highlighting).
  • Gridlines have settable limits (allows Add grid overlay #7827).
  • some triangulation fixes and improvement

@brisvag brisvag requested a review from a team as a code owner April 22, 2025 15:15
@brisvag
Copy link
Contributor Author
brisvag commented Apr 22, 2025

@napari-bot update constraints

Copy link
Contributor

Updated packages: contourpy, debugpy, hypothesis, ipython, lxml-html-clean, napari-plugin-manager, numba, numcodecs, numpy, packaging, pillow, prompt-toolkit, pydantic, pyqt6, pyqt6-qt6, typing-extensions, urllib3, vispy, zarr

This workflow cannot automatically update your PR or create PR to your repository. But you could open such PR by clicking the link: brisvag/napari@vispy-0.15...napari-bot:auto-update-dependencies/brisvag/napari/vispy-0.15.

You could also get the updated files from the https://github.com/napari-bot/napari/tree/auto-update-dependencies/brisvag/napari/vispy-0.15/resources/constraints. Or ask the maintainers to provide you the contents of the constraints artifact from the run https://github.com/napari/napari/actions/runs/14598410732

@brisvag brisvag requested a review from melonora as a code owner April 25, 2025 10:16
@brisvag brisvag requested a review from kevinyamauchi as a code owner April 28, 2025 09:47
@github-actions github-actions bot added the tests Something related to our tests label Apr 28, 2025
Copy link
codecov bot commented Apr 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.94%. Comparing base (6cac059) to head (a195d54).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7846      +/-   ##
==========================================
+ Cove
8000
rage   92.92%   92.94%   +0.02%     
==========================================
  Files         641      641              
  Lines       60627    60660      +33     
==========================================
+ Hits        56335    56381      +46     
+ Misses       4292     4279      -13     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Czaki
Copy link
Collaborator
Czaki commented Apr 28, 2025

pyqt6 should be downgraded to 6.8.1. I still do not fix the problem with pyqt6==6.9.0 on CI.

@brisvag
Copy link
Contributor Author
brisvag commented Apr 29, 2025

Should I manually edit the constraints, or is this pin being added in some other PR?

@brisvag brisvag changed the title Bump to vispy 0.15 Bump to vispy 0.15 and update Colormap model Apr 29, 2025
@Czaki
Copy link
Collaborator
Czaki commented Apr 29, 2025

Manually edit. I may do this for you (just local edit of pyproject.toml and run script).

@brisvag
Copy link
Contributor Author
brisvag commented Apr 29, 2025

Manually edit. I may do this for you (just local edit of pyproject.toml and run script).

if you can, yes please!

Comment on lines 65 to 66
# some colormaps use BaseColormap and custom mapping functions instead of
# standard colors/controls, so they are broken in napari
Copy link
Member

Choose a reason for hiding this comment

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

Whoa, like what, and is that something we should support? Could be handy. 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really; basically, you can create a BaseColormap and define your own glsl function for it, which might be whatever crazy thing you want. However, it's not really easy to communicate between python and "stringy glsl", so I don't think it's a good idea.

jni pushed a commit that referenced this pull request May 9, 2025
# References and relevant issues
- fixes #7855

# Description
Some colormap from vispy are broken (see issue for explanation). This PR
simply removes them from the available colormaps.

Updating them in vispy is another option, but I think it's worse because
these colormaps have been in vispy a long time, and people might depend
on their quirks. Also, `hot` is provided by matplotlib and `grays` is
essentially a duplicate of matplotlib's `gray`, so we really only lose
`ice`.

Note that #7846 additionally introduces a `HiLo` colormap, which also
currently cannot be represented by our `Colormap` model. Support for
that will need to be added in that PR.
Comment on lines 161 to 166
'bad': Colormap(
name='bad',
display_name='bad',
colors=[[0.0, 0.0, 0.0, 1.0], [1.0, 1.0, 1.0, 1.0]],
bad_color=[1.0, 0.0, 0.0, 1.0],
),
Copy link
Member

Choose a reason for hiding this comment

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

LOL is this a common name for this colormap? Or do we want to call it nan also?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol nope, I just made it up, assuming I would get lots of comments about it :P Yeah, nan is also an option. I can imagine even more verbose, like highlight_nan

Copy link
Contributor Author

Choose a reason for hiding this comment

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

going for simply nan for now.

Copy link
Member
@jni jni left a comment

Choose a reason for hiding this comment

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

Oh nice, this is very small now! 😊 I've left some very small suggestions, but otherwise, let's get this in! HiLo ftw!!!

Co-authored-by: Juan Nunez-Iglesias <jni@fastmail.com>
@brisvag
Copy link
Contributor Author
9E81
brisvag commented May 9, 2025

If you change it, how about having the docstring also say something like equivalent to vispy/matplotlib bad_color

I put matplotlib as you suggested. Note that vispy's was literally added on this release, so it's hardly a standard :P

Comment on lines 126 to 129
cmap_args = self.layer.colormap.dict()
cmap_args.pop('name')
cmap_args['bad_color'] = cmap_args.pop('nan_color')
self.node.cmap = VispyColormap(**cmap_args)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer to add proper method to our Colormap for dict construction rather than doing this in vispy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method already exists (dict()). The problem here is that our Colormap and vispy's are diverging, and I think this is the right place to take care of this difference. Eemember we plan to have different backends, and the _vispy module is exactly where vispy-specific stuff should be.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Current code makes it harder to test it. We should be able to easy iterate over all napari color maps and check if it properly converts into Vispy one.
Without spawning viewer etc.

Copy link
Contributor Author
@brisvag brisvag May 9, 2025

Choose a reason for hiding this comment

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

I see what you mean; I unified them into a function that lives in the _vispy module, and is now also used by the surface layer.

In fact, we shuld probably move everything relating to vispy from napari.utils.colormaps to there... except some are technically public api 🤔

@jni
Copy link
Member
jni commented May 10, 2025

Looks like the headless failure is real — there's now some qt imports leaking into the non-Qt parts of the codebase.

@jni
Copy link
Member
jni commented May 10, 2025

I think it can be fixed by moving the new function from _vispy to the colormaps utils. I think that's where it should go anyway tbh.

@brisvag
Copy link
Contributor Author
brisvag commented May 12, 2025

I think it can be fixed by moving the new function from _vispy to the colormaps utils. I think that's where it should go anyway tbh.

I'm not convinced by this, we shouldn't have vispy code in non-vispy areas. But we can do that another time, I'll move to see if that fixes it.

@Czaki
Copy link
Collaborator
Czaki commented May 12, 2025

I agree with @brisvag. We need the same colormap for all backends.

@jni
Copy link
Member
jni commented May 12, 2025

we shouldn't have vispy code in non-vispy areas.

We need the same colormap for all backends.

My point is not opposed to that. Having to_<backend>_dict export/conversion functions from our colormaps still allows the same base colormap model which then can be converted to other backends, and doesn't need to import said backend.

ie I wouldn't have done:

return VispyColormap(**cmap_args)

but just

return cmap_args

and then in the calling functions change:

self.node.cmap = _napari_cmap_to_vispy(self.layer.colormap)

to

self.node.cmap = VispyColormap(
    **_napari_cmap_to_vispy(self.layer.colormap)
)

Having said that, everything is green now, so maybe we merge and refactor another time??? 🥳 🚀

The other thing is that there might be a longer-term solution such that we can run vispy tests in the headless code. But currently that doesn't seem to be the case.

@jni jni added ready to merge Last chance for comments! Will be merged in ~24h highlight PR that should be mentioned in next release notes labels May 12, 2025
@jni
Copy link
Member
jni commented May 12, 2025

(I also note that you didn't need to add an import for VispyColormap, so it was already used in that file?)

@brisvag
Copy link
Contributor Author
brisvag commented May 12, 2025

(I also note that you didn't need to add an import for VispyColormap, so it was already used in that file?)

yep, that's why I said

In fact, we shuld probably move everything relating to vispy from napari.utils.colormaps to there... except some are technically public api 🤔

@TimMonko TimMonko merged commit b2d1497 into napari:main May 13, 2025
45 checks passed
@github-actions github-actions bot removed the ready to merge Last chance for comments! Will be merged in ~24h label May 13, 2025
@TimMonko
Copy link
Contributor

Adding a gif and image here for release notes:

python_HfSbvYeurc

image

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 tests Something related to our tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HiLO LUT
5 participants