Skip to content

Channel IDs on every patch (#125) - #127

Merged
guijacquemet merged 2 commits into
mainfrom
claude/channel-ids-and-stopped-runs
Nov 16, 2026
Merged

guijacquemet merged 2 commits into
mainfrom
claude/channel-ids-and-stopped-runs

Conversation

@guijacquemet

@guijacquemet guijacquemet commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

For the coming v0.7.2. Nothing tagged. Base e0e56bc (main after v0.7.1). Commits: 71a04ce (#125) and the review fix 76f221d.

Fixes #125.

Split: the #126 commit (88d03e4, a stopped preprocessing run's refusal) was moved to draft PR #128, because it reads preprocessing's discovery_report.json, which preprocessing documents as not for bricks; it waits for morphobricks-preprocessing #322. Its CHANGELOG entry moved with it.

#125: every patch records its channel IDs in its C order (71a04ce)

Field: a new documented field, PatchRegion.channel_ids (patches.csv column channel_ids, ;-separated, after channel_id). It holds the ID of every channel plane the patch holds, in its own C order, from the run's description (Fov.channel_ids through RunInputs; the resolver's FovSelection.channel_indices are fov.channel_ids.index(id)), whatever the normalization and splitting settings:

  • a patch of every channel gets every ID of its image;
  • a split patch gets (channel_id,);
  • an image without a C axis gets its one ID.

When normalizing, it equals normalization_channels.

Why not an existing field: channel_id is documented as the ID of the patch's c (one channel, None without c). normalization_channels is documented as None without normalization and is written only with the parameter columns.

In memory: the same rules from image_metadata["channel_ids"]. It stays None without IDs, so nothing is taken by position, and for a plane with no C axis and no c given the IDs of several channels.

Reading: read_patch_table reads the cell as a tuple checked with normalization's check_channel_ids. It and ExportedPatchTorchDataset refuse a table without the column, like any missing column.

Test: tests/test_patch_channel_ids.py runs Spec v04 (CTRL stores DNA, ACTIN; DrugA stores ACTIN, DNA) with the G4 suite's pixel rule (a plane depends on image and channel ID, never on its C index); patch arrays are checked against the generator plane by plane. Further cases: split, normalized, in memory with and without IDs, single plane, load refusals.

Goldens: tests/fixtures/v062_parity/digests.json changed only in its 57 patches.csv digests; each new table with its channel_ids column dropped has the v0.6.2 digest again.

Review fix (76f221d)

An in-memory image with a C axis of several channels, given image_metadata["channel_ids"] and image_metadata["c"] without splitting, gave patches holding every channel plane but recording channel_ids == (ids[c],). stamp_channel_ids now refuses it (as split_channels with c already is). Regression test added.

Owner questions

  1. Tables written before this change (no channel_ids column) are refused by read_patch_table and ExportedPatchTorchDataset. Recommendation: keep it (AR10: those are exactly the tables whose channel order a reader would have to assume).
  2. Source of the IDs: Fov.channel_ids rather than a full-channel resolver request (a single request cannot name every channel when units differ in channel set, A_SCOPE_INCOMPLETE). Recommendation: accept.

🤖 Generated with Claude Code

https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc

Without normalization and without channel splitting, a patch of a described
run recorded no channel ID (c, channel_id and normalization_channels empty), so
two units storing DNA, ACTIN and ACTIN, DNA gave patches that could only be
told apart by assuming the channel order (Spec S3.3, gate G3).

New field PatchRegion.channel_ids (patches.csv column channel_ids,
";"-separated, after channel_id): the ID of every channel plane the patch
holds, in its C order, from the run's description (Fov.channel_ids, the order
the resolver's selections index), whatever the normalization and splitting
settings; (channel_id,) for a split patch. In memory from
image_metadata["channel_ids"]; None without them, as documented. No existing
field fits: channel_id names the one channel of a patch with c, and
normalization_channels is documented as empty without normalization.

read_patch_table reads the column as a checked tuple and, like
ExportedPatchTorchDataset, refuses a table without it.

The v0.6.2 parity golden changes in its 57 patches.csv digests only; each new
table without its channel_ids column has the v0.6.2 digest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc
@guijacquemet
guijacquemet force-pushed the claude/channel-ids-and-stopped-runs branch from 88d03e4 to 71a04ce Compare November 16, 2026 23:20
@guijacquemet guijacquemet changed the title Channel IDs on every patch (#125); a stopped preprocessing run's refusal passed on (#126) Channel IDs on every patch (#125) Nov 16, 2026
…IDs (review of #127)

An in-memory image with a C axis of several channels, given
image_metadata["channel_ids"] and image_metadata["c"] without splitting, gave
patches holding every channel plane but recording channel_ids == (ids[c],)
(and channel_id == ids[c]). stamp_channel_ids now refuses it, as
extraction.split_channels with "c" already is. Regression test in
tests/test_patch_channel_ids.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc

@guijacquemet guijacquemet left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review: PASS after one fix (head 76f221d3c5c495e891b233dd7300194a6c03cea9)

Split. 88d03e4 (#126, reads preprocessing's discovery_report.json) moved to draft #128 (claude/stopped-run-refusal, ab3cbe3, cherry-picked onto e0e56bc; its CHANGELOG entry is in its own [Unreleased] section). It waits for morphobricks-preprocessing #322. This branch was force-pushed with --force-with-lease to 71a04ce, then the fix below. The #125 CHANGELOG section at 71a04ce was already coherent without #126.

Defect found and fixed (76f221d). An in-memory image with a C axis of several channels, given image_metadata["channel_ids"] and image_metadata["c"], without splitting, produced patches of shape (2, 8, 8) that recorded channel_ids == ('ACTIN',) (and channel_id == 'ACTIN'). stamp_channel_ids now refuses that combination, as split_channels together with c already is. Regression test test_in_memory_image_of_several_channels_given_c_is_refused_not_recorded_as_one_channel[CYX|YXC]: fails without the fix, passes with it. CHANGELOG updated.

Adversarial checks (C order and pixels):

  • Split patches give (channel_id,), with c from the per-image Fov.channel_ids. OK.
  • No C axis gives its one ID. With several IDs and no c it gives None. With c on a single plane it gives (ids[c],). OK.
  • Mixed channel sets (G1, partial_channels): the IDs are per image from fov_metadata (Fov.channel_ids), and RunInputs.read_plane returns C in that order. Checked by the v04 pixel tests and by G4 A02/A03. OK.
  • In memory with or without IDs: None without IDs, so nothing is taken by position. OK.
  • channel_policy="max"/"repeat_to_rgb" helpers: max gives a YX plane with several IDs, which stays None. repeat_to_rgb on a one-ID image is already refused by the per-C-index count check. Torch repeat_to_rgb acts only at load time. OK.
  • Normalization consistency: channel_ids == normalization_channels holds whenever IDs exist (test parametrized over split). Without IDs, normalization keeps its documented positional C<i> names while channel_ids stays None, which is correct.

AR10 / old tables: refusing a table without channel_ids (read_patch_table, ExportedPatchTorchDataset) is the right behaviour. Those tables are exactly the ones whose channel order a reader would have to assume. Reading them as None would silently default a written column.

Golden proof reproduced independently. I re-ran every parity case on this branch:

  • the regenerated digests equal the committed golden;
  • the case and file sets equal the base golden's;
  • exactly 57 entries changed, all patches.csv;
  • with the channel_ids column dropped, 57/57 tables match the base digest of the same case and file (a strict per-table match);
  • every non-empty cell is DNA;ACTIN.

Gates:

  • python tools/check.py (fresh py3.11 venv, .[test,zarr,notebook] plus CPU torch 2.15.0, preprocessing v0.6.1, normalization v0.7.0, PYTEST_ADDOPTS unset): 3014 passed, 0 skipped; code rules and Ruff clean. 3004 base, plus 8 tests from #125, plus 2 regression tests. #126's 7 tests left with #128.
  • G4 suite, MorphoFeature draft PR #240 bbe21f5 adversarial/, with MorphoObjects 0eefed7 installed first and then this branch --no-deps -e .: 9 passed, including A01 and A07.
  • A local A01 variant with normalization off and splitting off, reading patch.channel_ids: passed. 24 patches of both orders, and every mean equals the generator's pixels by ID.
  • CI on 76f221d: 7/7 green. Draft #128: 7/7 green.

Merging with a merge commit at the full head SHA. Not tagging.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Patches from a described run record no channel IDs without normalization or channel splitting

2 participants