Skip to content
Draft
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
7 changes: 5 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ src/morphobricks_preprocessing/
preprocessing's discovery and pairing; RunInputs.open raises
UnrecordedFilesError for them (PP-8b, contract §9.1)
run_inputs_text.py the texts RunInputs refuses a run with (moved from run_inputs.py in PP-12)
open_checks.py OPEN_PHASES, counted: the phases of opening a run told to a progress callback
(run_inputs.open_checked: RunInputs.open with checking=; #574) (pure)
run_inputs_stopped.py stopped_run_refusal: the one reader of discovery_report.json for the
bricks; RunInputs.open raises RunStoppedError (RUN_FOLDER_STOPPED, the
stopped run's error issues as the report records them) or
Expand Down Expand Up @@ -312,8 +314,9 @@ src/morphobricks_preprocessing/
on the Preprocessing app's finished run; cellpose_install.py installs
Cellpose 4.2.1.1 only on the user's tick (restart when numpy/opencv changed);
notebook_mask_register.py register_step(app, segmentation): cell 5, a
declaration to tick per mask type, then the app's own check, Masks answer,
save, run and Describe the masks
question per mask type (objects or binary, none chosen; objects registered),
then the app's own check, Masks answer, save, run and Describe the masks,
each step shown by notebook_register_progress.py RegisterWait (#574)
notebook_cellpose_preview.py MaskResult, preview_figures: the example result as
ZeroCostDL4Mic draws it (cellpose.plot.show_segmentation), one result per mask
notebook_cellpose_channels.py ChannelPicker, MaskTarget: the output's masks (Both:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ v0.5.1: no run before v0.5.1 is read.)
## Unreleased

- **The run's masks counter ends at N of N (follow-up of #567).** The mask header check reported "done of N" before each mask and nothing after the last, so the run's wait stopped at "N-1 of N" (preflight's closing `("masks", 1, 1, "")` is a placeholder the wait ignores unless the total is 1). The check now also reports `(total, total, "")` after the last mask; what is read and recorded is unchanged. A stray docstring in `notebook_progress` (the one of `PREPARING` sat after `COUNTED_PHASES`) is back under `PREPARING`. Tests: `tests/test_run_checking_progress.py`, `tests/test_notebook_progress.py`.
- **Cellpose cell 5, Register the masks: a clear question, and every step shown as it goes (#574, items 6 and 7; owner's Colab test of 26 November 2026).** Item 6: the tick box "Declare Cells as separate objects" under a TOML preview was awkward. Each mask type is now asked what it is, with no answer chosen: "Each object has its own number (label image: every cell/nucleus is a separate object)" or "Foreground / background only (binary mask)", with one sentence on why: "We ask because the two are measured differently, and we never guess which one a file is." The TOML is shown only folded (`<details>`) under the question. What is recorded is unchanged (`representation = "instances"` through the app's *Masks* question), and so is the refusal while a mask type is unanswered (the button stays disabled, saying "choose what Cells is", and pressing does nothing). Cellpose gives each object its own number, so the binary answer is refused beside the button, saying so; nothing records it (`BINARY_REFUSED`). Item 7: after **Register the masks** something ran for a long time with nothing in cell 5. Measured with a patched opener (`builtins.open`, bytes read per file) on main: per image of a `verify_content` run (the notebook's default), the press reads every image whole 4 times, each for its content SHA-256 (cell 5's own checks of the segmented run, the app's run, its check before it publishes, and the app's tissue-mask step that opens the run after it), and every mask whole 5 times (the run and its check before publishing, the mask step's fingerprints before and after reading, and its pixels for the piece counts, 1 per mask); a press that stops for the axes reads every image whole once, and showing cell 5 once more. The app drew its own waits in cell 3. Every one of these reads is a check or the data itself, so none was removed: what is read, and the run folder, are unchanged (normalized digests of every file of the run folder, and the reads per file, equal before and after). Cell 5 now shows the press with the waits of #567 (`notebook_progress.Wait` and its ticking thread, `notebook_register_progress.RegisterWait`): "Step k of 5 · <step>" with the elapsed time, and under it the step's own line: the run's checks counted ("Reading each image whole for its content SHA-256 · 2 of 200 · ctrl/rep1/a.tif"), through `segmentation_cellpose_run.open_run(checking=)` (`run_inputs.open_checked` and `open_checks`, the same code as #575, unchanged checks), and the app's own wait lines of its folder check, run and mask step, copied as the app draws them; then "Took m:ss." (or "Stopped after m:ss."). The button is disabled while it goes. Cell 5's text is unchanged. `tests/test_mask_register_progress.py`.
- **`piece_counts` counts the pieces of masks of objects by runs (#69).** It sorted every pixel (`np.unique(..., return_inverse=True)`, most of its time) and labelled each label again in its bounding box, so labels spread over the plane read it once each. Each row is now cut into runs of one label and runs of one label in neighbouring rows that touch (8-connected, from `masks.binary.STRUCTURE`) are joined with `scipy.sparse.csgraph.connected_components` (new pure module `mask_pieces`; `mask_scan.piece_counts` is the same function, imported). On pixel-scale masks (noise, checkerboards) runs are almost pixels and that graph needs several times the memory of the sort, so above `RUNS_PER_PIXEL_LIMIT` = 0.25 runs per pixel the former route is taken, unchanged. The results are byte-identical either way (labels in the mask's pixel type, counts `int64`): a property test compares both routes, forced and as chosen, with the former function, kept in the test as the reference, on random masks of every label pixel type (touching labels, holes, single pixels, edges, corners, no background, empty) and on the benchmark masks; every digest of `tools/benchmark_kernels.py --group masks` is unchanged, including its new pixel-scale cases (`benchmark_inputs.pixel_mask`). On the benchmark machine `piece_counts` of the 4096 px cells mask went from 2.1 to 2.3 s to 0.07 to 0.10 s and one position's scan from 4.9 to 5.1 s to 0.9 to 1.0 s; the pixel-scale masks take the time and memory they took before (`docs/benchmarks.md`). Outside the former results: a mask with a side of length 0 now has no labels, where the former function failed inside SciPy; a mask that is not 2D is refused with a `ValueError` saying so (it was a SciPy `RuntimeError`, or no labels when it was all background). **The mask scan refuses a mask plane of no pixels** (`mask_without_pixels`, naming the mask): before, SciPy's failure in `piece_counts` was its only guard, and with no labels such a plane would have counted as an image and as a plane of at most one label in its mask type's kind. `pair_counts` and the repeated pair work of #69 are not changed. `tests/test_mask_pieces.py`, `tests/test_mask_scan.py`.
- **The run shows its own folder and header check, and that check is no longer quadratic (owner Colab test of v0.9.0, 25 November 2026).** On a large mixed-layout experiment, *Run* showed "Preparing: checking the folders and the image headers again · 0:00 elapsed" for 10-15 minutes before the first image: the run checks every header again (bound to its fingerprint) with no progress reported, and the elapsed time was redrawn only on a progress report. The run now reports that check through `RunMode(checking=...)` (preflight's `(phase, done, total, path)`, operational only like `workers`; `run_experiment`'s parameters are unchanged), and the notebook shows each phase and each header of how many ("Preparing: reading the image headers again · 120 of 24,000"), with the elapsed time redrawn every second by `Wait.ticking()` while the run works. While it goes, the notebook says that a cell run meanwhile waits for it, and how to interrupt it. Two steps of the check were O(n²): each image's staging key took `MetadataReport.dtype` (a pass over every header) and the mask-name screen compared each image's name with every other one (`mask_names._mask_owner` now looks up the prefixes of the name). The outputs are byte for byte the same (`plane_histograms.csv`, `experiment_design.csv`, `image_qc.csv` of a 4,800-image three- and two-channel tree); the check before the first image took 30.0 s → 10.3 s for 12,000 images and 72-75 s → 24-27 s for 24,000 on local disk (`tests/test_run_checking_progress.py`). In a `verify_content` run (the notebook's default, and any run on a fresh output folder) the run then reads every image whole for its content SHA-256 before the first pixel is read: on Google Drive that pass, not the header check, is what took minutes (owner: about 200 images, 10-15 minutes). It is now reported too, as the phase `contents` (`run.phases.CONTENTS`, "Preparing: reading each image whole for its content SHA-256 · 12 of 200"); what is read and verified is unchanged.
- **Earlier work that does not record its experiment folder no longer leaves the stepper at a dead end (owner's Colab test of v0.9.0 at ca3b3c6).** An output folder holding only saved answers (here an older version's `morphobricks.draft.json`) showed *"The experiment folder it is of is not recorded … Enter the experiment folder and click Check folder"*: the stepper has no *Check folder* button (its check, *Looks right: read all image headers*, stays disabled until **Scan the folders**), and entering the folder showed the same message again, with no scan and no picture. Now the experiment folder entered is scanned at once on the stepper (folder walk and one picture; nothing is written), the message names the stepper's own buttons, and the check, on the user's click, reads the saved answers as always. Saved answers written by another version of the software (`DraftFileError` `unknown_version`, `unknown_key` or `spec_commit_mismatch`; the owner's file is format 3, `unknown_version`) are not earlier work (`EarlierWork.old_answers`): one line says they are not used and the file is left as it is, and the experiment folder entered is scanned and shown as above (an early **Scan the folders** click, before the typed folder reached the kernel, is made good when it arrives). The same scan follows a record and a run that name different folders. Each message names the buttons of the layout shown (the stacked pages say **Check folder**). Tests: `tests/test_notebook_restore.py`.
Expand Down
17 changes: 12 additions & 5 deletions docs/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,18 @@ run the experiment in the app of cell 3. Then:
reuses it) and **Segment** (it reuses the loaded model, and says in one line exactly which
model and settings it will use, in amber with what differs when the last Preview used
others). One line after the batch points to cell 5.
- **5. Register the masks** shows, for each mask type cell 4 wrote, the declaration it would
add (`[masks.Cells]` with `source_type = "Cells"` and `representation = "instances"`). Tick
each one and press **Register the masks**: the app of cell 3 then checks the folders again
with the masks folder, answers the mask on **Masks**, saves the description, runs again
(the histograms of unchanged images are reused) and describes the masks. Masks written into
- **5. Register the masks** asks, for each mask type cell 4 wrote, what the mask is, with no
answer chosen: *Each object has its own number (label image: every cell/nucleus is a
separate object)* or *Foreground / background only (binary mask)*. They are measured
differently, and the notebook never guesses which one a file is. Cellpose gives each object
its own number, so only the first is registered (the second is refused, saying why); the
declaration it adds (`[masks.Cells]` with `source_type = "Cells"` and `representation =
"instances"`) is shown folded under the question. Answer each one and press **Register the
masks**: the app of cell 3 then checks the folders again with the masks folder, answers the
mask on **Masks**, saves the description, runs again (the histograms of unchanged images are
reused) and describes the masks. Each step is shown under the button as it goes ("Step 4 of
5 · Running again…", its elapsed time, and the step's own line: the image read now, "n of
N"), then how long it took. Masks written into
the masks folder the run already used are fine. If its folder check asks you to confirm the
axes again, do it in cell 3 (step **Axes**) and press the button again (or run cell 5
again). It refuses, changing nothing, a mask type that collides with a mask already declared,
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ baseline = "tools/code_rules_baseline.json"
"morphobricks_preprocessing.name_issues" = "pure"
"morphobricks_preprocessing.run.phases" = "pure"
"morphobricks_preprocessing.ome_header" = "io"
"morphobricks_preprocessing.open_checks" = "pure"
"morphobricks_preprocessing.tiff_colour" = "io"
"morphobricks_preprocessing.tiff_axes" = "io"
"morphobricks_preprocessing.rgb_override" = "pure"
Expand Down Expand Up @@ -195,6 +196,7 @@ baseline = "tools/code_rules_baseline.json"
"morphobricks_preprocessing.notebook_cellpose_summary" = "ui"
"morphobricks_preprocessing.notebook_cellpose_view" = "ui"
"morphobricks_preprocessing.notebook_mask_register" = "ui"
"morphobricks_preprocessing.notebook_register_progress" = "ui"
"morphobricks_preprocessing.notebook_preprocessing_cellpose" = "ui"
"morphobricks_preprocessing.notebook_stop" = "ui"
"morphobricks_preprocessing.notebook_channels" = "ui"
Expand Down
Loading
Loading