Skip to content

Commit ad5d2bb

Browse files
alxndrkalininclaude
andcommitted
fix: address code review and Copilot feedback on PR #33
Code review fixes: - Fix regionprops() missing spacing tuple conversion for cucim compat - Remove unnecessary asnumpy(distance).shape — .shape works on both devices Copilot feedback fixes: - Make downscale_xy_only/filter_mode keyword-only in downscale_and_filter to preserve positional arg compatibility - Make mask/dilate_seeds keyword-only in segment_watershed, keep ball_size as 3rd positional arg for backward compat - Replace assert with ValueError for filter_shape validation - Fix numpy scalar formatting in feature_extraction_3d notebook (np.issubdtype check instead of isinstance(x, float)) - Use uv sync + uv run in notebooks CI workflow (matches lint-format.yml) - Remove dangling [tool.uv.sources] iohub entry from pyproject.toml Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 575f9e7 commit ad5d2bb

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

.github/workflows/notebooks.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ jobs:
2121
- name: set up python
2222
run: uv python install 3.11
2323

24-
- name: install jupyter
25-
run: uv pip install jupyter
24+
- name: install dependencies
25+
run: uv sync --extra examples
2626

2727
- name: convert notebooks to scripts
2828
run: |
2929
for nb in examples/notebooks/*.ipynb; do
30-
jupyter nbconvert --to script "$nb" --output-dir examples/scripts
30+
uv run jupyter nbconvert --to script "$nb" --output-dir examples/scripts
3131
done
3232
3333
- name: commit generated scripts

cubic/feature/voxel.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ def regionprops(
1616
spacing: list[float] | None = None,
1717
) -> list:
1818
"""Extract region-based morphological features."""
19+
# cucim requires spacing as tuple for kernel memoization
20+
if spacing is not None:
21+
spacing = tuple(spacing)
1922
return measure.regionprops(label_image, intensity_image, spacing=spacing)
2023

2124

cubic/segmentation/segment_utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ def downscale_and_filter(
1818
downscale_factor: float = 0.5,
1919
downscale_order: int = 3,
2020
downscale_anti_aliasing: bool = True,
21-
downscale_xy_only: bool = True,
2221
filter_size: int = 3,
2322
filter_shape: str = "square",
23+
*,
24+
downscale_xy_only: bool = True,
2425
filter_mode: str = "nearest",
2526
) -> npt.ArrayLike:
2627
"""Subsample and filter image prior to segmentation.
@@ -58,10 +59,8 @@ def downscale_and_filter(
5859
"""
5960
from ..scipy import ndimage as _ndimage
6061

61-
assert filter_shape in [
62-
"square",
63-
"circular",
64-
], "Filter shape must be 'square' or 'circular'."
62+
if filter_shape not in ("square", "circular"):
63+
raise ValueError("filter_shape must be 'square' or 'circular'.")
6564

6665
if downscale_factor < 1.0:
6766
if downscale_xy_only:
@@ -283,8 +282,9 @@ def remove_thin_objects(label_image, min_z=2):
283282
def segment_watershed(
284283
image: npt.ArrayLike,
285284
markers: npt.ArrayLike | None = None,
286-
mask: npt.ArrayLike | None = None,
287285
ball_size: int = 15,
286+
*,
287+
mask: npt.ArrayLike | None = None,
288288
dilate_seeds: bool = False,
289289
) -> npt.ArrayLike:
290290
"""Segment image using watershed algorithm.
@@ -335,7 +335,7 @@ def segment_watershed(
335335
footprint = to_same_device(footprint, distance)
336336
coords = feature.peak_local_max(distance, footprint=footprint, labels=image)
337337

338-
seed_mask = np.zeros(asnumpy(distance).shape, dtype=bool)
338+
seed_mask = np.zeros(distance.shape, dtype=bool)
339339
seed_mask[tuple(asnumpy(coords).T)] = True
340340
seed_mask = to_device(seed_mask, device)
341341
if dilate_seeds:

examples/notebooks/feature_extraction_3d.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@
158158
"print(\"-\" * len(header))\n",
159159
"for i in range(n_objects):\n",
160160
" row = \" \".join(\n",
161-
" f\"{props_np[c][i]:>16.2f}\"\n",
162-
" if isinstance(props_np[c][i], float)\n",
161+
" f\"{float(props_np[c][i]):>16.2f}\"\n",
162+
" if np.issubdtype(type(props_np[c][i]), np.floating)\n",
163163
" else f\"{int(props_np[c][i]):>16d}\"\n",
164164
" for c in key_cols\n",
165165
" )\n",

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,3 @@ convention = "numpy"
8282

8383
[tool.ruff.lint.isort]
8484
length-sort = true
85-
86-
[tool.uv.sources]
87-
iohub = { git = "https://github.com/czbiohub-sf/iohub" }

0 commit comments

Comments
 (0)