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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

Key dependencies: `numpy`, `scipy`, `tifffile`, `imageio`, and the MorphoBricks bricks `morphobricks-preprocessing` and `morphobricks-normalization` from GitHub at pinned tags (normalization `v0.7.1`; preprocessing `v0.7.0` — Spec ADR 0005 steps 2 and 2b: resolver contract v3, `read_objects`, the conversion helpers; v0.6.1 records the verified mask fingerprint; v0.7.0 raises `RunStoppedError` for a stopped run) (core, required; normalization is declared at the tag the preprocessing tag pins, owner decision D-h, checked by `tests/test_dependency_pins.py`; histograms, the plane table, plane IDs, pooling and normalization parameters are imported from `morphobricks_normalization`, not from their deprecated preprocessing paths). Optional extras: `ipywidgets`, `matplotlib`, `pillow`, `tqdm`, `joblib`, `jl-hidecode` (notebook extra); `torch` (optional `cellpatcher.torch_dataset` adapter only — never a core dependency); `morphobricks-preprocessing[zarr]` at the same tag (`zarr` extra, formerly `preprocessing`: OME-Zarr images and OME-NGFF label masks).

Current health snapshot (2026-11-16, v0.7.1 release prep: preprocessing `v0.6.0` (then `v0.6.1`, see the CHANGELOG) and normalization `v0.7.0` installed from their tags in a fresh venv, Linux): `.[test,zarr,notebook]` with CPU `torch` 2.15.0: 3000 passed, 0 skipped on Python 3.11 before #123, and 3004 passed, 0 skipped on Python 3.13 after it (`python tools/check.py`, code rules and Ruff clean; the smaller extras were not run locally). CI also runs `.[test]` on `windows-latest` (`pytest-windows`): 2899 passed, 42 skipped after #123, every skip an extra that job does not install (zarr, notebook, torch). Preprocessing refuses Z>1 inputs (2-D planes only), so the tests that built Z-stacks use T.
Current health snapshot (2026-11-17, v0.8.0 release prep: preprocessing `v0.7.0` and normalization `v0.7.1` installed from their tags in a fresh venv, Python 3.13, Linux): `.[test,zarr,notebook]` with CPU `torch` 2.15.0: 3085 passed, 0 skipped (pytest run in two halves of 41 test files, 955 + 2130; code rules and Ruff clean with `python tools/check.py --rules`; the smaller extras were not run locally). CI also runs `.[test]` on `windows-latest` (`pytest-windows`): 2980 passed, 42 skipped on #133, every skip an extra that job does not install (zarr, notebook, torch). Preprocessing refuses Z>1 inputs (2-D planes only), so the tests that built Z-stacks use T.

---

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Since v0.2.0 CellPatcher reads image and mask files only through a run of the
(v0.5): describe the experiment and publish its description in the preprocessing notebook, run it
on your experiment first, then point CellPatcher to the run's output folder. A run without a
published description is refused (`A_DESCRIPTION_REQUIRED`). What changed, with the migration notes for the
other bricks, is in the [CHANGELOG](notebooks/CellPatcher/CHANGELOG.md) (v0.2.0rc1 to v0.7.1).
other bricks, is in the [CHANGELOG](notebooks/CellPatcher/CHANGELOG.md) (v0.2.0rc1 to v0.8.0).

- **Normal user / manual workflow:** open `notebooks/CellPatcher/CellPatcher.ipynb` and give it the preprocessing run's output folder.
- **Choosing a patching strategy:** open `notebooks/CellPatcher_Strategy_Examples/CellPatcher_Strategy_Examples.ipynb`: each strategy on one image of your preprocessing run, nothing written.
Expand Down Expand Up @@ -120,7 +120,7 @@ Open the notebook in Colab:
**A release, anywhere (Google Colab included):**

```bash
pip install "cellpatcher[notebook,zarr] @ git+https://github.com/CellMigrationLab/CellPatcher.git@v0.7.1"
pip install "cellpatcher[notebook,zarr] @ git+https://github.com/CellMigrationLab/CellPatcher.git@v0.8.0"
```

The notebook's first cell does this on Colab (pinned to its `RELEASE_TAG`), mounts Google Drive and
Expand Down
2 changes: 1 addition & 1 deletion docs/normalization_contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ brick's

| Rule | Detail |
|---|---|
| Dependencies | `morphobricks-preprocessing` (unreleased: `v0.7.0`, `RunStoppedError`; `v0.6.1` in CellPatcher v0.7.1; `v0.6.0` in v0.7.0, Spec ADR 0005 steps 2 and 2b; `v0.5.6` in v0.6.2; `v0.5.5` in v0.6.1; `v0.5.3` in v0.6.0; `v0.5.2` in v0.5.0; `v0.5.1` in v0.4.0; `v0.5.0` in v0.3.0; `v0.4.0` in v0.2.0, `v0.4.0rc5` in v0.2.0rc3, `v0.4.0rc4` in v0.2.0rc2, `v0.4.0rc2` in v0.2.0rc1) and `morphobricks-normalization` (unreleased: `v0.7.1`, the tag preprocessing v0.7.0 pins; `v0.7.0` in CellPatcher v0.7.0 and v0.7.1, the tag preprocessing v0.6.0 and v0.6.1 pin; `v0.6.1` in CellPatcher v0.6.1 and v0.6.2, the tag preprocessing v0.5.5 and v0.5.6 pin; `v0.6.0` in CellPatcher v0.6.0, the tag preprocessing v0.5.3 pins; `v0.5.0` in CellPatcher v0.5.0, the tag preprocessing v0.5.2 pins; `v0.4.0` in CellPatcher v0.4.0, the tag preprocessing v0.5.1 pins; `v0.3.4` in v0.2.0 and v0.3.0: the tag preprocessing `v0.5.0` pins; `v0.3.3` in v0.2.0rc3, `v0.3.2` before) are core dependencies, pinned to tags in `setup.py`; normalization at the tag the preprocessing tag pins (owner decision D-h, checked by `tests/test_dependency_pins.py`). The `zarr` extra (`pip install "cellpatcher[zarr]"`, formerly `preprocessing`) installs `morphobricks-preprocessing[zarr]` at the same tag, for OME-Zarr images. Histograms, the plane table, plane IDs, pooling and normalization parameters, which moved to the normalization brick, are imported from `morphobricks_normalization`. |
| Dependencies | `morphobricks-preprocessing` (`v0.7.0` since CellPatcher v0.8.0, `RunStoppedError`; `v0.6.1` in v0.7.1; `v0.6.0` in v0.7.0, Spec ADR 0005 steps 2 and 2b; `v0.5.6` in v0.6.2; `v0.5.5` in v0.6.1; `v0.5.3` in v0.6.0; `v0.5.2` in v0.5.0; `v0.5.1` in v0.4.0; `v0.5.0` in v0.3.0; `v0.4.0` in v0.2.0, `v0.4.0rc5` in v0.2.0rc3, `v0.4.0rc4` in v0.2.0rc2, `v0.4.0rc2` in v0.2.0rc1) and `morphobricks-normalization` (`v0.7.1` since CellPatcher v0.8.0, the tag preprocessing v0.7.0 pins; `v0.7.0` in CellPatcher v0.7.0 and v0.7.1, the tag preprocessing v0.6.0 and v0.6.1 pin; `v0.6.1` in CellPatcher v0.6.1 and v0.6.2, the tag preprocessing v0.5.5 and v0.5.6 pin; `v0.6.0` in CellPatcher v0.6.0, the tag preprocessing v0.5.3 pins; `v0.5.0` in CellPatcher v0.5.0, the tag preprocessing v0.5.2 pins; `v0.4.0` in CellPatcher v0.4.0, the tag preprocessing v0.5.1 pins; `v0.3.4` in v0.2.0 and v0.3.0: the tag preprocessing `v0.5.0` pins; `v0.3.3` in v0.2.0rc3, `v0.3.2` before) are core dependencies, pinned to tags in `setup.py`; normalization at the tag the preprocessing tag pins (owner decision D-h, checked by `tests/test_dependency_pins.py`). The `zarr` extra (`pip install "cellpatcher[zarr]"`, formerly `preprocessing`) installs `morphobricks-preprocessing[zarr]` at the same tag, for OME-Zarr images. Histograms, the plane table, plane IDs, pooling and normalization parameters, which moved to the normalization brick, are imported from `morphobricks_normalization`. |
| Version | Installed from GitHub at a pinned commit or tag, recorded in `setup.py` and raised deliberately. |
| Formats | Since v0.2.0 (CP-1) the preprocessing run is read through the brick's `RunInputs` (its design v0.4 §6), which needs `run_manifest.json` manifest version `2` (preprocessing v0.4), or `3` for a run with the brick's `--verify-content` (preprocessing v0.4.0rc5, CellPatcher v0.2.0rc3), or `4` for a described run (preprocessing v0.5.0, CellPatcher v0.3.0, which refuses a run without a published description: `A_DESCRIPTION_REQUIRED`); since preprocessing v0.5.1 only `4` is read, and since preprocessing v0.5.2 (the W3 pins) only `5`, whose file entries record their `channel_ids` (an older manifest is refused, `preprocessing_run_refused`, never converted) and `RunInputs.open` itself refuses a run without a description, and the `plane_histograms.csv` version that brick reads; CellPatcher pins no version of its own. Any run `RunInputs` refuses is an error. |
| Needed for | Normalization (every scope), OME-Zarr images and labels, and plane-by-plane image reading. |
Expand Down
57 changes: 33 additions & 24 deletions notebooks/CellPatcher/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,26 @@ Release v0.3.0
Pin preprocessing v0.4.0rc4; prepare v0.2.0rc2

---
## [Unreleased] - Preprocessing v0.7.0, normalization v0.7.1; a stopped preprocessing run's refusal passed on (#126); D47 documented (#124)

For v0.7.2 or v0.8.0.

### Fixed
## [0.8.0] - 2026-11-17 - Preprocessing v0.7.0, normalization v0.7.1; a stopped run's refusal passed on (#126); TIFFs written as planes (#129, #131); channel IDs on every patch (#125); D47 documented (#124)

The v0.8.0 release (17 November 2026), from #127, #130, #132 and #133. A minor release because public API and
behaviour change: `write_array` to a TIFF without `axes` is refused (#131, **Breaking** below), `patches.csv` gains
the `channel_ids` column and `read_patch_table` refuses a table without it (#125), a stopped preprocessing run is
refused with preprocessing's own codes (`RUN_FOLDER_STOPPED`, `RUN_FOLDER_REPORT_UNREADABLE`) instead of
`preprocessing_run_refused` (#126), and the preprocessing pin moves to a new minor. It pins preprocessing `v0.7.0`
(`8865b72`; core and `zarr` extra; was `v0.6.1`) and normalization `v0.7.1` (`fcfaeac`; was `v0.7.0`), the tag
preprocessing `v0.7.0` pins (owner decision D-h). `__version__`, `setup.py` and every notebook (`RELEASE_TAG`,
`current_version`, `notebook_latest_versions.yaml`) are `0.8.0`. Pixels of every patch are unchanged; what changes
in the written files is listed under each **Changed** below. Bricks that pin CellPatcher pin `v0.8.0` together with
preprocessing `v0.7.0` and normalization `v0.7.1` (pip refuses two URLs for one package).

Reviewer's note on #126 (independent review of #133): for a folder that holds neither a `run_manifest.json` nor a
stopped run's report (no report, a `check` report or a provisional one), the refusal stays `preprocessing_run_refused`
but its suggested action now says to **give a written run or run preprocessing first** ("Give CellPatcher the output
folder of a preprocessing run that was written (it holds run_manifest.json), or run preprocessing on the experiment
first."); v0.7.1 said to run preprocessing again. A written run that is stale keeps the advice to run it again.

### Fixed (#126)
- **#126: a run preprocessing stopped on purpose is refused with preprocessing's own refusal, unchanged, and no
advice of CellPatcher's.** On an output folder where preprocessing stopped without writing a run (Spec `v29`: RGB
units beside fluorescence units, `R_HETEROGENEOUS_LAYOUT_NOT_ENABLED`), v0.7.1 refused with
Expand All @@ -93,7 +108,7 @@ For v0.7.2 or v0.8.0.
"again"); a written run that is stale (an image changed since, an older manifest) keeps the advice to run
preprocessing again, which fixes it. `tests/test_stopped_run.py`. Reworked from draft PR #128.

### Documented
### Documented (#124)
- **#124: decision D47 is kept and documented** (owner decision of 17 November 2026). In memory (`run_patching`,
the object scan, `CellSegmentationStrategy`) an integer cell-mode mask is instance labels used as stored, so a
0/1 integer region is one object, however many separate regions it has: an in-memory array carries no
Expand All @@ -102,7 +117,7 @@ For v0.7.2 or v0.8.0.
that a region passed to cell mode gives one large patch and to pass instance labels instead. No behaviour change;
`tests/test_cell_strategy.py` pins it through `run_patching`.

### Changed
### Changed (dependencies)
- **Dependencies:** pins preprocessing `v0.7.0` (`8865b72`; core and `zarr` extra; was `v0.6.1`) and
normalization `v0.7.1` (`fcfaeac`; was `v0.7.0`), the tag preprocessing `v0.7.0` pins (owner decision D-h).
Preprocessing v0.7.0 adds `RunStoppedError` and `RunReportUnreadableError` (#322), reports Spec `v29`
Expand All @@ -118,11 +133,9 @@ For v0.7.2 or v0.8.0.
golden `tests/fixtures/v062_parity/digests.json` and `tests/fixtures/shared_labeller/golden.json` pass unchanged
(no golden case writes a `-0.0`).

## [Unreleased] - write_array writes a TIFF as planes, laid out from the axes it is given (#131)
*#131 follows #129/#130 (PR #132).*

For v0.7.2. Follows #129/#130.

### Fixed
### Fixed (#131)
- **#131: `cellpatcher.io.write_array` writes a TIFF with an explicit photometric, never tifffile's guess from its
shape.** It called `tifffile.imwrite` without `photometric`, so an array with 3 or 4 along its first or last axis
(`CYX` or `YXC` channels) was written as an RGB(A) image, with tifffile's `DeprecationWarning`. As for exported
Expand All @@ -134,27 +147,25 @@ For v0.7.2. Follows #129/#130.
`tests/test_write_array_tiff.py` (3 and 4 channels in `CYX` and `YXC`, `ZCYX`, RGB declared as `CYX`/`YXC`,
the refusals, warnings as errors).

### Breaking (no backward compatibility, ADR 0002 AR10)
### Breaking: #131 (no backward compatibility, ADR 0002 AR10)
- **`write_array(path, array)` to a `.tif`/`.tiff` without `axes` is refused** (`ValueError` naming the fix:
pass `axes=`, for example `axes="YX"`, and `photometric="rgb"` for an RGB image), as are axes that do not
match the array, Y and X not last or followed by more than one axis, and `photometric="rgb"` on an array
without three channels just before Y and X or last; nothing is written then. `.npy` and the other formats
take no axes and are unchanged (`axes`/`photometric` are used for a TIFF only).

### Migration
### Migration (#131)
- Pass the array's axes: `write_array(path, image, axes="YX")` for one image, `axes="CYX"`/`"YXC"` for channels,
plus `photometric="rgb"` for an RGB image.

### Changed
### Changed (#131)
- Every caller passes what it knows: the 70 TIFF `write_array` calls in `tests/` (all of 2-D images and masks)
pass `axes="YX"`; no code under `src/`, `app/` or `notebooks/` calls it.
- `tools/code_rules_baseline.json` shrinks (the typed, documented `write_array`).

## [Unreleased] - TIFF patches written as planes, RGB only for an rgb unit (#129)

For v0.7.2. Found by the G4 adversarial suite (MorphoFeature draft PR #240, row A09) on `aca2c6c`.
*#129 (PR #130) was found by the G4 adversarial suite (MorphoFeature draft PR #240, row A09) on `aca2c6c`.*

### Fixed
### Fixed (#129)
- **#129: a TIFF patch is written with an explicit photometric, never tifffile's guess from its shape.**
`save_patch_array` called `tifffile.imwrite` without `photometric`, so a 3-channel fluorescence patch (`CYX`,
DNA/ACTIN/PHASE) was written as an RGB image (axes `SYX`), a 4-channel one as RGBA, and any patch 3 or 4 pixels
Expand All @@ -175,7 +186,7 @@ For v0.7.2. Found by the G4 adversarial suite (MorphoFeature draft PR #240, row
C strips; it is now written `planarconfig="contig"` (one Y/X page, the channels its samples), chosen from the
patch's `output_axes`, never its shape. Pixels, shape and dtype read back are unchanged.

### Changed
### Changed (#129)
- **Outputs:** a TIFF patch records its `channel_ids` (its C order) in its JSON image description as
`"channel_ids"`, beside the `"shape"` tifffile already wrote there (`TiffFile.shaped_metadata`); a patch without
channel IDs has none. A patch of 3 or 4 channels that is not of an `rgb` unit, and a patch 3 or 4 pixels wide
Expand All @@ -191,11 +202,9 @@ For v0.7.2. Found by the G4 adversarial suite (MorphoFeature draft PR #240, row
- `tests/test_patch_geometry.py` expects `image_type` as the last `PatchRegion` field; `tests/test_position_table.py`'s
stand-in `Fov` has an `image_type`. `tools/code_rules_baseline.json` shrinks (the typed `save_patch_array`).

## [Unreleased] - Channel IDs on every patch (#125)
*#125 (PR #127) was found by the S3.4 adversarial suite (MorphoFeature draft PR #240, gate G3).*

For v0.7.2. Found by the S3.4 adversarial suite (MorphoFeature draft PR #240, gate G3).

### Fixed
### Fixed (#125)
- **#125: every patch of a described run records its channel IDs, in its C order.** Without normalization and
without channel splitting, v0.7.1 recorded no channel ID at all (`c`, `channel_id` and `normalization_channels`
empty, on the patch and in `patches.csv`), so the patches of two units storing DNA, ACTIN and ACTIN, DNA could
Expand All @@ -214,7 +223,7 @@ For v0.7.2. Found by the S3.4 adversarial suite (MorphoFeature draft PR #240, ga
(without splitting) is refused: its patches hold every channel, so `c` would have labelled them with one ID
(review of #127).

### Changed
### Changed (#125)
- **Outputs:** `patches.csv` has one new last field column, `channel_ids` (before the dynamic `mask_fraction_*`
columns); every other column, value, patch file, `images.csv` and `positions.csv` is unchanged. The parity golden
`tests/fixtures/v062_parity/digests.json` changes in its 57 `patches.csv` digests only, one per table of every
Expand Down
6 changes: 3 additions & 3 deletions notebooks/CellPatcher/CellPatcher.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"appears when everything is ready.\n",
"\n",
"> **Colab users:** Step 0 connects your Google Drive (allow access in the window that opens)\n",
"> and installs CellPatcher **v0.7.1** from GitHub, which takes a minute or two. Keep the\n",
"> and installs CellPatcher **v0.8.0** from GitHub, which takes a minute or two. Keep the\n",
"> preprocessing output folder, your experiment and your results on Google Drive: in this\n",
"> notebook your Drive is the folder **/content/drive/MyDrive**. Everything else on the runtime is\n",
"> wiped when it disconnects; then run Step 0 again.\n",
Expand Down Expand Up @@ -95,12 +95,12 @@
"\n",
"# The notebook's version and name, as LabConstrictor's version check reads them\n",
"# (notebooks/notebook_latest_versions.yaml lists the latest version).\n",
"current_version = \"0.7.1\"\n",
"current_version = \"0.8.0\"\n",
"notebook_name = \"CellPatcher\"\n",
"# The release installed from GitHub when the package is missing (Google Colab, or a\n",
"# downloaded notebook). Set to the new tag, with current_version, before each release is\n",
"# tagged, so a tagged notebook installs its own release.\n",
"RELEASE_TAG = \"v0.7.1\"\n",
"RELEASE_TAG = \"v0.8.0\"\n",
"REPOSITORY = \"https://github.com/CellMigrationLab/CellPatcher.git\"\n",
"# The package's extras to install; on Colab also zarr, to read OME-Zarr images.\n",
"EXTRAS = \"notebook\"\n",
Expand Down
6 changes: 3 additions & 3 deletions notebooks/CellPatcher_Pytorch/CellPatcher_Pytorch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"appears when everything is ready.\n",
"\n",
"> **Colab users:** Step 0 connects your Google Drive (allow access in the window that opens)\n",
"> and installs CellPatcher **v0.7.1** from GitHub, which takes a minute or two; Colab already\n",
"> and installs CellPatcher **v0.8.0** from GitHub, which takes a minute or two; Colab already\n",
"> has PyTorch. Keep the CellPatcher output folder on Google Drive: in this notebook your Drive is\n",
"> the folder **/content/drive/MyDrive**. Everything else on the runtime is wiped when it\n",
"> disconnects; then run Step 0 again.\n",
Expand Down Expand Up @@ -79,12 +79,12 @@
"\n",
"# The notebook's version and name, as LabConstrictor's version check reads them\n",
"# (notebooks/notebook_latest_versions.yaml lists the latest version).\n",
"current_version = \"0.7.1\"\n",
"current_version = \"0.8.0\"\n",
"notebook_name = \"CellPatcher_Pytorch\"\n",
"# The release installed from GitHub when the package is missing (Google Colab, or a\n",
"# downloaded notebook). Set to the new tag, with current_version, before each release is\n",
"# tagged, so a tagged notebook installs its own release.\n",
"RELEASE_TAG = \"v0.7.1\"\n",
"RELEASE_TAG = \"v0.8.0\"\n",
"REPOSITORY = \"https://github.com/CellMigrationLab/CellPatcher.git\"\n",
"# The package's extras to install; on Colab also zarr, to read OME-Zarr images.\n",
"EXTRAS = \"notebook,torch\"\n",
Expand Down
Loading
Loading