Skip to content
Open
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
4 changes: 4 additions & 0 deletions docs/welcome.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ and choose the correct tool to use:
Many buttons have tooltips to help you understand what they do.
Simply hover over them to see the tooltip.

.. tip::
To try the plugin without your own data, download & open the small demo volume from
**File > Open Sample > CellSeg3D > Demo volume (c5image)**.


Documentation contents
--------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Here is a very small volume (from [IDR project 853](https://idr.openmicroscopy.org/webclient/?show=project-853)) to test on.
All credits to the original authors of the data.
You can install, launch `napari`, activate the CellSeg3D plugin app, and drag & drop this volume into the canvas.
You can install, launch `napari`, activate the CellSeg3D plugin app, and either drag & drop this volume into the canvas or open it from `File > Open Sample > CellSeg3D > Demo volume (c5image)`.
Then, for example, run the `Inference` module with one of our models.

See [CellSeg3D documentation](https://adaptivemotorcontrollab.github.io/CellSeg3D/welcome.html) for more details.
53 changes: 53 additions & 0 deletions napari_cellseg3d/_sample_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""Sample data contributed to napari's File > Open Sample menu."""

import hashlib
import urllib.request
from pathlib import Path

from napari_cellseg3d.utils import LOGGER as logger

C5IMAGE_NAME = "c5image.tif"
C5IMAGE_REPO_FILE = Path(__file__).parents[1] / "examples" / C5IMAGE_NAME
C5IMAGE_CACHE_FILE = Path(__file__).parent / "res" / "sample_data" / C5IMAGE_NAME
C5IMAGE_URL = (
"https://raw.githubusercontent.com/AdaptiveMotorControlLab/"
f"CellSeg3D/main/examples/{C5IMAGE_NAME}"
)
C5IMAGE_SHA256 = "9bb5a3da2ade6f66899da7247ca0b18c6c7adb43b9bd6b2c3869a32945a7d9ff"


def _sha256(path: Path) -> str:
return hashlib.sha256(path.read_bytes()).hexdigest()


def _download(url: str, dest: Path, sha256: str) -> None:
dest.parent.mkdir(parents=True, exist_ok=True)
tmp = dest.with_suffix(dest.suffix + ".part")
logger.info(f"Downloading sample data from {url}")
try:
with urllib.request.urlopen(url) as response: # noqa: S310
tmp.write_bytes(response.read())
digest = _sha256(tmp)
if digest != sha256:
raise ValueError(
f"Checksum mismatch for {url}: expected {sha256}, got {digest}"
)
tmp.replace(dest)
finally:
tmp.unlink(missing_ok=True)


def _c5image_path() -> Path:
if C5IMAGE_REPO_FILE.is_file():
return C5IMAGE_REPO_FILE
if not C5IMAGE_CACHE_FILE.is_file():
_download(C5IMAGE_URL, C5IMAGE_CACHE_FILE, C5IMAGE_SHA256)
return C5IMAGE_CACHE_FILE


def c5image():
"""Small demo volume from IDR project 853 (see examples/README.md)."""
from tifffile import imread

metadata = {"name": "c5image", "colormap": "inferno"}
return [(imread(_c5image_path()), metadata, "image")]
20 changes: 20 additions & 0 deletions napari_cellseg3d/_tests/test_sample_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from napari_cellseg3d import _sample_data


def test_c5image_from_repo():
assert _sample_data.C5IMAGE_REPO_FILE.is_file()
layers = _sample_data.c5image()
assert len(layers) == 1
data, meta, layer_type = layers[0]
assert data.shape == (124, 86, 94)
assert meta["name"] == "c5image"
assert layer_type == "image"


def test_c5image_open_sample(make_napari_viewer_proxy):
assert _sample_data.C5IMAGE_REPO_FILE.is_file()
viewer = make_napari_viewer_proxy()
viewer.open_sample("napari-cellseg3d", "c5image")
assert viewer.layers[-1].name == "c5image"
assert viewer.layers[-1].data.shape == (124, 86, 94)
assert viewer.layers[-1].colormap.name == "inferno"
9 changes: 9 additions & 0 deletions napari_cellseg3d/napari.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ contributions:
title: Create Trainer widget
python_name: napari_cellseg3d.plugins:Trainer

- id: napari-cellseg3d.sample_c5image
title: Load demo volume (c5image)
python_name: napari_cellseg3d._sample_data:c5image


widgets:
- command: napari-cellseg3d.load
Expand All @@ -40,3 +44,8 @@ contributions:

- command: napari-cellseg3d.help
display_name: Help/About...

sample_data:
- key: c5image
display_name: Demo volume (c5image)
command: napari-cellseg3d.sample_c5image
Loading