Skip to content

clip.report_marsclip_patches

report_marsclip_patches

Generate lightweight Stage A1 patch reports and preview artifacts.

save_patch_report

save_patch_report(dataset: MarsCLIPPatchDataset, out_dir: Path | str, *, preview_items: int = 4, report_items: int = 16) -> dict[str, Any]

Save a JSON patch summary and PNG preview for a Stage A1 dataset.

Source code in src/clip/report_marsclip_patches.py
def save_patch_report(
    dataset: MarsCLIPPatchDataset,
    out_dir: pathlib.Path | str,
    *,
    preview_items: int = 4,
    report_items: int = 16,
) -> dict[str, Any]:
    """Save a JSON patch summary and PNG preview for a Stage A1 dataset."""
    out_path = pathlib.Path(out_dir)
    out_path.mkdir(parents=True, exist_ok=True)

    count = min(len(dataset), max(preview_items, report_items))
    if count <= 0:
        raise ValueError("Patch dataset is empty.")

    samples = [dataset[i] for i in range(count)]
    summary = summarize_patch_records(dataset.patch_records)
    summary.update(summarize_patch_samples(samples[: min(report_items, len(samples))]))
    summary["image_size"] = list(dataset.image_size)
    summary["patch_size_deg"] = list(dataset.patch_size)

    preview_path = save_sample_preview(
        samples,
        out_path / "patch_preview.png",
        max_items=min(preview_items, len(samples)),
    )
    summary_path = out_path / "patch_summary.json"
    summary_path.write_text(json.dumps(summary, indent=2, sort_keys=True))

    return {
        "summary": summary,
        "summary_path": summary_path,
        "preview_path": preview_path,
    }