From f6ae8b824505092238858932f4e58e52cdf30464 Mon Sep 17 00:00:00 2001 From: Masood-Akram Date: Sat, 31 Jan 2026 13:57:23 -0800 Subject: [PATCH 1/4] colab: make setup cell more robust --- Python/01_Image_Basics.ipynb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Python/01_Image_Basics.ipynb b/Python/01_Image_Basics.ipynb index b9b789f9..655c5a3a 100644 --- a/Python/01_Image_Basics.ipynb +++ b/Python/01_Image_Basics.ipynb @@ -23,12 +23,21 @@ "outputs": [], "source": [ "# Setup to enable running the notebook in the Google Colab environment\n", - "import os\n", + "import pathlib\n", "\n", - "if \"COLAB_NOTEBOOK_ID\" in os.environ:\n", - " !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n", + "def _in_colab() -> bool:\n", + " try:\n", + " import google.colab # noqa: F401\n", + " return True\n", + " except Exception:\n", + " return False\n", + "\n", + "if _in_colab():\n", + " repo_dir = pathlib.Path(\"SimpleITK-Notebooks\")\n", + " if not repo_dir.exists():\n", + " !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n", " %cd SimpleITK-Notebooks/Python\n", - " !pip install -q -r requirements.txt" + " !pip install -q -r requirements.txt\n" ] }, { From cf2cac15af85faf61b1678edd3c2ffeb0aba2699 Mon Sep 17 00:00:00 2001 From: Masood-Akram Date: Tue, 3 Feb 2026 08:49:37 -0800 Subject: [PATCH 2/4] style: simplify colab setup block --- Python/01_Image_Basics.ipynb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Python/01_Image_Basics.ipynb b/Python/01_Image_Basics.ipynb index 655c5a3a..76cda44d 100644 --- a/Python/01_Image_Basics.ipynb +++ b/Python/01_Image_Basics.ipynb @@ -23,21 +23,19 @@ "outputs": [], "source": [ "# Setup to enable running the notebook in the Google Colab environment\n", - "import pathlib\n", "\n", - "def _in_colab() -> bool:\n", - " try:\n", - " import google.colab # noqa: F401\n", - " return True\n", - " except Exception:\n", - " return False\n", + "try:\n", + " import google.colab # noqa: F401\n", + " import pathlib\n", "\n", - "if _in_colab():\n", " repo_dir = pathlib.Path(\"SimpleITK-Notebooks\")\n", " if not repo_dir.exists():\n", " !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n", " %cd SimpleITK-Notebooks/Python\n", - " !pip install -q -r requirements.txt\n" + " !pip install -q -r requirements.txt\n", + "\n", + "except ImportError:\n", + " pass # not on Colab\n" ] }, { From 6a6eb88f472936ee9b74789f67accfbb130233de Mon Sep 17 00:00:00 2001 From: Ziv Yaniv Date: Tue, 3 Feb 2026 13:02:02 -0500 Subject: [PATCH 3/4] Update black formatting of notebooks. --- Python/01_Image_Basics.ipynb | 2 +- Python/36_Microscopy_Colocalization_Distance_Analysis.ipynb | 1 - Python/71_Trust_But_Verify.ipynb | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Python/01_Image_Basics.ipynb b/Python/01_Image_Basics.ipynb index 76cda44d..023888df 100644 --- a/Python/01_Image_Basics.ipynb +++ b/Python/01_Image_Basics.ipynb @@ -35,7 +35,7 @@ " !pip install -q -r requirements.txt\n", "\n", "except ImportError:\n", - " pass # not on Colab\n" + " pass # not on Colab" ] }, { diff --git a/Python/36_Microscopy_Colocalization_Distance_Analysis.ipynb b/Python/36_Microscopy_Colocalization_Distance_Analysis.ipynb index 84a66d63..713dd1f6 100644 --- a/Python/36_Microscopy_Colocalization_Distance_Analysis.ipynb +++ b/Python/36_Microscopy_Colocalization_Distance_Analysis.ipynb @@ -25,7 +25,6 @@ "import numpy as np\n", "import pandas as pd\n", "\n", - "\n", "%matplotlib widget\n", "import gui\n", "\n", diff --git a/Python/71_Trust_But_Verify.ipynb b/Python/71_Trust_But_Verify.ipynb index 12a72a84..51116781 100644 --- a/Python/71_Trust_But_Verify.ipynb +++ b/Python/71_Trust_But_Verify.ipynb @@ -75,7 +75,6 @@ "import matplotlib.pyplot as plt\n", "import ipywidgets as widgets\n", "\n", - "\n", "# utility method that either downloads data from the Girder repository or\n", "# if already downloaded returns the file name for reading from disk (cached data)\n", "%run update_path_to_download_script\n", From 52a2fcd7b4bdaf9c1145c52b9b1a34b6eb52a217 Mon Sep 17 00:00:00 2001 From: Ziv Yaniv Date: Tue, 3 Feb 2026 13:13:27 -0500 Subject: [PATCH 4/4] Removed flake8_nb directive from notebook. The notebook repository does not use flake8_nb for linting, so removed the noqa directive which is identified as a spelling mistake by our spellchecker. --- Python/01_Image_Basics.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/01_Image_Basics.ipynb b/Python/01_Image_Basics.ipynb index 023888df..8df29a37 100644 --- a/Python/01_Image_Basics.ipynb +++ b/Python/01_Image_Basics.ipynb @@ -25,7 +25,7 @@ "# Setup to enable running the notebook in the Google Colab environment\n", "\n", "try:\n", - " import google.colab # noqa: F401\n", + " import google.colab\n", " import pathlib\n", "\n", " repo_dir = pathlib.Path(\"SimpleITK-Notebooks\")\n",