Last active
December 28, 2020 19:31
-
-
Save mkitti/2f7c5fc3d3f8b0d15dd13f6d67b0e73d to your computer and use it in GitHub Desktop.
Invoking Napari from Julia Language 1.3.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
napari.jl | |
Test using PyCall.jl to invoke Napari ( http://github.com/napari ) from | |
the Julia language ( https://julialang.org/ ) 1.3.1 | |
Mark Kittisopikul | |
January 29th, 2020 | |
""" | |
using PyCall | |
pygui_start(:qt5) | |
# needed to kickstart Qt5 for some reason | |
qapp_obj = pyimport("qtpy.QtWidgets").QApplication([""]) | |
napari = pyimport("napari") | |
skimagedata = pyimport("skimage.data") | |
astronaut = skimagedata.astronaut(); | |
# Modified 2020/09/14 to add name keyword argument | |
# https://github.com/napari/napari/issues/1630 | |
napari.view_image(astronaut, name="astronaut") | |
using Images, TestImages | |
hela = testimage("hela-cells.tif"); | |
hela = imadjustintensity(hela); | |
hela = channelview(hela); | |
hela = PermutedDimsArray(hela,(2,3,1)); | |
#napari cannot handle UInt16 ?? Maybe QT issue | |
#hela = reinterpret(UInt16,hela); | |
napari.view_image(collect(Float32.(hela))) | |
mandrill = testimage("mandrill.tif"); | |
mandrill = channelview(mandrill); | |
mandrill = reinterpret(UInt8,mandrill); | |
mandrill = PermutedDimsArray(mandrill,(2,3,1)); | |
napari.view_image(collect(mandrill)); | |
if !isinteractive() | |
qapp_obj.exec() | |
end |
Yeah, I guess PyCall.jl is still the best option atm.
If I can help you, just reach out. I'm not experienced in shipping PyCall based packages but maybe I can support adding edge cases which crash.
It would be also cool if it's possible to run Napari in different threads or to prevent that they crash the whole Pluto session.
I haven't forgotten about this. Just a bit busy at the moment.
If you are interested in a full blown Julia package, check out the early preview of Napari.jl: https://github.com/mkitti/Napari.jl
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A Napari.jl package would still depend on PyCall.jl to do the heavy lifting. The other route that could be considered would be using https://zeromq.org/
Some of the issues are Napari bugs due to unexpected input from Julia. Some are PyCall issues. The intent of a Napari.jl package would be to try to save the user from some of those gotchas by normalizing the data.
The Gtk threading issues are unfortunate. There might be a way to pin tasks to threads though, which might resolve some of the issues:
https://julialang.zulipchat.com/#narrow/stream/225542-helpdesk/topic/confused.20by.20how.20threads.20are.20scheduled/near/217623767
JuliaLang/julia#34267 (comment)
I have motivation to roll out a v0.0.1 Napari.jl package this week due to the I2K conference.