Skip to content
Back to skills

Docs

ASecurity

> **Stage ID**: s2_hru_definition > **Pipeline order**: 2 of 9 > **Depends on**: s1_watershed_delineation

  • 200 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 11, 2026
testingpythongobashdatabase

Works with

  • cli

Security analysis

A100/100

Pro scans all 15 files and shows the line behind each finding

Scanned September 11, 2026

npx -y skills add lzwei196/KISS---Knowledge-Infrastructure-for-Scientific-Simulation --skill docs --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Docs?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Docs
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/lzwei196-docs-aa6c6518/badge)](https://www.skillsdirectory.com/skills/lzwei196-docs-aa6c6518)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# HRU Definition — Skill Document

> **Stage ID**: s2_hru_definition
> **Pipeline order**: 2 of 9
> **Depends on**: s1_watershed_delineation

## Purpose

Hydrologic Response Units (HRUs) are the fundamental computational units in SWAT+. Each HRU is a unique combination of subbasin + land use + soil type + slope class. SWAT+ simulates water balance, nutrient cycling, and plant growth independently for each HRU, then aggregates results to the subbasin level. Incorrect HRU definition propagates errors through all hydrological and water quality calculations.

## Prerequisites

Before starting this stage, verify:

- [ ] Subbasin shapefile exists from Stage 1 (`subbasins.shp`)
- [ ] Land use raster exists and covers the basin (NLCD, GlobeLand30, ESA WorldCover, or local)
- [ ] Land use lookup table maps raster values to SWAT+ plant codes (e.g., NLCD 41 -> FRSD)
- [ ] Soil raster exists (SSURGO MUKEY, HWSD MU, or FAO soil map)
- [ ] Soil lookup table maps raster values to soils.sol names
- [ ] DEM (for slope calculation)

## Inputs

| Input | Type | Source | Description |
|-------|------|--------|-------------|
| Subbasin shapefile | file | S1 output | Subbasin boundaries |
| Land use raster | file | NLCD / ESA / GlobeLand30 | Land use/land cover classification |
| Land use lookup | file | User-created CSV | Maps raster values to SWAT+ codes |
| Soil raster | file | SSURGO / HWSD / FAO | Soil type spatial data |
| Soil lookup | file | User-created CSV | Maps raster values to soils.sol names |
| DEM | file | Same as S1 | For slope calculation |
| Slope classes | config | User choice | Slope break points in percent |

## Procedure

### Step 1: Reclassify land use raster

Map raw land use raster values to SWAT+ plant database codes using the lookup table.

Common SWAT+ land use codes:
- `AGRL` (generic agriculture), `CORN` (corn), `SOYB` (soybean), `WWHT` (winter wheat)
- `FRSD` (deciduous forest), `FRSE` (evergreen forest), `FRST` (mixed forest)
- `PAST` (pasture), `RNGE` (range), `URBN` (urban), `WATR` (water), `WETL` (wetland)

**Expected result**: Reclassified land use raster with SWAT+ codes.

### Step 2: Reclassify soil raster

Map soil raster values to soil names matching entries in soils.sol.

**Expected result**: Reclassified soil raster with names matching soils.sol.

### Step 3: Generate slope classes

Compute slope from DEM and classify into user-defined classes.

Default slope classes: [0, 3, 8, 15, 9999] (i.e., 0-3%, 3-8%, 8-15%, >15%)

**Expected result**: Slope class raster.

### Step 4: Create HRU overlay

```bash
python tools/s2/create_hru_overlay.py
```

Overlay land use, soil, and slope class rasters onto subbasin boundaries. Each unique combination becomes an HRU.

**Expected result**: hru-data.hru file with one record per HRU.

### Step 5: Apply HRU thresholds

```bash
python tools/s2/apply_hru_threshold.py
```

Remove HRUs below area thresholds and redistribute their area to dominant HRUs. Recommended thresholds: land use 5-10%, soil 5-10%, slope 10-20%.

**Expected result**: Filtered hru-data.hru with reduced HRU count. Total area preserved.

**If this fails**: See diagnostic triplet dt_004. Verify area conservation after filtering.

### Step 6: Generate HRU connectivity

Write hru.con (HRU connectivity to routing units and landscape units).

**Expected result**: hru.con file with routing entries for all HRUs.

## Expected Outputs

| Output | Path | Verification |
|--------|------|--------------|
| hru-data.hru | `TxtInOut/hru-data.hru` | 50-5000 HRUs; each has valid land use, soil, slope |
| hru.con | `TxtInOut/hru.con` | One entry per HRU; all route to valid spatial objects |
| topography.hyd | `TxtInOut/topography.hyd` | Slope and slope length for each HRU |
| hydrology.hyd | `TxtInOut/hydrology.hyd` | Hydrological parameters (CN, etc.) for each HRU |

## Validation Checks

1. **HRU count**: Should be 50-5000 for typical basins. <10 is too few for spatial heterogeneity; >10000 slows execution without improving accuracy.

2. **Land use coverage**: All dominant land uses in the basin are represented in the HRU set.
   - Parse hru-data.hru and count unique land use types
   - Expected: at least 3-5 land use types for typical basins

3. **Area conservation**: Total HRU area equals watershed area within 0.1%.
   - Sum all HRU areas in hru-data.hru
   - Compare to watershed area from S1

4. **No orphan HRUs**: Every HRU in hru-data.hru has a corresponding entry in hru.con.

## Common Pitfalls

> **PITFALL**: HRU threshold too aggressive (>20%), biasing water yield
> Removing >20% of basin area through thresholds significantly changes the land use/soil distribution. Agricultural land (often small patches) may be entirely removed, eliminating nutrient source areas.
> **Do this instead**: Use 5-10% thresholds. For water quality studies, use 0% threshold (keep all HRUs).
> See diagnostic triplet dt_004 for full details.

> **PITFALL**: Land use raster values not matching SWAT+ plant codes
> If the lookup table is wrong, HRUs get assigned non-existent plant types. SWAT+ may crash or silently use default parameters.
> **Do this instead**: Verify every raster value has a valid mapping. Check against plants.plt database.

> **PITFALL**: Soil raster and soils.sol name mismatch
> If soil names in the raster lookup do not match soils.sol entries exactly (case-sensitive), SWAT+ assigns zero soil properties.
> **Do this instead**: Cross-check soil names after HRU creation against soils.sol header names.

---

*This skill document is part of the SWAT+ knowledge infrastructure.*
*Stage 2 of 9 | Tools used: create_hru_overlay, apply_hru_threshold | Related triplets: dt_004*

Files in this skill

  • REFERENCES.md1.6 KB
  • format_spec.yaml72.1 KB
  • model_couplings.yaml11.8 KB
  • papers.json7 KB
  • s1_watershed_delineation_skill.md6.7 KB
  • s2_hru_definition_skill.md5.5 KB
  • s3_weather_preparation_skill.md8.9 KB
  • s4_soil_database_skill.md5.8 KB
  • s5_landuse_management_skill.md6 KB
  • s6_calibration_parameters_skill.md6.5 KB
  • s7_simulation_config_skill.md8.5 KB
  • s8_model_execution_skill.md5.1 KB
  • s9_output_parsing_skill.md7 KB
  • validation_convention.yaml21.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…