Skip to content

Add per-shard CLI and Metadata_Imaging_ImageID propagation - #50

Merged
d33bs merged 9 commits into
WayScience:mainfrom
d33bs:cli
Aug 7, 2026
Merged

Add per-shard CLI and Metadata_Imaging_ImageID propagation#50
d33bs merged 9 commits into
WayScience:mainfrom
d33bs:cli

Conversation

@d33bs

@d33bs d33bs commented Aug 5, 2026

Copy link
Copy Markdown
Member

Description

This PR focuses on productionizing the CLI for use with orchestration for the NF1 project. We add an image_id arg in many spots to help enforce data provenance, which is important for warehousing and may fit in nicely with task parallelization.

What kind of change(s) are included?

  • Documentation (changes docs or other related content)
  • Bug fix (fixes an issue).
  • Enhancement (adds functionality).
  • Breaking change (these changes would cause existing functionality to not work as expected).

Checklist

Please ensure that all boxes are checked before indicating that this pull request is ready for review.

  • I have read and followed the CONTRIBUTING.md guidelines.
  • I have searched for existing content to ensure this is not a duplicate.
  • I have performed a self-review of these additions (including spelling, grammar, and related).
  • These changes pass all pre-commit checks.
  • I have added comments to my code to help provide understanding
  • I have added a test which covers the code changes found within this PR
  • I have deleted all non-relevant text in this pull request template.

d33bs added 2 commits August 5, 2026 17:30
ZedProfiler is the feature extractor the NF1 pipeline dispatches per
well/FOV shard via SLURM sbatch. This commit adds the command that process
runs and the identifier column that makes shards warehouse-joinable.

CLI (src/zedprofiler/cli.py):
- "ZedProfiler run" subcommand (argparse): repeatable --image/--label
  NAME=PATH flags, --anisotropy-spacing Z Y X, identifier fields
  (--patient-tumor/--plate/--well/--field), --out-dir, a --features
  selector, repeatable --feature TYPE[,key=value,...] advanced requests,
  --skip-existing, and --force.
- Reuses the six compute_* featurizers; builds the shared loader via
  ImageSetLoader.from_image_dict with the identifier fields.
- Restartable/idempotent: deterministic output paths, --skip-existing
  filters before any image is read (a finished shard re-run skips I/O
  entirely), and atomic writes (temp + os.replace) so a crashed shard
  never leaves a partial file that --skip-existing would mistake for
  complete.
- Fixes the orphaned/mis-cased console script to zedprofiler.cli:trigger.

Identifiers (src/zedprofiler/identifiers.py):
- build_image_id(patient_tumor, plate, well, field) -> deterministic
  Metadata_Imaging_ImageID; single source of truth for the format.

Loaders (src/zedprofiler/IO/loading_classes.py):
- ImageSetConfig carries patient_tumor/plate/well/field with an image_id
  property; ImageSetLoader exposes image_id (falls back to image_set_name).
- New from_image_dict classmethod builds a multi-channel loader from an
  in-memory {key: ndarray} dict (the path the CLI needs); it derives
  compartments/image names directly from the declared label keys so it is
  self-contained and correct independent of get_compartments.

Featurizers (6 modules):
- Each emits Metadata_Imaging_ImageID before Metadata_Experiment_ImageSet.
  Feature values are unchanged; only a metadata column is added.

Feature writing:
- save_features_as_parquet gains an opt-in atomic flag used by the CLI.

End-to-end CLI tests self-skip when the CellProfiler 3D tutorial data is
absent (it lands via a separate data commit), so the CLI test module stays
green everywhere and runs in full wherever the data is available.
ZedProfiler is the feature extractor the NF1 pipeline dispatches per
well/FOV shard via SLURM sbatch. This commit adds the command that process
runs and the identifier column that makes shards warehouse-joinable.

CLI (src/zedprofiler/cli.py):
- "ZedProfiler run" subcommand (argparse): repeatable --image/--label
  NAME=PATH flags, --anisotropy-spacing Z Y X, identifier fields
  (--patient-tumor/--plate/--well/--field), --out-dir, a --features
  selector, repeatable --feature TYPE[,key=value,...] advanced requests,
  --skip-existing, and --force.
- Reuses the six compute_* featurizers; builds the shared loader via
  ImageSetLoader.from_image_dict with the identifier fields.
- Restartable/idempotent: deterministic output paths, --skip-existing
  filters before any image is read (a finished shard re-run skips I/O
  entirely), and atomic writes (temp + os.replace) so a crashed shard
  never leaves a partial file that --skip-existing would mistake for
  complete.
- Fixes the orphaned/mis-cased console script to zedprofiler.cli:trigger.

Identifiers (src/zedprofiler/identifiers.py):
- build_image_id(patient_tumor, plate, well, field) -> deterministic
  Metadata_Imaging_ImageID; single source of truth for the format.

Loaders (src/zedprofiler/IO/loading_classes.py):
- ImageSetConfig carries patient_tumor/plate/well/field with an image_id
  property; ImageSetLoader exposes image_id (falls back to image_set_name).
- New from_image_dict classmethod builds a multi-channel loader from an
  in-memory {key: ndarray} dict (the path the CLI needs); it derives
  compartments/image names directly from the declared label keys so it is
  self-contained and correct independent of get_compartments.

Featurizers (6 modules):
- Each emits Metadata_Imaging_ImageID before Metadata_Experiment_ImageSet.
  Feature values are unchanged; only a metadata column is added.

Feature writing:
- save_features_as_parquet gains an opt-in atomic flag used by the CLI.

Tests:
- test_real_world_data.py colocalization loader switched to from_image_dict
  so the new image_id column is populated for the existing colocalization
  end-to-end test.
- CLI end-to-end tests run against the CellProfiler 3D tutorial data present
  on main and self-skip if that data is absent on other branches.
@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@b44f5d3). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #50   +/-   ##
=======================================
  Coverage        ?   94.47%           
=======================================
  Files           ?       17           
  Lines           ?     1648           
  Branches        ?        0           
=======================================
  Hits            ?     1557           
  Misses          ?       91           
  Partials        ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@d33bs
d33bs marked this pull request as ready for review August 6, 2026 13:51

@MikeLippincott MikeLippincott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

Comment thread src/zedprofiler/identifiers.py Outdated
Comment thread src/zedprofiler/cli.py
Comment thread src/zedprofiler/cli.py
Comment thread src/zedprofiler/cli.py
d33bs and others added 7 commits August 6, 2026 09:11
Co-Authored-By: Mike Lippincott <58147848+MikeLippincott@users.noreply.github.com>
Co-Authored-By: Mike Lippincott <58147848+MikeLippincott@users.noreply.github.com>
Co-Authored-By: Mike Lippincott <58147848+MikeLippincott@users.noreply.github.com>
Co-Authored-By: Mike Lippincott <58147848+MikeLippincott@users.noreply.github.com>
Integrates the rewritten origin/main (9bab886: per-shard CLI +
Metadata_Imaging_ImageID propagation) into the cli branch. No content
change: cli already contained all of upstream's current content (image_id
work, fov rename, get_compartments fix, real-world data) plus the CLI
feature-spec/coverage work, so the merge only records the integration.
Integrate the benchmarking framework and featurization performance
refactor from upstream (PR WayScience#48) with the per-shard CLI and
Metadata_Imaging_ImageID propagation work on this branch.

The two lines of work touched disjoint regions and merged cleanly, but
the upstream BenchmarkImageSet mock lacked the image_id attribute that
the cli featurization functions now read. Add image_id to
BenchmarkImageSet (mirroring ImageSetLoader's fallback to
image_set_name) and regenerate the six accuracy-lock signatures in
test_benchmark_contracts.py, which now include the
Metadata_Imaging_ImageID column.
@d33bs

d33bs commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

thank you @MikeLippincott!

@d33bs
d33bs merged commit 075abe0 into WayScience:main Aug 7, 2026
13 checks passed
@d33bs
d33bs deleted the cli branch August 7, 2026 17:17
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.

2 participants