Skip to content

Commit 83f01d8

Browse files
authored
Add ImJoy demo plugin and badge (#20)
* Add description and version number * improve readability in imjoy_plugin via api.init * bump imjoy-rpc version * recover imjoy_plugin * bump imjoy-rpc version * Fix plugin name * Add ImJoy demo plugin and badge * Simplify vizarr demo * set workspace to vizarr * Fix plugin name * Add readme * rename type
1 parent 73a9fb6 commit 83f01d8

9 files changed

+99
-6
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# vizarr
22
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/hms-dbmi/vizarr/master?filepath=example%2Fgetting_started.ipynb)
3+
[![launch ImJoy](https://imjoy.io/static/badge/launch-imjoy-badge.svg)](https://imjoy.io/#/app?workspace=vizarr&plugin=https://github.com/hms-dbmi/vizarr/blob/master/example/VizarrDemo.imjoy.html)
34

45
![Multiscale OME-Zarr in Jupyter Notebook with Vizarr](/screenshot.png)
56

binder/environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ dependencies:
1414
- pip:
1515
- imjoy>=0.10.0
1616
- imjoy-jupyter-extension
17-
- imjoy-rpc
17+
- imjoy-rpc>=0.2.11

example/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@ This notebook a contains a `vizarr` example visualizing a generic multiscale Zar
3333
$ jupyter notebook mandelbrot.ipynb
3434
```
3535

36+
## Display an Image in an ImJoy Plugin [![launch ImJoy](https://imjoy.io/static/badge/launch-imjoy-badge.svg)](https://imjoy.io/#/app?workspace=vizarr&plugin=https://github.com/hms-dbmi/vizarr/blob/master/example/VizarrDemo.imjoy.html)
37+
38+
This [demo plugin](VizarrDemo.imjoy.html) shows how to build an image visualization plugin with `vizarr` in [ImJoy](https://imjoy.io).
39+
3640

example/VizarrDemo.imjoy.html

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<docs lang="markdown">
2+
[TODO: write documentation for this plugin.]
3+
</docs>
4+
5+
<config lang="json">
6+
{
7+
"name": "VizarrDemo",
8+
"type": "native-python",
9+
"version": "0.1.0",
10+
"description": "A demo plugin which uses Vizarr to visualize images",
11+
"tags": [],
12+
"ui": "",
13+
"cover": "",
14+
"inputs": null,
15+
"outputs": null,
16+
"flags": [],
17+
"icon": "extension",
18+
"api_version": "0.1.8",
19+
"env": "",
20+
"permissions": [],
21+
"requirements": ["repo:https://github.com/hms-dbmi/vizarr.git", "conda: zarr scikit-image"],
22+
"dependencies": []
23+
}
24+
</config>
25+
26+
<script lang="python">
27+
import os
28+
os.chdir('vizarr/example')
29+
30+
from imjoy import api
31+
import zarr
32+
from create_fixture import create_ome_zarr
33+
import zarr
34+
35+
def encode_zarr_store(zobj):
36+
path_prefix = f"{zobj.path}/" if zobj.path else ""
37+
38+
def getItem(key):
39+
return zobj.store[path_prefix + key]
40+
41+
def setItem(key, value):
42+
zobj.store[path_prefix + key] = value
43+
44+
def containsItem(key):
45+
if path_prefix + key in zobj.store:
46+
return True
47+
48+
return {
49+
"_rintf": True,
50+
"_rtype": "zarr-array" if isinstance(zobj, zarr.Array) else "zarr-group",
51+
"getItem": getItem,
52+
"setItem": setItem,
53+
"containsItem": containsItem,
54+
}
55+
56+
57+
api.registerCodec(
58+
{"name": "zarr-array", "type": zarr.Array, "encoder": encode_zarr_store}
59+
)
60+
api.registerCodec(
61+
{"name": "zarr-group", "type": zarr.Group, "encoder": encode_zarr_store}
62+
)
63+
64+
65+
class Plugin:
66+
async def setup(self):
67+
pass
68+
69+
async def run(self, ctx):
70+
create_ome_zarr("astronaut.zarr") # creates an example OME-Zarr in the current directory
71+
multiscale_astronaut = zarr.open("astronaut.zarr", mode="r") # open the zarr created above in jupyter kernel
72+
73+
# Create Zarr
74+
images = [ { "source": multiscale_astronaut, "name": "astronaut" } ]
75+
76+
viewer = await api.createWindow(
77+
type="vizarr", src="https://hms-dbmi.github.io/vizarr"
78+
)
79+
for img in images:
80+
await viewer.add_image(img)
81+
82+
api.export(Plugin())
83+
</script>

example/imjoy_plugin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async def setup(self):
4444

4545
async def run(self, ctx):
4646
viewer = await api.createWindow(
47-
type="viv-plugin", src="https://hms-dbmi.github.io/vizarr"
47+
type="vizarr", src="https://hms-dbmi.github.io/vizarr"
4848
)
4949
if self.view_state:
5050
await viewer.set_view_state(self.view_state)

example/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ipywidgets>=7.0.0
33
scikit-image
44
imjoy>=0.10.0
55
fsspec
6-
imjoy-rpc
6+
imjoy-rpc>=0.2.11
77
zarr
88
numba
99
requests

multimodal_registration_vizarr.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@
673673
"\n",
674674
" async def run(self, ctx):\n",
675675
" viewer = await api.createWindow(\n",
676-
" type=\"viv-plugin\",\n",
676+
" type=\"vizarr\",\n",
677677
" src=\"https://hms-dbmi.github.io/vizarr/\"\n",
678678
" )\n",
679679
" for img in self.images:\n",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"@material-ui/core": "^4.11.0",
88
"@material-ui/icons": "^4.9.1",
99
"deck.gl": "^8.2.4",
10-
"imjoy-rpc": "^0.2.19",
10+
"imjoy-rpc": "^0.2.22",
1111
"next": "^9.5.1",
1212
"react": "^16.13.1",
1313
"react-dom": "^16.13.1",

src/pages/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useRouter } from 'next/router';
33
import { useEffect } from 'react';
44
import { useSetRecoilState } from 'recoil';
55

6+
import { version as vizarrVersion } from '../../package.json';
67
import { layerIdsState, sourceInfoState, viewerViewState } from '../state';
78

89
const Viewer = dynamic(() => import('../components/Viewer'));
@@ -37,7 +38,11 @@ function App() {
3738
useEffect(() => {
3839
async function initImjoy() {
3940
const { setupRPC } = await import('imjoy-rpc');
40-
const api = await setupRPC({ name: 'viv-plugin' });
41+
const api = await setupRPC({
42+
name: 'vizarr',
43+
description: 'A minimal, purely client-side program for viewing Zarr-based images with Viv & ImJoy',
44+
version: vizarrVersion,
45+
});
4146
const add_image = async (props) => addImage(props);
4247
const set_view_state = async (vs) => setViewState(vs);
4348
api.export({ add_image, set_view_state });

0 commit comments

Comments
 (0)