--- a +++ b/colab-utils/Colab - Download Data to Drive.ipynb @@ -0,0 +1,194 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Colab - Download Data to Drive.ipynb", + "version": "0.3.2", + "views": {}, + "default_view": {}, + "provenance": [], + "collapsed_sections": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "metadata": { + "id": "jasaF2lvl03G", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "# How to Download Data with Google Colab and Save it on your Drive.\n", + "\n", + "1. Download the Data.\n", + "2. Google Authentification Process.\n", + "3. Mount/Bridge your G-Drive in a local Folder.\n", + "4. Zip the files from the Colab Instance to your G-Drive.\n", + "\n", + "It is important that you download the data before bridging/mounting your own G-Drive on the Colab Instance.\n", + "\n", + "The Read/Write Speed when the G-Drive is Mounted is super slow." + ] + }, + { + "metadata": { + "id": "dre-TDmVgLm-", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "# 1- Download the Data\n", + "\n", + "Here is an example with the BNCI2020 Two class motor imagery (002-2014)\n", + "\n", + "(http://bnci-horizon-2020.eu/database/data-sets)\n" + ] + }, + { + "metadata": { + "id": "UldgxbAHfw89", + "colab_type": "code", + "colab": { + "autoexec": { + "startup": false, + "wait_interval": 0 + } + } + }, + "cell_type": "code", + "source": [ + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S01T.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S01E.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S02T.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S02E.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S03T.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S03E.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S04T.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S04E.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S05T.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S05E.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S06T.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S06E.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S07T.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S07E.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S08T.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S08E.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S09T.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S09E.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S10T.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S10E.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S11T.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S11E.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S12T.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S12E.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S13T.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S13E.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S14T.mat\n", + "!wget http://bnci-horizon-2020.eu/database/data-sets/002-2014/S14E.mat" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "gHsMIGoHoEDp", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#2- Google Authentification Process." + ] + }, + { + "metadata": { + "id": "h2m-iX75f5XH", + "colab_type": "code", + "colab": { + "autoexec": { + "startup": false, + "wait_interval": 0 + } + } + }, + "cell_type": "code", + "source": [ + "!apt-get install -y -qq software-properties-common python-software-properties module-init-tools\n", + "!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null\n", + "!apt-get update -qq 2>&1 > /dev/null\n", + "!apt-get -y install -qq google-drive-ocamlfuse fuse\n", + "from google.colab import auth\n", + "auth.authenticate_user()\n", + "from oauth2client.client import GoogleCredentials\n", + "creds = GoogleCredentials.get_application_default()\n", + "import getpass\n", + "!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL\n", + "vcode = getpass.getpass()\n", + "!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "9BYzWE3ep_8_", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#3- Mount/Bridge your G-Drive in a local Folder." + ] + }, + { + "metadata": { + "id": "X33zlNM2gInI", + "colab_type": "code", + "colab": { + "autoexec": { + "startup": false, + "wait_interval": 0 + } + } + }, + "cell_type": "code", + "source": [ + "!mkdir -p drive\n", + "!google-drive-ocamlfuse drive" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "XlEyC6qTqFPE", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#4- Zip the files from the Colab Instance to your G-Drive." + ] + }, + { + "metadata": { + "id": "gY6rsB8lgKbQ", + "colab_type": "code", + "colab": { + "autoexec": { + "startup": false, + "wait_interval": 0 + } + } + }, + "cell_type": "code", + "source": [ + "!zip ./drive/BCIData.zip *.mat" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file