docs(tutorial): run the whole pipeline at build, fail loudly on an empty mask - #55
Draft
xuefei-wang wants to merge 2 commits into
Draft
docs(tutorial): run the whole pipeline at build, fail loudly on an empty mask#55xuefei-wang wants to merge 2 commits into
xuefei-wang wants to merge 2 commits into
Conversation
…n empty mask
The tutorial is the only end-to-end check that the pieces of this package work
together, so every step should actually execute: raw image -> cellSAM
segmentation -> cell-type prediction -> visualization.
Two things had drifted from that:
- The napari screenshots were replaced with prose ("Static documentation builds
do not execute or embed GUI screenshots"), so the rendered docs no longer
showed the segmentation or the cell-type layers. Restore the two hide-cell
`nim.screenshot` cells and their `<img>` embeds, matching the tutorial as of
616d4b5. `docs/_static/_generated` is already gitignored, so the images stay
build artifacts.
- A user reported "the cell type prediction result appears empty". The only
post-segmentation check verified the mask *shape*, and a degenerate
all-background mask has the correct shape, so it passed; predict() then
returned [] and the DataFrame rendered empty with nothing to explain it.
Turn the shape check into a hard assert, add a cell-count assert, and report
the number of cells detected, so a failed segmentation stops the tutorial at
the point of failure.
Supersedes #54, which took the opposite approach (defaulting to the archive's
precomputed mask); per review, the computation must not be replaced.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FwCG7rydRT4EWWhuerxuuT
xuefei-wang
marked this pull request as draft
August 6, 2026 22:33
cellSAM's segmentation labels are not contiguous, so `int(mask.max())` under "Number of cells detected" reported the largest label ID rather than the cell count. The rendered page then contradicted itself: the guard cell showed 4644 while "Total number of cells" showed 1743 after relabel_sequential -- and 1743 is what predict() returns. Count distinct nonzero labels instead. Verified with a full docs build running real cellSAM segmentation (not the archive's precomputed mask, whose labels are already contiguous, which is why this only surfaces on a from-scratch run): guard cell, cell-type total, and the prediction DataFrame now all report 1743. The empty-mask assertion is unchanged. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01BHtuHjUExCH8bvCowX7GJ3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #54. Per @rossbar's review there, the tutorial must stay a real end-to-end demonstration (raw image → segmentation → cell-type prediction) since it is the only integration check that the pieces of this package work together. #54 took the opposite approach — defaulting to the archive's precomputed mask — and is being closed.
This PR keeps every step executing and fixes the two places where that had drifted.
1. Restore the napari screenshots
masterreplaced bothnim.screenshotcells with prose:so the rendered docs no longer show the segmentation or the cell-type layers. This restores the two
hide-cellscreenshot cells and their<img>embeds, matching the tutorial as of 616d4b5.docs/_static/_generatedis already in.gitignore, so the images remain build artifacts.2. Fail loudly on an empty segmentation
A user reported "the cell type prediction result appears empty." The only post-segmentation check verified the mask shape:
A degenerate all-background mask has the correct shape, so this passed.
predict()then returned[]for a mask with no cells and the DataFrame rendered empty, with nothing to explain it. Now:A failed or misconfigured segmentation now stops the tutorial where it actually breaks, and the cell count is useful output in its own right.
Result
Execution structure now matches the 616d4b5 snapshot:
{code-cell}scellsam_pipelinenim.screenshotcalls(24 vs 23 is the
download_modelcell added on master since 616d4b5; the guard replaces the old shape-check cell 1:1.)Nothing is precomputed — the two remaining
ds["segmentations/…"]mentions are prose noting the archive's masks exist, unchanged from 616d4b5, with no cell loading them.Verification
docs/site/tutorial.mdonly, 53 insertions / 8 deletions.ast.parse); code fences balanced; no non-executedpythonblocks (the 2 remaining plain fences are thebashinstall snippets, as on master).cellSAM,napari, andjupytextare not installed in this environment, so the screenshot cells and thecellsam_pipelinerun have not been exercised here — that needs a docs-env build.Out of scope
masterand the #54 branch also disagree on the wording of the abstention note. This PR leavesmaster's wording untouched.🤖 Generated with Claude Code
https://claude.ai/code/session_01FwCG7rydRT4EWWhuerxuuT