Skip to content
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

Add ImJoy demo plugin and badge #20

Merged
merged 13 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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?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)

Expand Down
2 changes: 1 addition & 1 deletion binder/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ dependencies:
- pip:
- imjoy>=0.10.0
- imjoy-jupyter-extension
- imjoy-rpc
- imjoy-rpc>=0.2.11
83 changes: 83 additions & 0 deletions example/VizarrDemo.imjoy.html
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="viv-plugin", src="https://hms-dbmi.github.io/vizarr"
manzt marked this conversation as resolved.
Show resolved Hide resolved
)
for img in images:
await viewer.add_image(img)

api.export(Plugin())
</script>
2 changes: 1 addition & 1 deletion example/imjoy_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ async def run(self, ctx):


def run_vizarr(images, view_state=None):
api.export(Plugin(images, view_state))
api.export(Plugin(images, view_state))
Copy link
Member

Choose a reason for hiding this comment

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

I can't leave a comment, but the type needs to be updated above on line 47

2 changes: 1 addition & 1 deletion example/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion multimodal_registration_vizarr.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.22",
"next": "^9.5.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
Expand Down
7 changes: 6 additions & 1 deletion src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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',
Copy link
Contributor Author

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.

description: 'A minimal, purely client-side program for viewing Zarr-based images with Viv & ImJoy',
version: vizarrVersion,
Copy link
Member

Choose a reason for hiding this comment

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

As a side note, how do you version kaibu? When hosting the app on gh-pages, I'm not sure of the best way to ensure older versions are available.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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, npm run dev didn't work for me.

Copy link
Member

@manzt manzt Aug 14, 2020

Choose a reason for hiding this comment

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

For some reason, npm run dev didn't work for me.

What isn't working exactly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 });
Expand Down