Skip to content

Instantly share code, notes, and snippets.

@oeway
Created May 20, 2021 12:55
Show Gist options
  • Save oeway/fc4028c6f4db0b5a72e3372abf9bb437 to your computer and use it in GitHub Desktop.
Save oeway/fc4028c6f4db0b5a72e3372abf9bb437 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ERROR:ImJoy-RPC:{'type': 'error', 'message': 'Traceback (most recent call last):\\n File \"/Users/wei.ouyang/miniconda3/lib/python3.7/site-packages/imjoy_rpc/rpc.py\", line 354, in _call_method\\n result = method(*args)\\n File \"/Users/wei.ouyang/workspace/ImJoy-Engine/imjoy/core/interface.py\", line 46, in get_plugin\\n raise Exception(f\"Plugin {name} not found\")\\nException: Plugin c2d69288-383d-45e5-a313-c2a704fe68b8 not found\\n', 'peer_id': '13038ba2-3d8f-43a5-9d56-a7f587bb84a5'}\n",
"ERROR:ImJoy-RPC:{'type': 'error', 'message': 'Traceback (most recent call last):\\n File \"/Users/wei.ouyang/miniconda3/lib/python3.7/site-packages/imjoy_rpc/rpc.py\", line 354, in _call_method\\n result = method(*args)\\n File \"/Users/wei.ouyang/workspace/ImJoy-Engine/imjoy/core/interface.py\", line 46, in get_plugin\\n raise Exception(f\"Plugin {name} not found\")\\nException: Plugin c2d69288-383d-45e5-a313-c2a704fe68b8 not found\\n', 'peer_id': '13038ba2-3d8f-43a5-9d56-a7f587bb84a5'}\n"
]
},
{
"ename": "Exception",
"evalue": "Traceback (most recent call last):\n File \"/Users/wei.ouyang/workspace/ImJoy-Engine/imjoy/core/interface.py\", line 46, in get_plugin\n raise Exception(f\"Plugin {name} not found\")\nException: Plugin c2d69288-383d-45e5-a313-c2a704fe68b8 not found",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mException\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-9-22550a7c66b0>\u001b[0m in \u001b[0;36masync-def-wrapper\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mlocations\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mawait\u001b[0m \u001b[0mplugin\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlocalize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mones\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlocations\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mException\u001b[0m: Traceback (most recent call last):\n File \"/Users/wei.ouyang/workspace/ImJoy-Engine/imjoy/core/interface.py\", line 46, in get_plugin\n raise Exception(f\"Plugin {name} not found\")\nException: Plugin c2d69288-383d-45e5-a313-c2a704fe68b8 not found"
]
}
],
"source": [
"import numpy as np\n",
"from imjoy import connect_to_server\n",
"ws = await connect_to_server(server_url=\"http://127.0.0.1:9527\", workspace=\"b54481bc-8685-46ca-8a4c-e2bd9bda9d08\", token=\"imjoy@eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZXMiOlsiYjU0NDgxYmMtODY4NS00NmNhLThhNGMtZTJiZDliZGE5ZDA4Il0sImV4cGlyZXNfYXQiOm51bGwsInVzZXJfaWQiOiI2NjczMGRmZC1jZmNlLTRjMDYtOTdmYi1hYTM5MTFlZTVmODYiLCJwYXJlbnQiOiJiNTQ0ODFiYy04Njg1LTQ2Y2EtOGE0Yy1lMmJkOWJkYTlkMDgiLCJlbWFpbCI6bnVsbCwicm9sZXMiOltdfQ.Qbt0J7f4XJccVNH4726tf0sPPq-jPUsz_B888_rrcgg\")\n",
"localize_plugin = await ws.getPlugin(\"localization\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"locations = await localize_plugin.localize(np.ones([100,100]))\n",
"print(locations)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"from imjoy import api\n",
"\n",
"class ImJoyPlugin():\n",
" def __init__(self,image):\n",
" self._image = image\n",
" \n",
" async def setup(self):\n",
" pass\n",
"\n",
" async def run(self, ctx):\n",
" # load the ImageJ.JS window\n",
" cellpose = await api.showDialog(src=\"https://cellpose.imjoy.io\")\n",
" # read the image\n",
" result = await cellpose.segment({\"input\": self._image, \"diam\": 300, \"net\": \"cyto\", \"chan1\": 1, \"chan2\": 3, \"keep_size\": True, \"outputs\": \"flow,mask,outline_plot,flow_plot\"})\n",
" # we will get mask and flow as numpy array\n",
" flow = result[\"flow\"]\n",
" mask = result[\"mask\"]\n",
" await api.alert(str(result[\"mask\"].shape))\n",
"\n",
"def segment(image):\n",
" api.export(ImJoyPlugin(image))"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"application/javascript": [
"window.connectPlugin && window.connectPlugin(\"65088bd1-0d92-408d-9685-b01d393fbb7c\")"
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div id=\"a4f022f7-b0cb-4efd-bec6-6daa29a12061\"></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"locations = await localize_plugin.localize(np.ones([100,100]))\n",
"segment(locations)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"application/javascript": [
"window.connectPlugin && window.connectPlugin(\"65088bd1-0d92-408d-9685-b01d393fbb7c\")"
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div id=\"8724f4b0-9d8e-48dd-a82d-ebbac03e5fbf\"></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"<Future finished result=[]>"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from imjoy import api\n",
"import numpy as np\n",
"\n",
"class ImJoyPlugin():\n",
" def setup(self):\n",
" api.log('plugin initialized')\n",
"\n",
" async def run(self, ctx):\n",
" # here the itk_image will be encoded via the registered encoder function (i.e.: itkimage_to_json)\n",
" api.showDialog(type=\"itk-vtk-viewer\", src=\"https://oeway.github.io/itk-vtk-viewer/\", data={\"image\": locations})\n",
"\n",
"api.export(ImJoyPlugin())\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment