From c8e9cfb071522594dd654f24c04be65c11a43632 Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Fri, 14 Aug 2020 02:36:53 +0200 Subject: [PATCH 01/12] Add description and version number --- src/pages/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pages/index.js b/src/pages/index.js index 92261df1..6958a70f 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -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, + }); const add_image = async (props) => addImage(props); const set_view_state = async (vs) => setViewState(vs); api.export({ add_image, set_view_state }); From 3ffd628bf8f8eead58c953c44847c068d76b3aee Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Fri, 14 Aug 2020 02:40:51 +0200 Subject: [PATCH 02/12] improve readability in imjoy_plugin via api.init --- binder/environment.yml | 2 +- example/imjoy_plugin.py | 31 +++++++++++++------------------ example/requirements.txt | 2 +- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/binder/environment.yml b/binder/environment.yml index 2a257316..a5d13072 100644 --- a/binder/environment.yml +++ b/binder/environment.yml @@ -14,4 +14,4 @@ dependencies: - pip: - imjoy>=0.10.0 - imjoy-jupyter-extension - - imjoy-rpc + - imjoy-rpc>=0.2.9 diff --git a/example/imjoy_plugin.py b/example/imjoy_plugin.py index 5f984878..3d5281b2 100644 --- a/example/imjoy_plugin.py +++ b/example/imjoy_plugin.py @@ -1,3 +1,4 @@ +import asyncio from imjoy import api import zarr @@ -23,6 +24,7 @@ def containsItem(key): "containsItem": containsItem, } +api.init() api.registerCodec( {"name": "zarr-array", "type": zarr.Array, "encoder": encode_zarr_store} @@ -32,25 +34,18 @@ def containsItem(key): ) -class Plugin: - def __init__(self, images, view_state=None): - if not isinstance(images, list): - images = [images] - self.images = images - self.view_state = view_state - async def setup(self): - pass - - async def run(self, ctx): - viewer = await api.createWindow( - type="viv-plugin", src="https://hms-dbmi.github.io/vizarr" - ) - if self.view_state: - await viewer.set_view_state(self.view_state) - for img in self.images: - await viewer.add_image(img) +async def run_vizarr_async(images, view_state=None): + if not isinstance(images, list): + images = [images] + viewer = await api.createWindow( + type="vizarr", src="https://hms-dbmi.github.io/vizarr" + ) + if view_state: + await viewer.set_view_state(view_state) + for img in images: + await viewer.add_image(img) def run_vizarr(images, view_state=None): - api.export(Plugin(images, view_state)) + asyncio.ensure_future(run_vizarr_async(images, view_state)) diff --git a/example/requirements.txt b/example/requirements.txt index d5aa8b5c..e30a0602 100644 --- a/example/requirements.txt +++ b/example/requirements.txt @@ -3,7 +3,7 @@ ipywidgets>=7.0.0 scikit-image imjoy>=0.10.0 fsspec -imjoy-rpc +imjoy-rpc>=0.2.9 zarr numba requests From 1ef84e23f03f00e5fe6757ce4c0162391e28e942 Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Fri, 14 Aug 2020 03:39:31 +0200 Subject: [PATCH 03/12] bump imjoy-rpc version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ad42265..05276873 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "@material-ui/core": "^4.11.0", "@material-ui/icons": "^4.9.1", "deck.gl": "^8.2.4", - "imjoy-rpc": "^0.2.19", + "imjoy-rpc": "^0.2.20", "next": "^9.5.1", "react": "^16.13.1", "react-dom": "^16.13.1", From 2a1f96a8963e07fd75e313a980157f9adb34f5f1 Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Fri, 14 Aug 2020 04:36:28 +0200 Subject: [PATCH 04/12] recover imjoy_plugin --- example/imjoy_plugin.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/example/imjoy_plugin.py b/example/imjoy_plugin.py index 3d5281b2..0e916de6 100644 --- a/example/imjoy_plugin.py +++ b/example/imjoy_plugin.py @@ -1,4 +1,3 @@ -import asyncio from imjoy import api import zarr @@ -24,7 +23,6 @@ def containsItem(key): "containsItem": containsItem, } -api.init() api.registerCodec( {"name": "zarr-array", "type": zarr.Array, "encoder": encode_zarr_store} @@ -34,18 +32,25 @@ def containsItem(key): ) +class Plugin: + def __init__(self, images, view_state=None): + if not isinstance(images, list): + images = [images] + self.images = images + self.view_state = view_state -async def run_vizarr_async(images, view_state=None): - if not isinstance(images, list): - images = [images] - viewer = await api.createWindow( - type="vizarr", src="https://hms-dbmi.github.io/vizarr" - ) - if view_state: - await viewer.set_view_state(view_state) - for img in images: - await viewer.add_image(img) + async def setup(self): + pass + + async def run(self, ctx): + viewer = await api.createWindow( + type="viv-plugin", src="https://hms-dbmi.github.io/vizarr" + ) + if self.view_state: + await viewer.set_view_state(self.view_state) + for img in self.images: + await viewer.add_image(img) def run_vizarr(images, view_state=None): - asyncio.ensure_future(run_vizarr_async(images, view_state)) + api.export(Plugin(images, view_state)) \ No newline at end of file From 628f52f55e314b5b5753d27bfb0c750e2e7bd1af Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Fri, 14 Aug 2020 04:44:10 +0200 Subject: [PATCH 05/12] bump imjoy-rpc version --- binder/environment.yml | 2 +- example/requirements.txt | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/binder/environment.yml b/binder/environment.yml index a5d13072..62640a8d 100644 --- a/binder/environment.yml +++ b/binder/environment.yml @@ -14,4 +14,4 @@ dependencies: - pip: - imjoy>=0.10.0 - imjoy-jupyter-extension - - imjoy-rpc>=0.2.9 + - imjoy-rpc>=0.2.11 diff --git a/example/requirements.txt b/example/requirements.txt index e30a0602..99cb4413 100644 --- a/example/requirements.txt +++ b/example/requirements.txt @@ -3,7 +3,7 @@ ipywidgets>=7.0.0 scikit-image imjoy>=0.10.0 fsspec -imjoy-rpc>=0.2.9 +imjoy-rpc>=0.2.11 zarr numba requests diff --git a/package.json b/package.json index 05276873..5cd903ba 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "@material-ui/core": "^4.11.0", "@material-ui/icons": "^4.9.1", "deck.gl": "^8.2.4", - "imjoy-rpc": "^0.2.20", + "imjoy-rpc": "^0.2.22", "next": "^9.5.1", "react": "^16.13.1", "react-dom": "^16.13.1", From 93884030c82a6a18b813fcf1baa164b3c801ddee Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Fri, 14 Aug 2020 05:01:12 +0200 Subject: [PATCH 06/12] Fix plugin name --- multimodal_registration_vizarr.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multimodal_registration_vizarr.ipynb b/multimodal_registration_vizarr.ipynb index afa2e850..862d52b6 100644 --- a/multimodal_registration_vizarr.ipynb +++ b/multimodal_registration_vizarr.ipynb @@ -673,7 +673,7 @@ "\n", " async def run(self, ctx):\n", " viewer = await api.createWindow(\n", - " type=\"viv-plugin\",\n", + " type=\"vizarr\",\n", " src=\"https://hms-dbmi.github.io/vizarr/\"\n", " )\n", " for img in self.images:\n", From c78d3d5733cb559d010654092e8b7d80e75b78c3 Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Fri, 14 Aug 2020 05:01:37 +0200 Subject: [PATCH 07/12] Add ImJoy demo plugin and badge --- README.md | 1 + example/VizarrDemo.imjoy.html | 96 +++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 example/VizarrDemo.imjoy.html diff --git a/README.md b/README.md index e137663f..bf0048d0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # vizarr [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/hms-dbmi/vizarr/master?filepath=example%2Fgetting_started.ipynb) +[![launch ImJoy](https://imjoy.io/static/badge/launch-imjoy-badge.svg)](https://imjoy.io/#/app?plugin=https://github.com/hms-dbmi/vizarr/blob/master/example/VizarrDemo.imjoy.html) ![Multiscale OME-Zarr in Jupyter Notebook with Vizarr](/screenshot.png) diff --git a/example/VizarrDemo.imjoy.html b/example/VizarrDemo.imjoy.html new file mode 100644 index 00000000..1bb81881 --- /dev/null +++ b/example/VizarrDemo.imjoy.html @@ -0,0 +1,96 @@ + +[TODO: write documentation for this plugin.] + + + +{ + "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": [] +} + + + From 71022e0a3cc2d728fdc131193ed2d8081a1ffcfc Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Fri, 14 Aug 2020 05:16:47 +0200 Subject: [PATCH 08/12] Simplify vizarr demo --- example/VizarrDemo.imjoy.html | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/example/VizarrDemo.imjoy.html b/example/VizarrDemo.imjoy.html index 1bb81881..a46c98ff 100644 --- a/example/VizarrDemo.imjoy.html +++ b/example/VizarrDemo.imjoy.html @@ -67,28 +67,15 @@ pass async def run(self, ctx): - if ctx.data: - data = ctx.data - else: - # use default astronaut image - 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 - data = {"images": [ { "source": multiscale_astronaut, "name": "astronaut" } ]} + 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 - assert "images" in data - images = data["images"] - view_state = data.get('view_state') + # Create Zarr + images = [ { "source": multiscale_astronaut, "name": "astronaut" } ] - if not isinstance(images, list): - images = [images] - viewer = await api.createWindow( type="viv-plugin", src="https://hms-dbmi.github.io/vizarr" ) - if view_state: - await viewer.set_view_state(view_state) for img in images: await viewer.add_image(img) From 73af6d3d23f6c1deb1646cae58dcd4533b7b34d2 Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Fri, 14 Aug 2020 05:23:58 +0200 Subject: [PATCH 09/12] set workspace to vizarr --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf0048d0..5673697c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # vizarr [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/hms-dbmi/vizarr/master?filepath=example%2Fgetting_started.ipynb) -[![launch ImJoy](https://imjoy.io/static/badge/launch-imjoy-badge.svg)](https://imjoy.io/#/app?plugin=https://github.com/hms-dbmi/vizarr/blob/master/example/VizarrDemo.imjoy.html) +[![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) ![Multiscale OME-Zarr in Jupyter Notebook with Vizarr](/screenshot.png) From ccaf061d1ad690de139180dfae100733d5e20b22 Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Fri, 14 Aug 2020 16:32:56 +0200 Subject: [PATCH 10/12] Fix plugin name --- example/VizarrDemo.imjoy.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/VizarrDemo.imjoy.html b/example/VizarrDemo.imjoy.html index a46c98ff..cd21e79c 100644 --- a/example/VizarrDemo.imjoy.html +++ b/example/VizarrDemo.imjoy.html @@ -74,7 +74,7 @@ images = [ { "source": multiscale_astronaut, "name": "astronaut" } ] viewer = await api.createWindow( - type="viv-plugin", src="https://hms-dbmi.github.io/vizarr" + type="vizarr", src="https://hms-dbmi.github.io/vizarr" ) for img in images: await viewer.add_image(img) From 7d94c26075106a99d6226c179d66801d90bb75b7 Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Fri, 14 Aug 2020 17:56:55 +0200 Subject: [PATCH 11/12] Add readme --- example/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/example/README.md b/example/README.md index 8c127536..04cb97b4 100644 --- a/example/README.md +++ b/example/README.md @@ -33,4 +33,8 @@ This notebook a contains a `vizarr` example visualizing a generic multiscale Zar $ jupyter notebook mandelbrot.ipynb ``` +## 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) + +This [demo plugin](VizarrDemo.imjoy.html) shows how to build an image visualization plugin with `vizarr` in [ImJoy](https://imjoy.io). + From 0a6af387d2279052a37ef094428c3371ff2a4997 Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Fri, 14 Aug 2020 19:12:45 +0200 Subject: [PATCH 12/12] rename type --- example/imjoy_plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/imjoy_plugin.py b/example/imjoy_plugin.py index 0e916de6..2c0ad096 100644 --- a/example/imjoy_plugin.py +++ b/example/imjoy_plugin.py @@ -44,7 +44,7 @@ async def setup(self): async def run(self, ctx): viewer = await api.createWindow( - type="viv-plugin", src="https://hms-dbmi.github.io/vizarr" + type="vizarr", src="https://hms-dbmi.github.io/vizarr" ) if self.view_state: await viewer.set_view_state(self.view_state) @@ -53,4 +53,4 @@ async def run(self, ctx): def run_vizarr(images, view_state=None): - api.export(Plugin(images, view_state)) \ No newline at end of file + api.export(Plugin(images, view_state))