Skip to content
Back to skills

Docs

ASecurity

Convert CMFD/MSWX meteorological forcing to wflow NetCDF format with correct units. wflow requires precipitation (mm/timestep), temperature (degC), and PET (mm/timestep). Unit errors here produce silent failures — the model runs but results are scientifically meaningless (dt_w001, dt_w002, dt_w003).

  • 231 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 11, 2026
testingpython

Works with

  • cli

Security analysis

A100/100

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

Scanned November 9, 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-8418c9bc/badge)](https://www.skillsdirectory.com/skills/lzwei196-docs-8418c9bc)

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
# s2 — Forcing Data Preparation Skill Document

## Purpose

Convert CMFD/MSWX meteorological forcing to wflow NetCDF format with correct units. wflow requires precipitation (mm/timestep), temperature (degC), and PET (mm/timestep). Unit errors here produce silent failures — the model runs but results are scientifically meaningless (dt_w001, dt_w002, dt_w003).

## Prerequisites

- Stage s1 complete (staticmaps.nc exists for grid definition)
- Forcing data available: CMFD (China) or MSWX (global), read straight from the data store
- Python packages: xarray, netCDF4, numpy, pandas

## Inputs

| Name | Type | Source | Description |
|------|------|--------|-------------|
| source | name | s0 config | `cmfd`, `mswx`, `nasa_power` or `gswp3` (`--source`) |
| forcing_dir | directory | data store | Root folder of the source (CMFD: `data/forcing/Data_forcing_03hr_010deg`) |
| staticmaps.nc | file | s1 | Grid definition for spatial alignment |
| start_year, end_year | int | s0 config | Simulation period |

## Procedure

1. **Select forcing source**: CMFD inside China, MSWX elsewhere
2. Run `convert_forcing_to_wflow.py --source <source> --forcing_dir <dataset root> --staticmaps_nc <staticmaps.nc>`
3. **Verify units immediately after conversion**:
   - Mean daily precip: 1-10 mm/day for most basins (check: `ncdump -v precip forcing.nc | tail`)
   - Temperature range: -30 to 45 degC (if > 200, still in Kelvin — dt_w002)
   - Mean PET: 1-8 mm/day depending on climate
4. If PET is missing, run `calculate_pet.py` (Hargreaves or Penman-Monteith)
5. Verify forcing.nc spatial dimensions match staticmaps.nc (dt_w008)

## Unit Conversion Table (CRITICAL)

| Variable | CMFD Unit | MSWX Unit | wflow Unit | Conversion |
|----------|-----------|-----------|------------|------------|
| Precipitation | mm/3hr | mm/3hr | mm/day | Sum 8 values per day |
| Temperature | K | K | degC | Subtract 273.15 |
| Specific humidity | kg/kg | kg/kg | — | Used for PET calc |
| Shortwave radiation | W/m2 | W/m2 | — | Used for PET calc |
| Wind speed | m/s | m/s | — | Used for PET calc |
| Pressure | Pa | Pa | — | Used for PET calc |

## Expected Outputs

| Output | Path | Verification |
|--------|------|-------------|
| forcing.nc | outputs/<run>/wflow_project/forcing.nc | Has precip, temp, pet variables |

## Validation Checks

1. forcing.nc has 3 variables: precip, temp, pet
2. Time dimension length = (end_year - start_year + 1) * 365 (approximately)
3. Spatial dimensions match staticmaps.nc
4. Mean precip is 1-10 mm/day
5. Temperature range is physically plausible (-30 to 45 degC)
6. PET is 0-15 mm/day (no negatives)
7. No NaN values in active cells

## Common Pitfalls

- **dt_w001**: Precip in mm/s instead of mm/day (runoff 86400x too high)
- **dt_w002**: Temperature in Kelvin (no snow in cold basins, wrong PET)
- **dt_w003**: PET missing or zero (all precip becomes runoff)
- **dt_w004**: Snow in tropical basins (temperature offset not applied)
- **dt_w008**: Grid mismatch between forcing and staticmaps (DimensionMismatch)


## Strict input contract (2026-10-03 repair)

The converter requires the full requested daily calendar and identical records
for every active `wflow_subcatch` cell. Missing, nonfinite, negative rain/PET,
inverted temperature extrema, missing cell records and truncated arrays fail
before writing. No weather is interpolated or substituted. Inactive grid padding
is NaN and must be excluded from basin statistics.

PET uses the documented Hargreaves approximation for the whole file. Tmin/Tmax
must be supplied; equal extrema are valid and yield zero PET. The former 0.5 C
minimum temperature range was removed. Daily precipitation and PET are mm per
86400-second model step; temperature is Celsius.

For CMFD with original-source validation, pass `--forcing_dir` and omit `--source`.
This direct route requires exactly one original P and T file per requested month,
declared kg m-2 s-1 and K units, all matching 3-hourly source timestamps and finite
values in every active cell before daily reduction. SRad is unnecessary for HG.

The `--source` route validates the shared loader's daily output, but cannot undo
source gaps or replaced extrema hidden by that dependency. Its NetCDF
`validation_scope` records this narrower guarantee. Geographic grid coordinates
and an explicit `wflow_subcatch` mask are required. Projected grids require an
explicit reprojection before point-source lookup.

Files in this skill

  • REFERENCES.md1.6 KB
  • format_spec.yaml45.8 KB
  • papers.json5.4 KB
  • s0_configuration_skill.md2.2 KB
  • s10_reservoir_skill.md8.2 KB
  • s1_hydromt_setup_skill.md15.3 KB
  • s2_forcing_skill.md2.9 KB
  • s3_parameters_skill.md2.9 KB
  • s4_execution_skill.md2.8 KB
  • s5_output_skill.md2.5 KB
  • s6_s8_sediment_skill.md6.1 KB
  • s9_coupling_skill.md3.1 KB
  • validation_convention.yaml14.8 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.

View all in testing →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.