|
209 | 209 | "cell_type": "markdown", |
210 | 210 | "metadata": {}, |
211 | 211 | "source": [ |
212 | | - "## Map to \"fsaverage\"\n\nThe second mapper we provide maps the voxel data to a Freesurfer\naverage surface (\"fsaverage\"), that can be used in ``pycortex``.\nFirst, let's download the \"fsaverage\" surface.\n\n" |
| 212 | + "## Map to \"fsaverage\"\n\nThe second mapper we provide maps the voxel data to a Freesurfer\naverage surface (\"fsaverage\"), that can be used in ``pycortex``.\n\nIf you are running the notebook on Colab, you might need to update the\npycortex filestore as following:\n\n" |
213 | 213 | ] |
214 | 214 | }, |
215 | 215 | { |
|
220 | 220 | }, |
221 | 221 | "outputs": [], |
222 | 222 | "source": [ |
223 | | - "import cortex\n\nsurface = \"fsaverage\"\n\nif not hasattr(cortex.db, surface):\n cortex.utils.download_subject(subject_id=surface)" |
| 223 | + "import cortex\ntry:\n import google.colab # noqa\n in_colab = True\nexcept ImportError:\n in_colab = False\nprint(in_colab)\n\nif in_colab:\n filestore = cortex.options.config['basic']['filestore']\n cortex.database.db = cortex.database.Database(filestore)\n cortex.db = cortex.database.db\n cortex.utils.db = cortex.database.db\n cortex.dataset.braindata.db = cortex.database.db\n cortex.quickflat.utils.db = cortex.database.db\n cortex.quickflat.composite.db = cortex.database.db" |
224 | 224 | ] |
225 | 225 | }, |
226 | 226 | { |
227 | 227 | "cell_type": "markdown", |
228 | 228 | "metadata": {}, |
229 | 229 | "source": [ |
230 | | - "If you are running the notebook on Colab, you might need to update the\npycortex filestore as following:\n\n" |
| 230 | + "Now, let's download the \"fsaverage\" surface.\n\n" |
231 | 231 | ] |
232 | 232 | }, |
233 | 233 | { |
|
238 | 238 | }, |
239 | 239 | "outputs": [], |
240 | 240 | "source": [ |
241 | | - "try:\n import google.colab # noqa\n in_colab = True\nexcept ImportError:\n in_colab = False\nprint(in_colab)\n\nif in_colab:\n filestore = cortex.options.config['basic']['filestore']\n cortex.database.db = cortex.database.Database(filestore)\n cortex.db = cortex.database.db\n cortex.utils.db = cortex.database.db\n cortex.dataset.braindata.db = cortex.database.db\n cortex.quickflat.utils.db = cortex.database.db\n cortex.quickflat.composite.db = cortex.database.db" |
| 241 | + "surface = \"fsaverage\"\n\nif not hasattr(cortex.db, surface):\n cortex.utils.download_subject(subject_id=surface)" |
242 | 242 | ] |
243 | 243 | }, |
244 | 244 | { |
|
281 | 281 | "cell_type": "markdown", |
282 | 282 | "metadata": {}, |
283 | 283 | "source": [ |
284 | | - "To start an interactive 3D viewer in the browser, use the ``webshow``\nfunction.\n\n" |
| 284 | + "To start an interactive 3D viewer in the browser, we can use the ``webshow``\nfunction in pycortex.\nIf you are running the notebook on Colab, you first need to tunnel the pycortex\napplication out of Colab. To do so, use the following cell to start a tunnel\nwith ``ngrok`` and to get an address where the pycortex viewer will be made\naccessible.\n\n" |
285 | 285 | ] |
286 | 286 | }, |
287 | 287 | { |
|
292 | 292 | }, |
293 | 293 | "outputs": [], |
294 | 294 | "source": [ |
295 | | - "if False:\n cortex.webshow(vertex, open_browser=False, port=8050)" |
| 295 | + "if in_colab:\n from IPython import get_ipython\n get_ipython().system_raw('./ngrok http 8050 &')\n plt.pause(1)\n\n command = \"\"\"\n curl -s http://localhost:4040/api/tunnels | python3 -c \\\n \"import sys, json; print(json.load(sys.stdin)['tunnels'][0]['public_url'])\"\n \"\"\"\n result = get_ipython().getoutput(command, split=True)\n print(\"Use the following address to connect to the brain viewer:\\n\"\n f\"{result}\\n\"\n \"and not the one proposed by pycortex ('Open viewer: ...')\\n\")" |
296 | 296 | ] |
297 | 297 | }, |
298 | 298 | { |
299 | 299 | "cell_type": "markdown", |
300 | 300 | "metadata": {}, |
301 | 301 | "source": [ |
302 | | - "If you are running the notebook on Colab, you need to tunnel the pycortex\napplication out of Colab. To do so, use the following cell to start a tunnel\nwith ``ngrok`` and to get an address where the pycortex viewer will be made\naccessible.\n\n" |
| 302 | + "Now you can start an interactive 3D viewer by changing ``run_webshow`` to\n``True`` and running the following cell. If you are using Colab, remember to\nuse the address returned by ngrok in the cell above rather than the address\nreturned by this cell.\n\n" |
303 | 303 | ] |
304 | 304 | }, |
305 | 305 | { |
|
310 | 310 | }, |
311 | 311 | "outputs": [], |
312 | 312 | "source": [ |
313 | | - "if in_colab:\n from IPython import get_ipython\n get_ipython().system_raw('./ngrok http 8050 &')\n plt.pause(1)\n\n command = \"\"\"\n curl -s http://localhost:4040/api/tunnels | python3 -c \\\n \"import sys, json; print(json.load(sys.stdin)['tunnels'][0]['public_url'])\"\n \"\"\"\n result = get_ipython().getoutput(command, split=True)\n print(\"Use the following address to connect to the brain viewer:\\n\"\n f\"{result}\\n\"\n \"and not the one proposed by pycortex ('Open viewer: ...')\\n\")" |
| 313 | + "run_webshow = False\nif run_webshow:\n cortex.webshow(vertex, open_browser=False, port=8050)" |
314 | 314 | ] |
315 | 315 | }, |
316 | 316 | { |
|
328 | 328 | }, |
329 | 329 | "outputs": [], |
330 | 330 | "source": [ |
331 | | - "from cortex.testing_utils import has_installed\n\n\nfig = cortex.quickshow(vertex, colorbar_location='right',\n with_rois=has_installed(\"inkscape\"))\nplt.show()" |
| 331 | + "from cortex.testing_utils import has_installed\n\nfig = cortex.quickshow(vertex, colorbar_location='right',\n with_rois=has_installed(\"inkscape\"))\nplt.show()" |
332 | 332 | ] |
333 | 333 | }, |
334 | 334 | { |
|
355 | 355 | "name": "python", |
356 | 356 | "nbconvert_exporter": "python", |
357 | 357 | "pygments_lexer": "ipython3", |
358 | | - "version": "3.7.3" |
| 358 | + "version": "3.8.3" |
359 | 359 | } |
360 | 360 | }, |
361 | 361 | "nbformat": 4, |
|
0 commit comments