-
Notifications
You must be signed in to change notification settings - Fork 38
Add ImJoy demo plugin and badge #20
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
Changes from all commits
c8e9cfb
3ffd628
1ef84e2
2a1f96a
628f52f
9388403
c78d3d5
71022e0
73af6d3
ccaf061
2cb9e1f
7d94c26
0a6af38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,4 +14,4 @@ dependencies: | |
| - pip: | ||
| - imjoy>=0.10.0 | ||
| - imjoy-jupyter-extension | ||
| - imjoy-rpc | ||
| - imjoy-rpc>=0.2.11 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <docs lang="markdown"> | ||
| [TODO: write documentation for this plugin.] | ||
| </docs> | ||
|
|
||
| <config lang="json"> | ||
| { | ||
| "name": "VizarrDemo", | ||
| "type": "native-python", | ||
| "version": "0.1.0", | ||
| "description": "A demo plugin which uses Vizarr to visualize images", | ||
| "tags": [], | ||
| "ui": "", | ||
| "cover": "", | ||
| "inputs": null, | ||
| "outputs": null, | ||
| "flags": [], | ||
| "icon": "extension", | ||
| "api_version": "0.1.8", | ||
| "env": "", | ||
| "permissions": [], | ||
| "requirements": ["repo:https://github.com/hms-dbmi/vizarr.git", "conda: zarr scikit-image"], | ||
| "dependencies": [] | ||
| } | ||
| </config> | ||
|
|
||
| <script lang="python"> | ||
| import os | ||
| os.chdir('vizarr/example') | ||
|
|
||
| from imjoy import api | ||
| import zarr | ||
| from create_fixture import create_ome_zarr | ||
| import zarr | ||
|
|
||
| def encode_zarr_store(zobj): | ||
| path_prefix = f"{zobj.path}/" if zobj.path else "" | ||
|
|
||
| def getItem(key): | ||
| return zobj.store[path_prefix + key] | ||
|
|
||
| def setItem(key, value): | ||
| zobj.store[path_prefix + key] = value | ||
|
|
||
| def containsItem(key): | ||
| if path_prefix + key in zobj.store: | ||
| return True | ||
|
|
||
| return { | ||
| "_rintf": True, | ||
| "_rtype": "zarr-array" if isinstance(zobj, zarr.Array) else "zarr-group", | ||
| "getItem": getItem, | ||
| "setItem": setItem, | ||
| "containsItem": containsItem, | ||
| } | ||
|
|
||
|
|
||
| api.registerCodec( | ||
| {"name": "zarr-array", "type": zarr.Array, "encoder": encode_zarr_store} | ||
| ) | ||
| api.registerCodec( | ||
| {"name": "zarr-group", "type": zarr.Group, "encoder": encode_zarr_store} | ||
| ) | ||
|
|
||
|
|
||
| class Plugin: | ||
| async def setup(self): | ||
| pass | ||
|
|
||
| async def run(self, ctx): | ||
| create_ome_zarr("astronaut.zarr") # creates an example OME-Zarr in the current directory | ||
| multiscale_astronaut = zarr.open("astronaut.zarr", mode="r") # open the zarr created above in jupyter kernel | ||
|
|
||
| # Create Zarr | ||
| images = [ { "source": multiscale_astronaut, "name": "astronaut" } ] | ||
|
|
||
| viewer = await api.createWindow( | ||
| type="vizarr", src="https://hms-dbmi.github.io/vizarr" | ||
| ) | ||
| for img in images: | ||
| await viewer.add_image(img) | ||
|
|
||
| api.export(Plugin()) | ||
| </script> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ ipywidgets>=7.0.0 | |
| scikit-image | ||
| imjoy>=0.10.0 | ||
| fsspec | ||
| imjoy-rpc | ||
| imjoy-rpc>=0.2.11 | ||
| zarr | ||
| numba | ||
| requests | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { useRouter } from 'next/router'; | |
| import { useEffect } from 'react'; | ||
| import { useSetRecoilState } from 'recoil'; | ||
|
|
||
| import { version as vizarrVersion } from '../../package.json'; | ||
| import { layerIdsState, sourceInfoState, viewerViewState } from '../state'; | ||
|
|
||
| const Viewer = dynamic(() => import('../components/Viewer')); | ||
|
|
@@ -37,7 +38,11 @@ function App() { | |
| useEffect(() => { | ||
| async function initImjoy() { | ||
| const { setupRPC } = await import('imjoy-rpc'); | ||
| const api = await setupRPC({ name: 'viv-plugin' }); | ||
| const api = await setupRPC({ | ||
| name: 'vizarr', | ||
| description: 'A minimal, purely client-side program for viewing Zarr-based images with Viv & ImJoy', | ||
| version: vizarrVersion, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a side note, how do you version
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use netlify for that, it can build different sites for releases and PRs (example) as I mentioned in another PR. The setup is very easy, you basically connect the repo and fill in the a build command.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, could you test and see if you get the version work. For some reason,
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What isn't working exactly?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I change the create window src to http://127.0.0.1:3000, it doesn’t work.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works now, just tried it. please ignore this, sorry. |
||
| }); | ||
| const add_image = async (props) => addImage(props); | ||
| const set_view_state = async (vs) => setViewState(vs); | ||
| api.export({ add_image, set_view_state }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am changing the name to vizarr here to be consistent with the web app name.