From 1a00042f738aa1d2a0141bfd3e8c7e0a2877848b Mon Sep 17 00:00:00 2001 From: Mathieu Boudreau Date: Tue, 6 Feb 2024 14:59:01 -0400 Subject: [PATCH] Try a Colab-compatibility version --- content/index.ipynb | 111 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 109 insertions(+), 2 deletions(-) diff --git a/content/index.ipynb b/content/index.ipynb index ca96247..5255e17 100644 --- a/content/index.ipynb +++ b/content/index.ipynb @@ -12,7 +12,15 @@ "outputs": [], "source": [ "build = 'archive' # 'archive' uses the neurolibre archive of the data., 'latest' would download the latest versions of the data.\n", - "notebook = 'figures'" + "notebook = 'figures' # figures: no processing, use downloaded processed data and do figures & stats,\n", + " # jupyter: if some processed data exists, cleanup; Reprocess data\n", + " # colab: download and process data from scratch in Google Colab\n", + "\n", + "try:\n", + " import google.colab\n", + " notebook = 'colab'\n", + "except:\n", + " pass" ] }, { @@ -268,6 +276,76 @@ "import statsmodels.api as sm" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [ + "remove_input", + "remove_output" + ] + }, + "outputs": [], + "source": [ + "# Start timer\n", + "start_time = datetime.now()\n", + "\n", + "# Check where we are\n", + "!pwd" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [ + "remove_input", + "remove_output" + ] + }, + "outputs": [], + "source": [ + "# Google Colab-Only\n", + "# ⚠️ No need to run this cell if you run this notebook locally and already have these dependencies installed.\n", + "\n", + "if notebook == 'colab':\n", + " # Install packages on system\n", + " !sudo apt-get update\n", + " !sudo apt-get install git-annex\n", + "\n", + " # Install Python libaries\n", + " !wget -O requirements.txt https://raw.githubusercontent.com/shimming-toolbox/rf-shimming-7t/main/requirements.txt\n", + " !pip install -r requirements.txt\n", + "\n", + " # Install SCT ⏳\n", + " !git clone --depth 1 https://github.com/spinalcordtoolbox/spinalcordtoolbox.git\n", + " !yes | spinalcordtoolbox/install_sct\n", + " os.environ['PATH'] += f\":/content/spinalcordtoolbox/bin\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [ + "remove_input", + "remove_output" + ] + }, + "outputs": [], + "source": [ + "# Download data and define path variables\n", + "\n", + "# Google Colab-Only\n", + "if notebook=='colab':\n", + " !datalad install https://github.com/OpenNeuroDatasets/ds004906.git\n", + " os.chdir(\"ds004906\")\n", + " !datalad get . # uncomment for production\n", + " # !datalad get sub-01/ # debugging\n", + " # Get derivatives containing manual labels\n", + " !datalad get derivatives" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -296,7 +374,8 @@ } ], "source": [ - "os.chdir(\"../data/rf-shimming-7t/ds004906\")\n", + "if notebook!='colab':\n", + " os.chdir(\"../data/rf-shimming-7t/ds004906\")\n", "\n", "path_data = os.getcwd()\n", "print(f\"path_data: {path_data}\")\n", @@ -1717,6 +1796,34 @@ ":filter: docname in docnames\n", "```" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [ + "remove_input", + "remove_output" + ] + }, + "outputs": [], + "source": [ + "# Indicate duration of data processing\n", + "\n", + "end_time = datetime.now()\n", + "total_time = (end_time - start_time).total_seconds()\n", + "\n", + "# Convert seconds to a timedelta object\n", + "total_time_delta = timedelta(seconds=total_time)\n", + "\n", + "# Format the timedelta object to a string\n", + "formatted_time = str(total_time_delta)\n", + "\n", + "# Pad the string representation if less than an hour\n", + "formatted_time = formatted_time.rjust(8, '0')\n", + "\n", + "print(f\"Total Runtime [hour:min:sec]: {formatted_time}\")" + ] } ], "metadata": {