|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "bdd8e256", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# 1. Install pacakges" |
| 9 | + ] |
| 10 | + }, |
| 11 | + { |
| 12 | + "cell_type": "code", |
| 13 | + "execution_count": 1, |
| 14 | + "id": "e4b70b54", |
| 15 | + "metadata": { |
| 16 | + "scrolled": true |
| 17 | + }, |
| 18 | + "outputs": [ |
| 19 | + { |
| 20 | + "name": "stdout", |
| 21 | + "output_type": "stream", |
| 22 | + "text": [ |
| 23 | + "Collecting neuroglancer\n", |
| 24 | + " Downloading neuroglancer-2.22-cp39-cp39-macosx_10_9_x86_64.whl (2.5 MB)\n", |
| 25 | + "\u001b[K |████████████████████████████████| 2.5 MB 2.1 MB/s eta 0:00:01\n", |
| 26 | + "\u001b[?25hCollecting requests\n", |
| 27 | + " Downloading requests-2.26.0-py2.py3-none-any.whl (62 kB)\n", |
| 28 | + "\u001b[K |████████████████████████████████| 62 kB 992 kB/s eta 0:00:01\n", |
| 29 | + "\u001b[?25hCollecting google-auth\n", |
| 30 | + " Downloading google_auth-1.33.1-py2.py3-none-any.whl (152 kB)\n", |
| 31 | + "\u001b[K |████████████████████████████████| 152 kB 22.8 MB/s eta 0:00:01\n", |
| 32 | + "\u001b[?25hCollecting Pillow>=3.2.0\n", |
| 33 | + " Downloading Pillow-8.3.1-cp39-cp39-macosx_10_10_x86_64.whl (2.9 MB)\n", |
| 34 | + "\u001b[K |████████████████████████████████| 2.9 MB 9.8 MB/s eta 0:00:01\n", |
| 35 | + "\u001b[?25hRequirement already satisfied: tornado in /Applications/anaconda3/envs/exm/lib/python3.9/site-packages (from neuroglancer) (6.1)\n", |
| 36 | + "Collecting sockjs-tornado\n", |
| 37 | + " Downloading sockjs-tornado-1.0.7.tar.gz (21 kB)\n", |
| 38 | + "Collecting numpy>=1.11.0\n", |
| 39 | + " Downloading numpy-1.21.1-cp39-cp39-macosx_10_9_x86_64.whl (17.0 MB)\n", |
| 40 | + "\u001b[K |████████████████████████████████| 17.0 MB 8.6 MB/s eta 0:00:01\n", |
| 41 | + "\u001b[?25hCollecting google-apitools\n", |
| 42 | + " Downloading google_apitools-0.5.32-py3-none-any.whl (135 kB)\n", |
| 43 | + "\u001b[K |████████████████████████████████| 135 kB 57.1 MB/s eta 0:00:01\n", |
| 44 | + "\u001b[?25hRequirement already satisfied: six in /Applications/anaconda3/envs/exm/lib/python3.9/site-packages (from neuroglancer) (1.16.0)\n", |
| 45 | + "Collecting httplib2>=0.8\n", |
| 46 | + " Downloading httplib2-0.19.1-py3-none-any.whl (95 kB)\n", |
| 47 | + "\u001b[K |████████████████████████████████| 95 kB 4.1 MB/s eta 0:00:01\n", |
| 48 | + "\u001b[?25hCollecting fasteners>=0.14\n", |
| 49 | + " Downloading fasteners-0.16.3-py2.py3-none-any.whl (28 kB)\n", |
| 50 | + "Collecting oauth2client>=1.4.12\n", |
| 51 | + " Downloading oauth2client-4.1.3-py2.py3-none-any.whl (98 kB)\n", |
| 52 | + "\u001b[K |████████████████████████████████| 98 kB 9.7 MB/s eta 0:00:01\n", |
| 53 | + "\u001b[?25hRequirement already satisfied: pyparsing<3,>=2.4.2 in /Applications/anaconda3/envs/exm/lib/python3.9/site-packages (from httplib2>=0.8->google-apitools->neuroglancer) (2.4.7)\n", |
| 54 | + "Collecting pyasn1>=0.1.7\n", |
| 55 | + " Downloading pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)\n", |
| 56 | + "\u001b[K |████████████████████████████████| 77 kB 5.9 MB/s eta 0:00:01\n", |
| 57 | + "\u001b[?25hCollecting rsa>=3.1.4\n", |
| 58 | + " Downloading rsa-4.7.2-py3-none-any.whl (34 kB)\n", |
| 59 | + "Collecting pyasn1-modules>=0.0.5\n", |
| 60 | + " Downloading pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB)\n", |
| 61 | + "\u001b[K |████████████████████████████████| 155 kB 47.4 MB/s eta 0:00:01\n", |
| 62 | + "\u001b[?25hRequirement already satisfied: setuptools>=40.3.0 in /Applications/anaconda3/envs/exm/lib/python3.9/site-packages (from google-auth->neuroglancer) (52.0.0.post20210125)\n", |
| 63 | + "Collecting cachetools<5.0,>=2.0.0\n", |
| 64 | + " Downloading cachetools-4.2.2-py3-none-any.whl (11 kB)\n", |
| 65 | + "Collecting charset-normalizer~=2.0.0\n", |
| 66 | + " Downloading charset_normalizer-2.0.3-py3-none-any.whl (35 kB)\n", |
| 67 | + "Requirement already satisfied: certifi>=2017.4.17 in /Applications/anaconda3/envs/exm/lib/python3.9/site-packages (from requests->neuroglancer) (2021.5.30)\n", |
| 68 | + "Collecting urllib3<1.27,>=1.21.1\n", |
| 69 | + " Downloading urllib3-1.26.6-py2.py3-none-any.whl (138 kB)\n", |
| 70 | + "\u001b[K |████████████████████████████████| 138 kB 61.5 MB/s eta 0:00:01\n", |
| 71 | + "\u001b[?25hCollecting idna<4,>=2.5\n", |
| 72 | + " Downloading idna-3.2-py3-none-any.whl (59 kB)\n", |
| 73 | + "\u001b[K |████████████████████████████████| 59 kB 3.0 MB/s eta 0:00:01\n", |
| 74 | + "\u001b[?25hBuilding wheels for collected packages: sockjs-tornado\n", |
| 75 | + " Building wheel for sockjs-tornado (setup.py) ... \u001b[?25ldone\n", |
| 76 | + "\u001b[?25h Created wheel for sockjs-tornado: filename=sockjs_tornado-1.0.7-py3-none-any.whl size=31688 sha256=da6c4214e5ad5a0cb44b8cdba835ee0881a84c3f83998396b1cab6d70af1bddc\n", |
| 77 | + " Stored in directory: /Users/weidf/Library/Caches/pip/wheels/19/db/34/221419adf0402a8a6d6816706e7123e0d1a1e2141911b54a5b\n", |
| 78 | + "Successfully built sockjs-tornado\n", |
| 79 | + "Installing collected packages: pyasn1, rsa, pyasn1-modules, httplib2, urllib3, oauth2client, idna, fasteners, charset-normalizer, cachetools, sockjs-tornado, requests, Pillow, numpy, google-auth, google-apitools, neuroglancer\n", |
| 80 | + "Successfully installed Pillow-8.3.1 cachetools-4.2.2 charset-normalizer-2.0.3 fasteners-0.16.3 google-apitools-0.5.32 google-auth-1.33.1 httplib2-0.19.1 idna-3.2 neuroglancer-2.22 numpy-1.21.1 oauth2client-4.1.3 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.26.0 rsa-4.7.2 sockjs-tornado-1.0.7 urllib3-1.26.6\n" |
| 81 | + ] |
| 82 | + } |
| 83 | + ], |
| 84 | + "source": [ |
| 85 | + "# install neuroglancer for visualization\n", |
| 86 | + "import sys\n", |
| 87 | + "!{sys.executable} -m pip install neuroglancer" |
| 88 | + ] |
| 89 | + }, |
| 90 | + { |
| 91 | + "cell_type": "code", |
| 92 | + "execution_count": 15, |
| 93 | + "id": "f2cd2ad5", |
| 94 | + "metadata": { |
| 95 | + "scrolled": true |
| 96 | + }, |
| 97 | + "outputs": [ |
| 98 | + { |
| 99 | + "name": "stdout", |
| 100 | + "output_type": "stream", |
| 101 | + "text": [ |
| 102 | + "Cloning into 'emu_repo'...\n", |
| 103 | + "remote: Enumerating objects: 265, done.\u001b[K\n", |
| 104 | + "remote: Counting objects: 100% (265/265), done.\u001b[K\n", |
| 105 | + "remote: Compressing objects: 100% (167/167), done.\u001b[K\n", |
| 106 | + "remote: Total 265 (delta 140), reused 207 (delta 85), pack-reused 0\u001b[K\n", |
| 107 | + "Receiving objects: 100% (265/265), 61.57 KiB | 2.46 MiB/s, done.\n", |
| 108 | + "Resolving deltas: 100% (140/140), done.\n", |
| 109 | + "Obtaining file:///Users/weidf/Code/biomed/exM/emu_repo\n", |
| 110 | + "Requirement already satisfied: scipy in /Applications/anaconda3/envs/exm/lib/python3.9/site-packages (from emu==0.1) (1.7.0)\n", |
| 111 | + "Requirement already satisfied: numpy in /Applications/anaconda3/envs/exm/lib/python3.9/site-packages (from emu==0.1) (1.21.1)\n", |
| 112 | + "Requirement already satisfied: networkx in /Applications/anaconda3/envs/exm/lib/python3.9/site-packages (from emu==0.1) (2.5.1)\n", |
| 113 | + "Requirement already satisfied: h5py in /Applications/anaconda3/envs/exm/lib/python3.9/site-packages (from emu==0.1) (3.3.0)\n", |
| 114 | + "Requirement already satisfied: imageio in /Applications/anaconda3/envs/exm/lib/python3.9/site-packages (from emu==0.1) (2.9.0)\n", |
| 115 | + "Requirement already satisfied: pillow in /Applications/anaconda3/envs/exm/lib/python3.9/site-packages (from imageio->emu==0.1) (8.3.1)\n", |
| 116 | + "Requirement already satisfied: decorator<5,>=4.3 in /Applications/anaconda3/envs/exm/lib/python3.9/site-packages (from networkx->emu==0.1) (4.4.2)\n", |
| 117 | + "Installing collected packages: emu\n", |
| 118 | + " Running setup.py develop for emu\n", |
| 119 | + "Successfully installed emu-0.1\n" |
| 120 | + ] |
| 121 | + } |
| 122 | + ], |
| 123 | + "source": [ |
| 124 | + "# install EM-util for utility functions\n", |
| 125 | + "!git clone https://github.com/donglaiw/EM-util emu_repo\n", |
| 126 | + "!{sys.executable} -m pip install -e emu_repo" |
| 127 | + ] |
| 128 | + }, |
| 129 | + { |
| 130 | + "cell_type": "markdown", |
| 131 | + "id": "7120ec2f", |
| 132 | + "metadata": {}, |
| 133 | + "source": [ |
| 134 | + "# 2. Load a 3D volume in neuroglancer" |
| 135 | + ] |
| 136 | + }, |
| 137 | + { |
| 138 | + "cell_type": "code", |
| 139 | + "execution_count": 8, |
| 140 | + "id": "0fd23f1e", |
| 141 | + "metadata": {}, |
| 142 | + "outputs": [ |
| 143 | + { |
| 144 | + "data": { |
| 145 | + "text/plain": [ |
| 146 | + "5770307678" |
| 147 | + ] |
| 148 | + }, |
| 149 | + "execution_count": 8, |
| 150 | + "metadata": {}, |
| 151 | + "output_type": "execute_result" |
| 152 | + } |
| 153 | + ], |
| 154 | + "source": [ |
| 155 | + "# download data\n", |
| 156 | + "import requests\n", |
| 157 | + "url = 'http://rhoana.rc.fas.harvard.edu/dataset/F000_Round1.ims'\n", |
| 158 | + "r = requests.get(url, allow_redirects=True)\n", |
| 159 | + "open('F000_Round1.ims', 'wb').write(r.content)" |
| 160 | + ] |
| 161 | + }, |
| 162 | + { |
| 163 | + "cell_type": "code", |
| 164 | + "execution_count": 1, |
| 165 | + "id": "57adc104", |
| 166 | + "metadata": {}, |
| 167 | + "outputs": [], |
| 168 | + "source": [ |
| 169 | + "# load the 3d image volume\n", |
| 170 | + "import h5py\n", |
| 171 | + "import numpy as np\n", |
| 172 | + "# order: zyx\n", |
| 173 | + "im = np.array(h5py.File('F000_Round1.ims','r')['DataSet']['ResolutionLevel 0']['TimePoint 0']['Channel 4']['Data'])" |
| 174 | + ] |
| 175 | + }, |
| 176 | + { |
| 177 | + "cell_type": "code", |
| 178 | + "execution_count": null, |
| 179 | + "id": "e84d45e5", |
| 180 | + "metadata": {}, |
| 181 | + "outputs": [ |
| 182 | + { |
| 183 | + "name": "stderr", |
| 184 | + "output_type": "stream", |
| 185 | + "text": [ |
| 186 | + "Exception in thread Thread-4:\n", |
| 187 | + "Traceback (most recent call last):\n", |
| 188 | + " File \"/Applications/anaconda3/envs/exm/lib/python3.9/threading.py\", line 954, in _bootstrap_inner\n", |
| 189 | + " self.run()\n", |
| 190 | + " File \"/Applications/anaconda3/envs/exm/lib/python3.9/threading.py\", line 892, in run\n", |
| 191 | + " self._target(*self._args, **self._kwargs)\n", |
| 192 | + " File \"/Applications/anaconda3/envs/exm/lib/python3.9/site-packages/neuroglancer/server.py\", line 315, in start_server\n", |
| 193 | + " global_server = Server(ioloop=ioloop, **global_server_args)\n", |
| 194 | + " File \"/Applications/anaconda3/envs/exm/lib/python3.9/site-packages/neuroglancer/server.py\", line 100, in __init__\n", |
| 195 | + " sockets = tornado.netutil.bind_sockets(port=bind_port, address=bind_address)\n", |
| 196 | + " File \"/Applications/anaconda3/envs/exm/lib/python3.9/site-packages/tornado/netutil.py\", line 104, in bind_sockets\n", |
| 197 | + " socket.getaddrinfo(address, port, family, socket.SOCK_STREAM, 0, flags),\n", |
| 198 | + " File \"/Applications/anaconda3/envs/exm/lib/python3.9/socket.py\", line 953, in getaddrinfo\n", |
| 199 | + " for res in _socket.getaddrinfo(host, port, family, type, proto, flags):\n", |
| 200 | + "socket.gaierror: [Errno 8] nodename nor servname provided, or not known\n" |
| 201 | + ] |
| 202 | + } |
| 203 | + ], |
| 204 | + "source": [ |
| 205 | + "# setup neuroglancer\n", |
| 206 | + "import neuroglancer\n", |
| 207 | + "\n", |
| 208 | + "ip='127.0.0.1' # or public IP of the machine for sharable display\n", |
| 209 | + "port=98092 # change to an unused port number\n", |
| 210 | + "neuroglancer.set_server_bind_address(bind_address=ip, bind_port=port)\n", |
| 211 | + "viewer=neuroglancer.Viewer()\n", |
| 212 | + "\n", |
| 213 | + "print(viewer)" |
| 214 | + ] |
| 215 | + }, |
| 216 | + { |
| 217 | + "cell_type": "code", |
| 218 | + "execution_count": null, |
| 219 | + "id": "27166990", |
| 220 | + "metadata": {}, |
| 221 | + "outputs": [], |
| 222 | + "source": [ |
| 223 | + "import emu\n", |
| 224 | + "from emu.ng import ngLayer\n", |
| 225 | + "# set volume resolution: order xyz\n", |
| 226 | + "res= [170,170,400]\n", |
| 227 | + "with viewer.txn() as s:\n", |
| 228 | + " s.layers.append(name='im', layer=ngLayer(im, res, tt='image'))" |
| 229 | + ] |
| 230 | + } |
| 231 | + ], |
| 232 | + "metadata": { |
| 233 | + "kernelspec": { |
| 234 | + "display_name": "Python 3", |
| 235 | + "language": "python", |
| 236 | + "name": "python3" |
| 237 | + }, |
| 238 | + "language_info": { |
| 239 | + "codemirror_mode": { |
| 240 | + "name": "ipython", |
| 241 | + "version": 3 |
| 242 | + }, |
| 243 | + "file_extension": ".py", |
| 244 | + "mimetype": "text/x-python", |
| 245 | + "name": "python", |
| 246 | + "nbconvert_exporter": "python", |
| 247 | + "pygments_lexer": "ipython3", |
| 248 | + "version": "3.9.5" |
| 249 | + } |
| 250 | + }, |
| 251 | + "nbformat": 4, |
| 252 | + "nbformat_minor": 5 |
| 253 | +} |
0 commit comments