Repository navigation
Channel IDs on every patch (#125) - #127
Conversation
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
88d03e4 to
71a04ce
Compare
…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
left a comment
There was a problem hiding this comment.
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,), withcfrom the per-imageFov.channel_ids. OK. - No C axis gives its one ID. With several IDs and no
cit givesNone. Withcon a single plane it gives(ids[c],). OK. - Mixed channel sets (G1,
partial_channels): the IDs are per image fromfov_metadata(Fov.channel_ids), andRunInputs.read_planereturns C in that order. Checked by the v04 pixel tests and by G4 A02/A03. OK. - In memory with or without IDs:
Nonewithout IDs, so nothing is taken by position. OK. channel_policy="max"/"repeat_to_rgb"helpers: max gives a YX plane with several IDs, which staysNone. repeat_to_rgb on a one-ID image is already refused by the per-C-index count check. Torchrepeat_to_rgbacts only at load time. OK.- Normalization consistency:
channel_ids == normalization_channelsholds whenever IDs exist (test parametrized over split). Without IDs, normalization keeps its documented positionalC<i>names whilechannel_idsstaysNone, 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_idscolumn 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_ADDOPTSunset): 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
bbe21f5adversarial/, with MorphoObjects0eefed7installed 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
For the coming v0.7.2. Nothing tagged. Base
e0e56bc(main after v0.7.1). Commits:71a04ce(#125) and the review fix76f221d.Fixes #125.
Split: the #126 commit (
88d03e4, a stopped preprocessing run's refusal) was moved to draft PR #128, because it reads preprocessing'sdiscovery_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.csvcolumnchannel_ids,;-separated, afterchannel_id). It holds the ID of every channel plane the patch holds, in its own C order, from the run's description (Fov.channel_idsthroughRunInputs; the resolver'sFovSelection.channel_indicesarefov.channel_ids.index(id)), whatever the normalization and splitting settings:(channel_id,);When normalizing, it equals
normalization_channels.Why not an existing field:
channel_idis documented as the ID of the patch'sc(one channel,Nonewithoutc).normalization_channelsis documented asNonewithout normalization and is written only with the parameter columns.In memory: the same rules from
image_metadata["channel_ids"]. It staysNonewithout IDs, so nothing is taken by position, and for a plane with no C axis and nocgiven the IDs of several channels.Reading:
read_patch_tablereads the cell as a tuple checked with normalization'scheck_channel_ids. It andExportedPatchTorchDatasetrefuse a table without the column, like any missing column.Test:
tests/test_patch_channel_ids.pyruns 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.jsonchanged only in its 57patches.csvdigests; each new table with itschannel_idscolumn 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"]andimage_metadata["c"]without splitting, gave patches holding every channel plane but recordingchannel_ids == (ids[c],).stamp_channel_idsnow refuses it (assplit_channelswithcalready is). Regression test added.Owner questions
channel_idscolumn) are refused byread_patch_tableandExportedPatchTorchDataset. Recommendation: keep it (AR10: those are exactly the tables whose channel order a reader would have to assume).Fov.channel_idsrather 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