|
| 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> |
0 commit comments