Skip to content
Back to skills

Docs

ASecurity

Extract and structure SWAP output files into standardized CSV format for analysis, visualization, and comparison with observations.

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

Security analysis

A100/100

Pro scans all 10 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-64d9dffa/badge)](https://www.skillsdirectory.com/skills/lzwei196-docs-64d9dffa)

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
# S5: SWAP Output Parsing

## Purpose
Extract and structure SWAP output files into standardized CSV format for analysis, visualization, and comparison with observations.

## Inputs
- **SWAP output directory**: Contains result.blc, result.inc, result.vap, result.csv, etc.
- **Output prefix**: Value of OUTFIL parameter (default: "result")

## Outputs
- `water_balance.csv`: Annual water balance components (cm)
- `daily_increments.csv`: Daily flux increments (cm)
- `swap_timeseries.csv`: Custom CSV output (if SWCSV=1)
- `summary.json`: Simulation summary with totals

## Procedure
1. **Parse .blc file** (detailed yearly water balance):
   - Extract components: Rain, Irrigation, Runoff, Transpiration, Evaporation, Drainage
   - All values in cm (centimeters of water)
   - Check balance closure: Sum_In ≈ Sum_Out + ΔStorage

2. **Parse .inc file** (water balance increments):
   - Daily or output-interval records
   - Columns vary by SWAP version; common: date, daynr, rain, irrig, interc, runoff, drainage, dstor, epot, eact, tpot, tact, qbottom, gwl
   - Units: cm for depths, cm for cumulative fluxes

3. **Parse .vap file** (soil profiles):
   - Profiles at each output date
   - Columns: depth (cm), theta (m³/m³), h (cm), K (cm/d)
   - Multiple profiles per file, separated by date headers

4. **Parse native CSV** (if SWCSV=1):
   - Comma-separated with header row
   - Units specified in comment line above header
   - Variables as listed in INLIST_CSV

5. **Generate summary JSON**:
   - Total rainfall, ET, drainage over simulation
   - Number of years, daily records
   - Key ratios: ET/Rain, Drainage/Rain

## Verification
- Water balance closure: |Sum_In - Sum_Out - ΔStorage| < 0.1 cm per year
- No NaN values in parsed output
- Daily records count matches simulation days
- Soil moisture values in 0-1 range (not negative, not > OSAT)

## Traps

### TRAP 1: .blc balance includes storage change
The In/Out sums in .blc may not be equal because storage change is implicit. The difference (In - Out) equals the change in soil water storage over the balance period.

### TRAP 2: Units in .inc are cumulative
The .inc file reports cumulative values over the output interval (set by PERIOD). To get daily rates, divide by the interval length. If PERIOD=1, values are daily.

### TRAP 3: Mixed unit conventions
- Rainfall, ET, drainage in .blc: cm (centimeters)
- Soil moisture (theta): dimensionless (cm³/cm³)
- Pressure head (h): cm (negative = unsaturated)
- Hydraulic conductivity (K): cm/day
- GWL: cm below surface (negative)

### TRAP 4: Date format in output
SWAP outputs dates as DD-Mon-YYYY (e.g., "01-Jan-2002") or as day number. Parsing must handle both formats.

### TRAP 5: Multiple drainage levels
If DRAMET=3 (multi-level), drainage appears as separate entries per level in .blc. Sum all levels for total drainage.

## Example
```python
# Parse water balance from .blc
# Expected output for Hupselbrook 2002:
# {"year": 2002, "rain": 84.18, "irrigation": 0.50,
#  "interception": 3.74, "transpiration": 38.17,
#  "soil_evaporation": 16.69, "drainage": 22.11,
#  "sum_in": 84.68, "sum_out": 80.72}
```

Files in this skill

  • format_spec.yaml33.5 KB
  • papers.json7.1 KB
  • s0_configuration_skill.md2 KB
  • s1_met_forcing_skill.md3 KB
  • s2_soil_parameters_skill.md3 KB
  • s4_execution_skill.md3.2 KB
  • s5_output_parsing_skill.md3.1 KB
  • s6_visualization_skill.md2.8 KB
  • validation_convention.yaml19.2 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…