---
name: codex-panel-reproduce
description: Use this skill when asked to reproduce or refine a single scientific figure panel as editable Python/matplotlib code in NaturePanelForge. It covers the local Codex panel-to-code workflow, dry-runs, review loops, expected artifacts, and validation.
---

# Codex Panel Reproduce

## Trigger

Use this for code-only reproduction or refinement of one scientific figure panel in NaturePanelForge. The target is an editable Python script plus rendered PNG/PDF, not image editing or raster tracing.

For local user-supplied images, do not run Qwen scoring and do not require Qwen outputs. Qwen context is only optional metadata when the input already comes from an existing SciFigureHub/NaturePanelForge pipeline directory.

## Inputs

- Single-image workflow: a target panel image path, optional caption, optional source PDF.
- Existing-panel workflow: a panel directory containing `target.png`; optional `metadata.json`, `qwen_score.json`, `qwen_prompt.md`, and `raw_response.txt`. Missing Qwen files are acceptable for user-supplied images.
- Refine workflow: an existing panel directory containing `target.png`, `reproduce_panel.py`, `reproduce_panel.png`, and `reproduce_panel.pdf`.

## Reproduce One Panel

Run from the NaturePanelForge repo root:

```bash
python3 forge.py single-panel-image \
  --image path/to/target_panel.png \
  --out-root UserRuns/single_panel \
  --panel-id my_panel \
  --caption "brief visual/caption context" \
  --chart-type user_supplied \
  --review-rounds 4 \
  --skip-existing
```

This command prepares the local single-image bundle itself. It writes placeholder user-image metadata as needed; it does not classify the image with Qwen and does not need a local Qwen model.

For an existing panel directory:

```bash
python3 examples/prompt_codex_reproduce_fig02_g.py \
  --panel-dir path/to/panel_dir \
  --panel-root path/to/panel_root \
  --reviews-dir path/to/reviews_root \
  --specs-dir path/to/specs_root \
  --jobs 1 \
  --review-rounds 4 \
  --skip-existing
```

Expected panel outputs:

- `reproduce_panel.py`
- `reproduce_panel.png`
- `reproduce_panel.pdf`

Expected mirrored review/spec outputs:

- `reproduce_panel_run_log.md`
- `reproduce_panel_review_notes.md`
- `reproduce_panel_review_summary.json`
- `reproduce_panel_prompt.md`
- `reproduce_panel_raw_response.txt`

## Dry Run

Use `--dry-run` before a live run to create/check task context and print the nested Codex prompt without running it:

```bash
python3 -m nature_panel_forge.reproduce_image --image path/to/target_panel.png --out-root UserRuns/dry_run --dry-run --print-command
```

For existing panel directories, add `--dry-run` to the batch reproduce or refine command.

## Refine Existing Output

Use refinement only after a baseline reproduction exists:

```bash
python3 examples/prompt_codex_refine_reproduce.py \
  --panel-dir path/to/panel_dir \
  --panel-root path/to/panel_root \
  --reviews-dir path/to/refine_reviews_root \
  --specs-dir path/to/refine_specs_root \
  --jobs 1 \
  --review-rounds 4 \
  --skip-existing
```

Refine in place by editing `reproduce_panel.py`; do not create a competing script. Also write `refine_complexity_assessment.json`.

## Review Loop

Each live run should alternate code-writing and review passes until close enough or `--review-rounds` is reached. The review must compare the saved PNG against `target.png` and record concrete findings about chart type, data pattern, axes, ticks, labels, legends/colorbars, annotations, colors, font/readability, edge visibility, and layout collisions.

If a review finds a fixable issue, edit the Python code and rerender. Do not modify `target.png`, `target.pdf`, metadata, score files, prompts, or raw source context.

## Validation

Before reporting success, verify:

- `python path/to/reproduce_panel.py` exits successfully.
- The PNG and PDF outputs exist and are regenerated by the script.
- Review summary JSON has `review_passed: true`.
- Refine runs also have `font_audit_passed`, `layout_audit_passed`, and `edge_visibility_passed` set to true.
- The final response lists created files, final PNG size, iteration count, and the regeneration command.

## Natural-Language Use

When the user asks in natural language, infer the CLI call and run the workflow. A good request looks like:

```text
Use the codex-panel-reproduce skill to reproduce this scientific panel as editable Python/matplotlib code.
Target image: /path/to/target_panel.png
Optional PDF: /path/to/target_panel.pdf
Output root: UserRuns/my_panel
Panel id: my_panel
Chart type: bubble_plot
Caption: A short description of the visual structure, axes, legend, and data pattern.
Do not use Qwen scoring. Generate reproduce_panel.py, reproduce_panel.png, reproduce_panel.pdf, review notes, review summary, and a run log. Then report the output directory, review_passed, contract_passed, final PNG size, and rerender command.
```
