|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "\n", |
| 8 | + "# Setup Google Colab\n", |
| 9 | + "\n", |
| 10 | + "In this script, we setup a Google Colab environment. This script will only work\n", |
| 11 | + "when run from [Google Colab](https://colab.research.google.com/). You can\n", |
| 12 | + "skip it if you run the tutorials on your machine.\n", |
| 13 | + "\n", |
| 14 | + "> **Note:** This script will install all the required dependencies and download the data.\n", |
| 15 | + "> It will take around 10 minutes to run, but you need to run it only once in your Colab session.\n", |
| 16 | + "> If your Colab session is disconnected, you will need to run this script again." |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "markdown", |
| 21 | + "metadata": {}, |
| 22 | + "source": [ |
| 23 | + "## Change runtime to use a GPU\n", |
| 24 | + "\n", |
| 25 | + "This tutorial is much faster when a GPU is available to run the computations.\n", |
| 26 | + "In Google Colab you can request access to a GPU by changing the runtime type.\n", |
| 27 | + "To do so, click the following menu options in Google Colab:\n", |
| 28 | + "\n", |
| 29 | + "> (Menu) \"Runtime\" -> \"Change runtime type\" -> \"Hardware accelerator\" -> \"GPU\".\n", |
| 30 | + "\n" |
| 31 | + ] |
| 32 | + }, |
| 33 | + { |
| 34 | + "cell_type": "markdown", |
| 35 | + "metadata": {}, |
| 36 | + "source": [ |
| 37 | + "## Install all required dependencies and download the data\n", |
| 38 | + "\n", |
| 39 | + "Uncomment and run the following cell to download the required packages.\n", |
| 40 | + "\n" |
| 41 | + ] |
| 42 | + }, |
| 43 | + { |
| 44 | + "cell_type": "code", |
| 45 | + "execution_count": null, |
| 46 | + "metadata": { |
| 47 | + "collapsed": false |
| 48 | + }, |
| 49 | + "outputs": [], |
| 50 | + "source": [ |
| 51 | + "#!git config --global user.email \"you@example.com\" && git config --global user.name \"Your Name\"\n", |
| 52 | + "#!wget -O- http://neuro.debian.net/lists/jammy.us-ca.libre | sudo tee /etc/apt/sources.list.d/neurodebian.sources.list\n", |
| 53 | + "#!apt-key adv --recv-keys --keyserver hkps://keyserver.ubuntu.com 0xA5D32F012649A5A9 > /dev/null\n", |
| 54 | + "#!apt-get -qq update > /dev/null\n", |
| 55 | + "#!apt-get install -qq inkscape git-annex-standalone > /dev/null\n", |
| 56 | + "#!pip install -q voxelwise_tutorials" |
| 57 | + ] |
| 58 | + }, |
| 59 | + { |
| 60 | + "cell_type": "markdown", |
| 61 | + "metadata": {}, |
| 62 | + "source": [ |
| 63 | + "For the record, here is what each command does:\n", |
| 64 | + "\n" |
| 65 | + ] |
| 66 | + }, |
| 67 | + { |
| 68 | + "cell_type": "code", |
| 69 | + "execution_count": null, |
| 70 | + "metadata": { |
| 71 | + "collapsed": false |
| 72 | + }, |
| 73 | + "outputs": [], |
| 74 | + "source": [ |
| 75 | + "# - Set up an email and username to use git, git-annex, and datalad (required to download the data)\n", |
| 76 | + "# - Add NeuroDebian to the package sources\n", |
| 77 | + "# - Update the gpg keys to use NeuroDebian\n", |
| 78 | + "# - Update the list of available packages\n", |
| 79 | + "# - Install Inkscape to use more features from Pycortex, and install git-annex to download the data\n", |
| 80 | + "# - Install the tutorial helper package, and all the required dependencies" |
| 81 | + ] |
| 82 | + }, |
| 83 | + { |
| 84 | + "cell_type": "code", |
| 85 | + "execution_count": null, |
| 86 | + "metadata": { |
| 87 | + "collapsed": false |
| 88 | + }, |
| 89 | + "outputs": [], |
| 90 | + "source": [ |
| 91 | + "try:\n", |
| 92 | + " import google.colab # noqa\n", |
| 93 | + " in_colab = True\n", |
| 94 | + "except ImportError:\n", |
| 95 | + " in_colab = False\n", |
| 96 | + "if not in_colab:\n", |
| 97 | + " raise RuntimeError(\"This script is only meant to be run from Google \"\n", |
| 98 | + " \"Colab. You can skip it if you run the tutorials \"\n", |
| 99 | + " \"on your machine.\")" |
| 100 | + ] |
| 101 | + }, |
| 102 | + { |
| 103 | + "cell_type": "markdown", |
| 104 | + "metadata": {}, |
| 105 | + "source": [ |
| 106 | + "Now run the following cell to download the data for the tutorials.\n", |
| 107 | + "\n" |
| 108 | + ] |
| 109 | + }, |
| 110 | + { |
| 111 | + "cell_type": "code", |
| 112 | + "execution_count": null, |
| 113 | + "metadata": { |
| 114 | + "collapsed": false |
| 115 | + }, |
| 116 | + "outputs": [], |
| 117 | + "source": [ |
| 118 | + "from voxelwise_tutorials.io import download_datalad\n", |
| 119 | + "\n", |
| 120 | + "DATAFILES = [\n", |
| 121 | + " \"features/motion_energy.hdf\",\n", |
| 122 | + " \"features/wordnet.hdf\",\n", |
| 123 | + " \"mappers/S01_mappers.hdf\",\n", |
| 124 | + " \"responses/S01_responses.hdf\",\n", |
| 125 | + "]\n", |
| 126 | + "\n", |
| 127 | + "source = \"https://gin.g-node.org/gallantlab/shortclips\"\n", |
| 128 | + "destination = \"/content/shortclips\"\n", |
| 129 | + "\n", |
| 130 | + "for datafile in DATAFILES:\n", |
| 131 | + " local_filename = download_datalad(\n", |
| 132 | + " datafile,\n", |
| 133 | + " destination=destination,\n", |
| 134 | + " source=source\n", |
| 135 | + " )" |
| 136 | + ] |
| 137 | + }, |
| 138 | + { |
| 139 | + "cell_type": "markdown", |
| 140 | + "metadata": {}, |
| 141 | + "source": [ |
| 142 | + "Now run the following cell to set up the environment variables for the\n", |
| 143 | + "tutorials and pycortex.\n", |
| 144 | + "\n" |
| 145 | + ] |
| 146 | + }, |
| 147 | + { |
| 148 | + "cell_type": "code", |
| 149 | + "execution_count": null, |
| 150 | + "metadata": { |
| 151 | + "collapsed": false |
| 152 | + }, |
| 153 | + "outputs": [], |
| 154 | + "source": [ |
| 155 | + "import os\n", |
| 156 | + "os.environ['VOXELWISE_TUTORIALS_DATA'] = \"/content\"\n", |
| 157 | + "\n", |
| 158 | + "import sklearn\n", |
| 159 | + "sklearn.set_config(assume_finite=True)" |
| 160 | + ] |
| 161 | + }, |
| 162 | + { |
| 163 | + "cell_type": "markdown", |
| 164 | + "metadata": {}, |
| 165 | + "source": [ |
| 166 | + "Your Google Colab environment is now set up for the voxelwise tutorials.\n", |
| 167 | + "\n" |
| 168 | + ] |
| 169 | + } |
| 170 | + ], |
| 171 | + "metadata": { |
| 172 | + "kernelspec": { |
| 173 | + "display_name": "Python 3", |
| 174 | + "language": "python", |
| 175 | + "name": "python3" |
| 176 | + }, |
| 177 | + "language_info": { |
| 178 | + "codemirror_mode": { |
| 179 | + "name": "ipython", |
| 180 | + "version": 3 |
| 181 | + }, |
| 182 | + "file_extension": ".py", |
| 183 | + "mimetype": "text/x-python", |
| 184 | + "name": "python", |
| 185 | + "nbconvert_exporter": "python", |
| 186 | + "pygments_lexer": "ipython3", |
| 187 | + "version": "3.7.12" |
| 188 | + } |
| 189 | + }, |
| 190 | + "nbformat": 4, |
| 191 | + "nbformat_minor": 0 |
| 192 | +} |
0 commit comments