MANDATORY EXECUTION POLICY — READ BEFORE PROCEEDING
You MUST run the actual model binary or package described in this document.
If the model fails to import, compile, or execute, you MUST:
1. Check
diagnostics/triplets.yamlfor a matching error pattern
2. Try the fix suggested in the triplet's
remedysection
3. If still failing, report the error to the user with full details
You MUST NOT substitute a simplified Python formula, regression equation,
or hand-coded approximation in place of the real model.
Before starting, run:
python preflight_check.py(in this KI directory)
to verify that the model binary/package and required data are available.
DEBUGGING PROTOCOL — When something goes wrong, follow this order:
1. Check triplets —
diagnostics/triplets.yamlmay already cover this error
2. Read official docs — The model's own documentation for expected formats/units
3. Find working examples — Check
outputs/or the model's shipped test data
4. Fix the tool — With knowledge of what "correct" looks like
Do NOT write custom debug scripts. The answers are in the docs and examples.
<!-- KI-MAP:BEGIN (projected by generate_skill_map.py — edit the KI, not this table) -->
KI map — what to read, and when
| when you need | read | why |
|---|---|---|
| FIRST, always | preflight_check.py | run it (python preflight_check.py): proves env/binary/data are usable and emits a machine-readable PREFLIGHT_REPORT= line. Do not debug a run that never had a healthy environment. |
| to run the pipeline stages | tools/ (7 tools; the REAL engine is tools/run_hms_engine.py) | the executable pipeline. Read each tool's argparse (--help) before composing a command; SKILL.md's stage table says which tool serves which stage. |
| before running a stage | docs/s*_*.md (7 stage docs) | per-stage procedure, verification and traps — the how-to that SKILL.md's overview compresses. |
| on ANY error, before debugging | diagnostics/triplets.yaml (22 entries) | symptom → diagnosis → remedy for this model's known failure modes. Check here FIRST; the answer usually exists. Never renumber or rewrite entries. |
| to know what an output IS | dag.yaml | the model's identity: every output's medium, units, validation_rank (1 = the headline variable) and observability. Scoring and obs-binding read THIS — when asked 'what does this model predict', the dag is the answer, not a guess. |
| when building inputs / parsing outputs | docs/format_spec.yaml | exact I/O shapes + known_issues, projected from dag + triplets. Regenerate with ki_tools_common/generate_format_spec.py after changing either — never hand-edit. |
| to judge a run's skill | docs/validation_convention.yaml | how this model's field judges it validated: per-dag_variable metrics, directions and CITED pass-bands. A run is graded against these, not against intuition. |
| for claims and thresholds | docs/gathered_papers.json (22 papers) + docs/papers_index.md | the literature this KI is judged by; each entry's text_path is fetched full text in the central paper cache. role: benchmark marks the model's own skill paper. |
| for a machine-readable summary | knowledge_infrastructure.yaml | the manifest (package, pipeline, validation tier, counts) — projected by ki_tools_common/generate_ki_manifest.py; regenerate after structural changes, never hand-edit. |
Projected 2026-10-06 from the KI's actual contents — 9 components present. Refresh: python3 ki_tools_common/generate_skill_map.py --ki_dir <this KI>.
<!-- KI-MAP:END -->
<!-- KI-TOOL-INDEX:BEGIN (projected by generate_skill_map.py — the discoverability contract: every public tool, exact path; PURPOSE stays human-authored elsewhere) -->
Executable tool index (projected — complete by construction)
Every public tool in this KI, by exact path. What each is FOR lives in the
human-written Tool Inventory above; --help on any of these prints its arguments.
| tool (exact path) | invocation |
|---|---|
| tools/calibrate_hms.py (SURROGATE, not HEC-HMS) | KISSPATH_PYTHON_ENV/bin/python {KI}/tools/calibrate_hms.py --help |
| tools/convert_forcing_to_hms.py | KISSPATH_PYTHON_ENV/bin/python {KI}/tools/convert_forcing_to_hms.py --help |
| tools/convert_soil_to_hms.py | KISSPATH_PYTHON_ENV/bin/python {KI}/tools/convert_soil_to_hms.py --help |
| tools/parse_hms_output.py | KISSPATH_PYTHON_ENV/bin/python {KI}/tools/parse_hms_output.py --help |
| tools/run_hec_hms.py (SURROGATE, not HEC-HMS) | KISSPATH_PYTHON_ENV/bin/python {KI}/tools/run_hec_hms.py --help |
| tools/run_hms_engine.py (default run route: the REAL engine) | KISSPATH_PYTHON_ENV/bin/python {KI}/tools/run_hms_engine.py --help |
| tools/validate_hms.py | KISSPATH_PYTHON_ENV/bin/python {KI}/tools/validate_hms.py --help |
7 public tools; _-prefixed helpers and packaging files excluded.
<!-- KI-TOOL-INDEX:END -->
HEC-HMS (Hydrologic Engineering Center — Hydrologic Modeling System) — Knowledge Infrastructure
Package: hydrocraft-hec-hms v1.0.0
Model: HEC-HMS 4.14 (USACE Hydrologic Engineering Center), official Linux build, run headless by tools/run_hms_engine.py
Created by: Jianyun Zhang Research Group, Hohai University
Last updated: 2026-03-28
Stats: current tool, stage-doc and triplet counts: the KI map at the top of this file
Validation status (2026-10-06): the REAL engine reproduces the USACE castro sample exactly (runs Current + Future, 54/54 element peaks/volumes/peak times; Outlet peak 540.2749050 cfs) and, for run Current, scores NSE 0.858 / KGE 0.811 / r 0.933 / PBIAS +0.98 % against the observed Castro Valley outlet flow of 16 Jan 1973 (USACE parameters, no calibration by us; see Validation).
Data Preparation
Forcing data
Data Sources: convert_forcing_to_hms.py reads daily CMFD NetCDFs with declared units and geographic coordinates in declared degrees; partial-day values (time bounds/steps not a whole day) and values outside NetCDF valid_range/valid_min/valid_max fail. It requires an explicit --pet_csv (date,pet_mm, mm/day); there is no automatic Hargreaves fallback or assumed temperature range. Missing required dates/active cells fail before writing. Temperature is required by default; --temperature_mode unused explicitly omits it only for a model with no temperature-dependent process. See S4.
Data Validation Reference: See data_ki/CMFD/SKILL.md for CMFD unit documentation and known traps.
See data_ki/HWSD/SKILL.md for soil property documentation.
See data_ki/ObservedQ/SKILL.md for observed discharge data.
Overview
Real engine: tools/run_hms_engine.py runs the official USACE HEC-HMS 4.14 binary headless (Jython API: Project.open -> computeRun) on an HMS project folder, checks the run log and a fresh results file, exports DSS series to CSV and can compare against reference results. This is the model of record.
SURROGATE: tools/run_hec_hms.py (and calibrate_hms.py, which calls it) is a HydroCraft Python stand-in for SCS-CN + SCS UH + Linear Reservoir + Muskingum. It is NOT HEC-HMS; never report its output as a HEC-HMS result. It stays only for the legacy daily CSV workflow (Quick Start steps 1-6). The forcing/soil tools (convert_*_to_hms.py) still write CSV/JSON for the surrogate; they do not yet write HMS .basin/.met/.gage/DSS files, so a new basin for the real engine needs an HMS project built outside these tools (open gap).
What HEC-HMS does: Event-based and continuous rainfall-runoff simulation. Computes:
- Precipitation losses (infiltration) via SCS Curve Number, Green-Ampt, or Initial+Constant
- Direct runoff transform via SCS Unit Hydrograph, Clark UH, Snyder UH, or ModClark
- Channel routing via Muskingum, Muskingum-Cunge, Modified Puls, or Lag
- Baseflow via Linear Reservoir, Recession, or Constant Monthly
- Snowmelt via Temperature Index or Energy Budget
- Evapotranspiration via Monthly Average, Priestley-Taylor, or Gridded
- Reservoir routing via specified release, elevation-storage-discharge
Key difference from other HydroCraft models: HEC-HMS is a lumped/semi-distributed event or continuous model. Unlike VIC (gridded, physically-based) or SWAT (HRU-based), HEC-HMS operates on subbasins connected by channel reaches. Each subbasin is treated as a lumped unit. The model is excellent for flood forecasting and design storm analysis but does not resolve spatial variability within subbasins.
Installation
Official USACE executable (required for HEC-HMS results)
HEC-HMS 4.14: KISSPATH_HOME/engine_builds_20261006/HEC_HMS/HEC-HMS-4.14/ (bundled JRE)
Headless launcher (KI binary): KISSPATH_HOME/engine_builds_20261006/HEC_HMS/run_hms_headless.sh
(same java call as hec-hms.sh + -Djava.awt.headless=true, no DISPLAY check; env HMS_ENGINE overrides)
Build log: KISSPATH_HOME/engine_builds_20261006/HEC_HMS/BUILD_LOG.md
Source: https://github.com/HydrologicEngineeringCenter/hec-downloads/releases/download/1.0.47/HEC-HMS-4.14-linux64.tar.gz
License: US Government Public Domain (binary distribution)
KI run tool: python3 tools/run_hms_engine.py --project <p>.hms --run <Run> --workdir <dir>
Official samples: HEC-HMS-4.14/samples.zip (castro, river_bend, tenk, tifton)
Python SURROGATE (HydroCraft, not HEC-HMS)
Tools: ki/tools/*.py
Dependencies: numpy, pandas, xarray, netCDF4, geopandas, shapely, matplotlib, scipy
Python: 3.10+
The official HEC-HMS distribution is available without charge from USACE. The HydroCraft Python stand-in is a SURROGATE; no equivalence with the real engine has been shown.
Test example (real engine — official castro sample)
mkdir -p /tmp/hms_samples && cd /tmp/hms_samples && unzip -q KISSPATH_HOME/engine_builds_20261006/HEC_HMS/HEC-HMS-4.14/samples.zip 'samples/castro/*'
python3 tools/run_hms_engine.py --project /tmp/hms_samples/samples/castro/castro.hms \
--run Current --run Future --workdir /tmp/hms_castro_run --export Outlet:FLOW \
--reference_results /tmp/hms_samples/samples/castro/results
# expect exit 0, reference n_mismatch 0, Outlet peak 540.2749050 cfs
Surrogate test example (NOT HEC-HMS)
python3 ki/tools/run_hec_hms.py \
--basin_shp /path/to/basin.shp \
--forcing_dir /path/to/forcing/ \
--soil_file /path/to/soil.img \
--landcover_file /path/to/landcover.tif \
--start_date 1980-01-01 --end_date 1990-12-31 \
--output_dir /path/to/output/
Pipeline
| # | Stage | Tool | Parallel | Notes |
|---|-------|------|----------|-------|
| 0 | Configuration | — | — | Set basin, period, resolution, paths |
| 1 | Domain Setup | — | — | Define subbasin(s) from DEM + shapefile |
| 2 | Soil Parameters | convert_soil_to_hms.py | Yes | HWSD → SCS CN, Soil Group, Green-Ampt params |
| 3 | Land Cover | convert_soil_to_hms.py | Yes | AVHRR → CN adjustment by land use |
| 4 | Forcing Conversion | convert_forcing_to_hms.py | Yes | CMFD/MSWX → HEC-HMS precipitation + PET |
| 5 | Model Parameters | — | — | Set loss, transform, routing, baseflow methods |
| 6 | Model Execution (REAL engine) | run_hms_engine.py | No | HEC-HMS 4.14 headless on an HMS project; log + fresh-results checks; DSS export to CSV |
| 6s | Model Execution (SURROGATE) | run_hec_hms.py | No | Python stand-in, NOT HEC-HMS (legacy daily CSV workflow only) |
| 7 | Output Parsing | run_hms_engine.py exports / parse_hms_output.py (surrogate CSV) | No | Discharge time series to CSV |
| 8 | Routing (optional) | — | — | Channel routing already integrated in run |
Output Description
This section restates the KI dag output facts. If this body and dag.yaml ever
disagree, dag.yaml is the source of truth.
Headline output (validation_rank: 1 in dag.yaml):
discharge— Simulated routed streamflow at the basin (or subbasin) outlet. (m^3/s)
| Output variable (dag var) | Validation role | Unit | Description |
|-----------------------------|-----------------|------|-------------|
| discharge | rank 1 output | m^3/s | Simulated routed streamflow at the basin (or subbasin) outlet. |
Other dag outputs present in this KI: runoff_depth, loss, subbasin_outflow.
Unit Table / Unit Conversion Table
Exact I/O shapes live in docs/format_spec.yaml; this table is the body-level
unit checklist for the HEC-HMS pipeline and known unit traps.
| Variable | Source or pipeline unit | Model/output unit | Conversion or check |
|----------|-------------------------|-------------------|---------------------|
| Precipitation | CMFD mm/day | daily HEC-HMS timestep mm | Use daily value directly for daily runs; for sub-daily runs divide by the number of timesteps per day. |
| Temperature | CMFD K | HEC-HMS Celsius | Subtract 273.15. |
| PET | forcing converter output mm | HEC-HMS daily PET depth | Confirm daily-vs-monthly before execution; see dt_118. |
| Basin area | km2 | km2 in runoff-to-discharge conversion | Do not pass m2 or acres where area_km2 is expected. |
| Runoff depth | model intermediate/output runoff_depth | depth variable | Listed as a dag output; consult dag.yaml for its authoritative unit. |
| Loss | model intermediate/output loss | loss variable | Listed as a dag output; consult dag.yaml for its authoritative unit. |
| Subbasin outflow | model output subbasin_outflow | routed flow variable | Listed as a dag output; consult dag.yaml for its authoritative unit. |
| Discharge | routed streamflow | m^3/s | Rank-1 dag output: discharge. |
Tools Reference
| # | Tool | Stage | Lines | Purpose |
|---|------|-------|-------|---------|
| 1 | convert_forcing_to_hms.py | s4 | ~450 | CMFD/MSWX NetCDF → daily precip (mm) + PET (mm) |
| 2 | convert_soil_to_hms.py | s2-s3 | ~350 | HWSD + AVHRR → SCS Curve Number + soil properties |
| 3 | run_hms_engine.py | s6 | ~400 | REAL engine: run HEC-HMS 4.14 headless, check log/results, export DSS, compare to reference |
| 3s | run_hec_hms.py | s6 | ~430 | SURROGATE (not HEC-HMS): Python SCS-CN + SCS UH + Muskingum + baseflow |
| 4 | parse_hms_output.py | s7 | ~250 | Parse output CSV → standardized discharge CSV |
| 5 | validate_hms.py | s7 | ~350 | Compare simulated vs observed Q, compute metrics |
| 6 | calibrate_hms.py | s5 | ~290 | SURROGATE calibration (GLUE-style) of run_hec_hms.py; not HEC-HMS parameters |
Skill Knowledge
| # | Document | Stage | Knowledge Type |
|---|----------|-------|----------------|