Skip to content

Commit

Permalink
Try a Colab-compatibility version
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuboudreau committed Feb 6, 2024
1 parent d69dd45 commit 1a00042
Showing 1 changed file with 109 additions and 2 deletions.
111 changes: 109 additions & 2 deletions content/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down Expand Up @@ -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": {},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit 1a00042

Please sign in to comment.