Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions napari_cellseg3d/_tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ def test_all_plugins_import(make_napari_viewer_proxy):
plugins.napari_experimental_provide_dock_widget()


def test_plugin_metrics(make_napari_viewer_proxy):
def test_plugin_metrics(make_napari_viewer_proxy, qtbot):
viewer = make_napari_viewer_proxy()
w = m.MetricsUtils(viewer=viewer, parent=None)
viewer.window.add_dock_widget(w)
qtbot.addWidget(w)
# viewer.window.add_dock_widget(w)

im_path = str(Path(__file__).resolve().parent / "res/test.tif")
labels_path = im_path
Expand Down
130 changes: 126 additions & 4 deletions notebooks/Colab_inference_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"id": "view-in-github"
},
"source": [
"<a href=\"https://colab.research.google.com/github/MMathisLab/CellSeg3d/blob/main/Notebooks/Colab_inference_demo.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
"<a href=\"https://colab.research.google.com/github/AdaptiveMotorControlLab/CellSeg3D/blob/main/notebooks/Colab_inference_demo.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
Expand Down Expand Up @@ -53,9 +53,131 @@
},
"outputs": [],
"source": [
"# @markdown ##Install CellSeg3D and grab demo data\n",
"!git clone https://github.com/AdaptiveMotorControlLab/CellSeg3d.git --branch main --single-branch ./CellSeg3D\n",
"!pip install napari-cellseg3d"
"# @markdown ## Install CellSeg3D and ensure demo data\n",
"\n",
"import os\n",
"import shutil\n",
"import subprocess\n",
"import sys\n",
"import time\n",
"from pathlib import Path\n",
"\n",
"REPO_DIR = Path(\"/content/CellSeg3D\")\n",
"DEMO_FILE = REPO_DIR / \"examples\" / \"c5image.tif\"\n",
"REPO_URL = \"https://github.com/AdaptiveMotorControlLab/CellSeg3D.git\"\n",
"\n",
Comment thread
C-Achard marked this conversation as resolved.
"\n",
"def run(cmd, **kwargs):\n",
" print(\"+\", \" \".join(map(str, cmd)))\n",
" subprocess.check_call(cmd, **kwargs)\n",
"\n",
"\n",
"def cellseg3d_ok():\n",
" try:\n",
" import napari_cellseg3d\n",
" from napari_cellseg3d.dev_scripts import remote_inference\n",
"\n",
" print(\"CellSeg3D import OK.\")\n",
" return True\n",
"\n",
" except Exception as e:\n",
" print(\"CellSeg3D import failed:\")\n",
" print(type(e).__name__, e)\n",
" return False\n",
"\n",
"\n",
"def ensure_demo_data():\n",
" if DEMO_FILE.is_file():\n",
" print(f\"Demo data found: {DEMO_FILE}\")\n",
" return\n",
"\n",
" print(\"Demo data not found. Cloning CellSeg3D repository...\")\n",
"\n",
" if REPO_DIR.exists():\n",
" print(f\"Removing incomplete existing directory: {REPO_DIR}\")\n",
" shutil.rmtree(REPO_DIR)\n",
"\n",
" run(\n",
" [\n",
" \"git\",\n",
" \"clone\",\n",
" REPO_URL,\n",
" \"--branch\",\n",
" \"main\",\n",
" \"--single-branch\",\n",
" str(REPO_DIR),\n",
" ]\n",
" )\n",
"\n",
" if not DEMO_FILE.is_file():\n",
" raise FileNotFoundError(\n",
" f\"Expected demo file was not found after cloning: {DEMO_FILE}\"\n",
" )\n",
"\n",
" print(f\"Demo data ready: {DEMO_FILE}\")\n",
"\n",
"\n",
"package_ok = cellseg3d_ok()\n",
"installed_package = False\n",
"\n",
"if not package_ok:\n",
" print(\"Installing CellSeg3D...\")\n",
"\n",
" if shutil.which(\"uv\") is None:\n",
" run([sys.executable, \"-m\", \"pip\", \"install\", \"-q\", \"uv\"])\n",
" else:\n",
" print(\"uv already installed.\")\n",
"\n",
" run(\n",
" [\n",
" \"uv\",\n",
" \"pip\",\n",
" \"install\",\n",
" \"--system\",\n",
" \"napari-cellseg3d\",\n",
" ]\n",
" )\n",
"\n",
" installed_package = True\n",
"\n",
"else:\n",
" print(\"CellSeg3D already available — skipping package install.\")\n",
"\n",
"\n",
"ensure_demo_data()\n",
"\n",
"\n",
"if installed_package:\n",
" print(\"Restarting runtime to reload installed binary dependencies...\")\n",
" print(\n",
" \"Colab may show this as a crash, but it is expected. \"\n",
" \"After the runtime reconnects, run the notebook again from the beginning. \"\n",
" \"This cell should then skip installation and continue normally.\"\n",
" )\n",
"\n",
" time.sleep(1)\n",
" os.kill(os.getpid(), 9)\n",
"\n",
"else:\n",
" print(\"Setup complete.\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"<div style=\"\n",
" padding: 12px 16px;\n",
" border-left: 5px solid #f59e0b;\n",
" border-radius: 6px;\n",
" margin: 12px 0;\n",
"\">\n",
" <b>⚠️ Runtime restart is required after installation</b><br>\n",
"The runtime must be restarted after installing CellSeg3D to use the newly installed package. \n",
"\n",
"<b>The notebook will \"crash\" after installing, but this is expected, you may simply run the notebook again from the beginning after the runtime restarts.</b>\n",
"</div>"
]
},
{
Expand Down
Loading