# Operational S2S Extreme-Heat Forecast for Vietnam — Opus Prompt Package Built with the Claude Opus Prompt Architect meta-prompt (§1 intake → §3 composition → §4 anti-pattern check → §6 output format). --- ## 1. Task classification | Dimension | Classification | |---|---| | Horizon | Long-running autonomous — a multi-day build: data ingest, 2,080 reforecast cases, many calibration models, cross-validated verification, three written deliverables. | | Stakes | High cost-of-error — feeds an operational heat-warning workflow and a peer-reviewed paper. Silent leakage in cross-validation would invalidate both. | | Ambiguity | Partially specified. Data, target windows and the EHD threshold formula are fixed; calibration family selection, probability→binary decision rule, and downscaling strategy are deliberately delegated. | | Interactivity | Effectively unattended. User is asynchronous; work must continue across long stretches without answers. | | Delegation | Yes — calibration families, verification, and shapefile/regional products are weakly-dependent workstreams. | | Context volume | High — multi-source synthesis (S2S reforecast archive, gridded obs, station obs, shapefile, method literature). | | Extended thinking | Yes — interacting constraints (leakage, lead-dependence, ensemble-size mismatch, threshold definition, regridding order). | | Memory | Yes — recurs across sessions; `CLAUDE.md` and `MEMORY.md` are explicit deliverables. | | Domain sensitivity | None. | ## 2. Selected blocks - **OP-11** — frames the operational + publication mission so scope decisions inherit the right standard of evidence. - **OP-01** — outcome-first: method selection is the research contribution; prescribing steps would defeat the point. - **OP-02** — extended thinking: leakage, lead-dependence and threshold interactions must be reconciled before code is written. - **OP-03** — long-horizon autonomy (user asynchronous). Excludes OP-04. - **OP-05** — evidence discipline across the reforecast archive, two observation sources and competing calibration literature. - **OP-09** — every skill claim must point at a cross-validated number, not a plausible narrative. - **OP-06** — scope guard on a pipeline that invites endless refactoring. - **OP-07** — parallel delegation across calibration families. - **OP-08** — `MEMORY.md` is a required artefact; lessons must compound. - **OP-13** — validation pass; high-stakes per intake. - **OP-10** — final message discipline after unattended runs. - **OP-12 (adapted)** — deliverable channel. The target harness already has a user-facing file/message channel, so the prompt points at "the harness's user-facing channel" instead of declaring the meta-prompt's `send_to_user` JSON schema. ## 3. Assembled prompt ```text I'm building an operational subseasonal-to-seasonal (S2S) forecast product for extreme heat over Vietnam, for a hydro-meteorological research group. Two things depend on it: a duty forecaster will run it on a schedule to issue heat outlooks out to 45 days, and it will be written up for a peer-reviewed journal. So the method has to survive review AND be runnable by someone who did not build it. With that in mind, build and validate the complete workflow described below. A validated, reproducible, operationally runnable forecasting workflow that takes an ECMWF S2S forecast and produces, for every grid cell over Vietnam and for each of six fixed lead blocks, a binary flag: 1 = high probability of an extreme heat day (EHD), 0 = not. Plus the regional aggregation, verification evidence, and documentation described under . The scientific contribution is the calibration and decision-threshold choice, not the plumbing. Spend your effort there. Everything is or will be linked into the working directory. Inventory it first — do not assume filenames, variable names, units, calendars, grids or ensemble dimensions. Read the actual file headers and report what you found before using anything. - ECMWF S2S reforecast (hindcast) for Tx (daily maximum 2m temperature): 20 years, 104 initializations per year, ensemble members per initialization. Verify the member count, forecast length, native grid spacing and initialization calendar from the files themselves. Retain any other S2S fields present (T2m, MSLP, Z500, OLR, soil moisture, SST, MJO indices) — they are candidate predictors. - Gridded observed Tx over Vietnam, 2002-2023. - Station observed Tx, 1961-2025 (Both the lengths and the periods of data availability vary among stations). - Shapefile of Vietnam's 7 climate regions. * All data sources are provided in sub-folder of data in working folder. Reconcile the two observation sources rather than silently preferring one. Quantify gridded-vs-station disagreement in Tx and in derived EHD frequency, per region, before either is used as a calibration target. State which you used as the calibration target, which as independent validation, and why. Document station metadata gaps, obvious inhomogeneities and missing-data handling — do not impute silently. Lead blocks — fixed and non-overlapping, covering day 0 to day 45 relative to initialization. No running or sliding windows anywhere in the aggregation or the verification: W1 = days 0-10 W2 = days 11-17 W3 = days 18-24 W4 = days 25-31 W5 = days 32-38 W6 = days 39-45 Extreme heat day (EHD): a day is an EHD when Tx >= threshold, where threshold = min(Tx90p, 35 degC) Tx90p is the calendar-day 90th percentile of observed Tx from a fixed climatological baseline period. Choose and justify the baseline period and the percentile-estimation window; note that a centred multi-day window for percentile estimation is a climatology-construction choice and is NOT the running window that is prohibited above — keep the two clearly separated in the writing. Flag this early: with min(), in regions and seasons where Tx90p sits well below 35 degC the threshold is set by the percentile, so the index fires at temperatures a Vietnamese forecaster would not call nang nong. Implement min() exactly as specified, then produce a diagnostic showing threshold and resulting EHD frequency by region and by month under min() versus max(Tx90p, 35), and surface that diagnostic through the harness's user-facing channel early rather than holding it to the end. Do not substitute your preferred definition — the choice is the user's. Forecast targets, in this order: Primary - P(at least one EHD within the lead block) Secondary - P(a heatwave event: >= 3 consecutive EHDs). Handle events that straddle a block boundary explicitly and say how. Report the primary target everywhere; report the secondary wherever sample size supports it. Bias correction / calibration of ensemble Tx — implement several distinct method families, each with a real hyperparameter search, and weight the comparison toward machine-learning methods: Statistical baselines (needed as reference, not as the answer): lead-dependent mean bias correction; mean-variance scaling; empirical quantile mapping and quantile delta mapping (vary quantile count and extrapolation rule); NGR/EMOS trained on CRPS. Machine learning (the priority): quantile regression forests; gradient boosting with pinball/quantile loss; distributional regression networks trained on CRPS; a convolutional or encoder-decoder network that corrects the gridded field spatially; analog ensemble; isotonic distributional regression as a nonparametric strong baseline. Calibration must be lead-dependent and must respect the seasonal cycle. Predictors may include ensemble mean and spread, ensemble quantiles, lead time, harmonic calendar terms, grid location and elevation, and the additional S2S fields above. Justify predictor inclusion with a skill difference, not with plausibility. The S2S archive grid is coarse relative to the observation grid, so the workflow includes a downscaling step. Decide whether to bias-correct then downscale, downscale then bias-correct, or learn a joint mapping — and show the comparison that justifies the choice rather than asserting it. From calibrated members to a decision: 1. Convert calibrated members to P(EHD in block). Do not stop at the raw exceedance fraction — assess and, if warranted, recalibrate the probability (reliability diagram first; isotonic or logistic recalibration if it is miscalibrated). 2. Choose the probability threshold that converts P into the 1/0 flag. This choice is yours to make and defend. Evaluate candidates - maximum Peirce/Youden skill, ROC-optimal point, maximum F1 or CSI, frequency-bias-corrected, and cost-loss / relative economic value over a plausible range of forecaster cost-loss ratios - and select one, stating the operational reasoning. Fit the threshold per lead block and per climate region, and report the sensitivity of the final product to that choice. A threshold fitted on data used for verification is a failed deliverable. Cross-validation is the load-bearing part of this project. Use leave-one-year-out over the 20 reforecast years, with hyperparameter selection nested inside the left-out fold. The observed climatology, the Tx90p threshold, the calibration parameters, the probability recalibration and the decision threshold must all be fit without the held-out year. Write the leakage rule into CLAUDE.md and check it at every handoff. Score, against both a climatological reference and the raw uncalibrated ensemble: Continuous Tx - MAE, RMSE, bias, CRPS and CRPSS, rank histogram, spread-error ratio Probabilistic - Brier score and BSS with decomposition, reliability diagram, ROC and AUC, sharpness Binary 1/0 - POD, POFD, FAR, EDI, SEDI, CSI, ETS, HSS, Peirce score, frequency bias Stratify every score by lead block, by climate region, by season, and by event severity. Establish significance with a bootstrap that resamples whole years to preserve serial correlation, and control field significance across grid cells with FDR. Say plainly at which lead block skill drops to the reference level - a defensible "no skill beyond W4" is a better result than a decorated one. - Gridded binary EHD field over Vietnam, one field per lead block per initialization, CF-compliant NetCDF, with the underlying probability field retained alongside it. - Regional product: zonal aggregation of the binary field onto the 7 climate regions from the shapefile, with the aggregation rule (areal fraction of flagged cells and the fraction required to flag a region) defined and justified. - Map figure showing the 7 regions classified 1/0, and a chart showing the regional partition. Publication quality: readable projection, defensible colour choices, legible at journal column width, colourblind-safe. - Table of the regional partition based on the positive/negative EHD ratio: rows = 7 regions, columns = 6 lead blocks, reporting the positive count, negative count, positive ratio, resulting regional flag, and the verification scores that support that flag. Deliver it as both a figure-ready table and a machine-readable file. 1. The pipeline itself - config-driven, one command per stage, seeded, logged, with a pinned environment and tests covering the leakage rule and the index computation. It must run for a real-time forecast, not only for reforecasts. Address explicitly what changes when real-time ensemble size differs from the reforecast ensemble size the calibration was trained on, and whether the operational model version matches the reforecast version. 2. CLAUDE.md - orientation for a future agent session: repository map, data locations and conventions, environment setup, how to run each stage, the cross-validation and leakage invariants, naming conventions, and what must not be changed without re-running verification. 3. MEMORY.md - one lesson per entry with a one-line summary at the top: decisions and why, approaches that were confirmed, approaches that failed and the evidence that killed them. Update entries rather than accumulating near-duplicates; delete an entry once it is shown wrong. Do not restate what the repository or the report already records. 4. Operational guide - a duty forecaster's document: prerequisites, schedule, commands, expected runtime, output locations, how to read the product, failure modes and what to do about each, and the known limits of the forecast. 5. Results report - paper-ready: data, methods, cross-validation protocol, method comparison, verification results, regional findings, limitations, and reproduction instructions. Written as prose with figures and tables, not as a slide outline. 6. Evidence pack - every figure, table and score file behind the report, plus the run logs and configs that produced them, organised so a reviewer can trace any number in the report back to the run that produced it. Language: code, comments, CLAUDE.md and MEMORY.md in English. Results report in English. Operational guide in Vietnamese with an English summary. Say so and flip it if that is wrong. Decide the approach yourself, but these specific steps fail quietly if left to default judgment - handle each one explicitly and record the decision in MEMORY.md: - Fitting the observed Tx90p climatology on all years, including the held-out one. - Calibrating with a single lead-independent correction; S2S bias grows with lead. - Regridding order - coarse-to-fine interpolation before calibration changes the distribution you are calibrating. - Estimating a 90th percentile per grid cell per calendar day from too few samples. - Reforecast-vs-real-time ensemble size and model version mismatch. - Treating the coarse S2S land-sea mask as if it resolved Vietnam's coastline and terrain. - Reporting skill against climatology only, where the raw ensemble is the reference that matters operationally. You are operating with extended autonomy on a task that will take many steps. The user is not available to answer questions mid-task. For actions that are reversible and follow directly from this request, proceed without asking. Reserve stopping for an irreversible action, a genuine scope change, or a decision that depends on information only the user has - the EHD threshold semantics flagged above is the one such decision anticipated here, and the instruction there is to implement as specified, produce the diagnostic, and continue. Before ending your turn, check whether your last paragraph is a plan, a promise, or a question you could have resolved yourself; if so, do that work now instead of ending on it. Before producing the final answer, reason through the problem step by step in your thinking. Identify the constraints that interact, resolve conflicts between sources explicitly, and check your plan against the stated requirements before acting on it. Keep the final answer free of that scratch work. Delegate independent subtasks to subagents and continue other work while they run rather than blocking on each sequentially. Natural decomposition: Coordinator |- Data + QC - inventory, reconcile gridded vs station obs, build climatology |- Calibration A - statistical baselines, full parameter sweep |- Calibration B - tree/boosting ML family, nested tuning |- Calibration C - neural / spatial family, nested tuning |- Verification - scoring, bootstrap, significance; owns the leakage check |- Regional - shapefile zonal products, maps, tables |- Validator - independent re-derivation of headline scores Give each subagent a bounded scope, the data it may use, the cross-validation fold structure it must respect, and the exact output format you need back. Intervene if output looks off-scope. Synthesise the comparison yourself; do not have one calibration subagent judge another's results. Don't add features, refactor, or introduce abstractions beyond what the workflow requires. Resist building a general-purpose post-processing framework - this is one product for one domain. Validate at real boundaries (file I/O, config, external data), not everywhere. When synthesising across the reforecast archive, the two observation sources and the calibration literature, attribute each material claim to its source rather than blending them. Where gridded and station observations disagree, or where two calibration methods rank differently under different scores, say so and state which you weighted more heavily and why. Do not silently resolve a contradiction by picking a side. Before reporting progress, check each claim against a concrete result from this session - a score file, a figure, a test run, a diff. Report only what you can point to. If a model was trained but not yet verified, say that. If a stage failed, say so with the actual error, not a softened paraphrase. No skill number reaches the report or the user without a cross-validated run behind it. Between steps, when you have content the user must see - the threshold diagnostic, the method comparison table, a draft figure, the first end-to-end product - surface it through the harness's user-facing file/message channel as it is produced rather than holding everything to the end. Use it for deliverables, not for narration. Before finalising, check silently: does this answer the actual task; are all hard constraints satisfied (six fixed blocks, no running windows, min(Tx90p, 35), 7 regions, gridded 1/0 output, all six deliverables); is every skill claim backed by a cross-validated number; is the leakage rule satisfied everywhere including threshold and climatology fitting; did you invent any result; are limitations stated; were any irreversible actions taken? Fix what is wrong before returning. Do not show this checklist. Open your final message with one sentence answering what you built and whether it has skill. Detail comes after. Since the user will not have watched the run, write the final message as a re-grounding: complete sentences, file names and identifiers spelled out in their own clause, and none of the shorthand you invented while working. You have ample context remaining. Do not stop, summarise, or suggest a new session on account of context limits. Continue the work. ``` ## 4. Omitted but considered - **OP-04 (interactive checkpoints)** — omitted. Mutually exclusive with OP-03, and the intake put interactivity at "asynchronous". Including both would have given the agent licence to stall on the threshold-semantics question instead of producing the diagnostic and continuing. - **OP-12 as written in the meta-prompt** — the JSON `send_to_user` tool schema was omitted and replaced with a harness-neutral instruction, because the target harness already exposes a user-facing file and message channel. Declaring a duplicate tool would have created two channels for one job. - **Prescriptive step sequencing** — deliberately withheld per §4's primary anti-pattern, except inside ``, which is exactly the licensed exception: named steps with a known quiet-failure mode. - **Vague intensifiers** ("be rigorous", "think carefully") — excluded; OP-02 and OP-13 do that work structurally. - **A fixed method ranking or a recommended winning calibration method** — withheld on purpose. Naming a favourite would anchor the comparison that is the project's scientific contribution. --- ## 5. Requested enhancements (v2 — queued by user 2026-09-14, NOT YET IMPLEMENTED) The v1 build (tasks 1–10) is complete. The user has queued a second iteration. These extend the method; they do NOT relax the v1 hard constraints (six fixed blocks, `EHD = min(Tx90p,35)`, leakage rule). Canonical spec + open questions live in `CLAUDE.md` → "REQUESTED ENHANCEMENTS (v2)". 1. **Predictand = severity, not Tx.** Use `Sev = Tx − Threshold` (Threshold = `min(Tx90p,35°C)`) as the predictand instead of raw Tx; `Sev ≥ 0 ⇔ EHD`, so severity regression maps straight to P(EHD) and carries the magnitude of exceedance. 2. **Expand the AI model zoo** to forecast EHD/EHDE from `Sev` (v1 has only logistic + HGB). 3. **Two-level cascade.** *LV1* forecasts **nEHDE** (no event); samples that are **nearly certain nEHDE** (prob ≈ 1) are removed. *LV2* builds AI models on the remaining samples to forecast **yEHDE** (yes event) — so the hard classifier is not swamped by trivial negatives. 4. **Whole-dataset (2003–2022) verification** with POD, POFD, FAR, EDI, SEDI (+ CSI, ETS/HSS, Peirce, frequency bias), computed on out-of-sample LOYO-pooled predictions (leakage rule). Open questions before building (see CLAUDE.md): the exact EHDE definition (≥3-consecutive heatwave vs ≥1 EHD), the "nearly certain nEHDE" removal cutoff, and whether v2 targets QG_1 or `../HW*`. --- ## 6. Additional requrements: 1. Compare the performance of the AI members in forecasting EHDE, with priority given to **high POD** and **low POFD and FAR**, particularly for **W3–W6**. Assess the contribution of individual members to the **Stack/Ensemble**. 2. Test the following probability-based method: $$ P(yEHDE)=m/n, $$ where \(n\) is the number of AI members participating in the EHDE forecast, and \(m\) is the number of members predicting \(yEHDE\). The resulting product is a **probability map of yEHDE occurrence**. 3. Based on (2), generate the deterministic \(yEHDE\) forecast by defining: $$ EHDE=1 \quad \text{if} \quad P(yEHDE)>P_0, $$ where \(P_0\) is an **optimal probability threshold to be determined**. 4. Using the resulting \(yEHDE\) forecasts, construct an **event forecast table for each region and each week**: * Let \(N_j\) be the total number of grid points within region \(R_j\). * Let \(M_j\) be the number of grid points within region \(R_j\) for week \(W_k\) where \(yEHDE=1\). Then, $$ P[yEHDE(R_j,W_k)] = \frac{M_j}{N_j}. $$ * If $$ P[yEHDE(R_j,W_k)] \ge P_{\text{thres}}, $$ forecast that region \(R_j\) will experience \(yEHDE\) during week \(W_k\). * If $$ P[yEHDE(R_j,W_k)] < P_{\text{thres}}, $$ forecast that region \(R_j\) will **not** experience \(yEHDE\) during week \(W_k\), i.e. \(nEHDE\).