Context
PR #214 replaced the hardcoded-Python-script workflow for configuring a Hapi run with a YAML
file plus a builder. This issue documents that change.
What Changed
- New module
src/hapi/config.py: a pure pydantic schema (RunConfig and its nested blocks)
that validates a parsed YAML mapping for both lumped and distributed runs. Imports nothing
from hapi, so it stays a leaf of the import graph.
- New
Catchment.from_yaml classmethod (src/hapi/catchment.py): reads the file, validates it,
resolves every relative path against the file's own directory, and makes the read_* calls
in the order the build-then-mutate pattern requires. Calibration.from_yaml returns its own
type; Run.from_yaml is overridden to refuse, since Run holds entry points rather than
being a catchment.
- New
MeteoInputs.from_config (src/hapi/inputs.py): dispatches over meteo.source to the
three existing loaders (from_rasters, from_netcdf, from_netcdf_files).
- Validation rules: required blocks per
spatial_resolution and meteo.source, refusal of
fields the chosen run shape will never read, routing_method derived from
parameters.maxbas when unstated (and required to agree with it otherwise), the resolved
meteorological window checked rather than two independent pairs, and every missing input
path reported together before any reader runs.
- All four Coello example scripts (
examples/hydrological-model/coello/run/) ported to
YAML-driven configurations, each script paired with a .yaml file beside it.
- New docs page
docs/examples/run-configuration.md, linked from the two existing run pages,
plus the generated API reference docs/api/config.md.
Affected locations
| File |
Symbol |
src/hapi/config.py |
RunConfig, CatchmentConfig, MeteoConfig, FlowNetworkConfig, ParametersConfig, ConceptualModelConfig, GaugesConfig, OutputsConfig |
src/hapi/catchment.py |
Catchment.from_yaml |
src/hapi/inputs.py |
MeteoInputs.from_config |
src/hapi/run.py |
Run.from_yaml (override, refuses) |
Usage Example
from hapi.catchment import Catchment
from hapi.run import Run
model = Catchment.from_yaml("coello-distributed-model-run-netcdf.yaml")
Run.RunHapi(model)
Verification
Implemented in #214.
Context
PR #214 replaced the hardcoded-Python-script workflow for configuring a Hapi run with a YAML
file plus a builder. This issue documents that change.
What Changed
src/hapi/config.py: a pure pydantic schema (RunConfigand its nested blocks)that validates a parsed YAML mapping for both lumped and distributed runs. Imports nothing
from
hapi, so it stays a leaf of the import graph.Catchment.from_yamlclassmethod (src/hapi/catchment.py): reads the file, validates it,resolves every relative path against the file's own directory, and makes the
read_*callsin the order the build-then-mutate pattern requires.
Calibration.from_yamlreturns its owntype;
Run.from_yamlis overridden to refuse, sinceRunholds entry points rather thanbeing a catchment.
MeteoInputs.from_config(src/hapi/inputs.py): dispatches overmeteo.sourceto thethree existing loaders (
from_rasters,from_netcdf,from_netcdf_files).spatial_resolutionandmeteo.source, refusal offields the chosen run shape will never read,
routing_methodderived fromparameters.maxbaswhen unstated (and required to agree with it otherwise), the resolvedmeteorological window checked rather than two independent pairs, and every missing input
path reported together before any reader runs.
examples/hydrological-model/coello/run/) ported toYAML-driven configurations, each script paired with a
.yamlfile beside it.docs/examples/run-configuration.md, linked from the two existing run pages,plus the generated API reference
docs/api/config.md.Affected locations
src/hapi/config.pyRunConfig,CatchmentConfig,MeteoConfig,FlowNetworkConfig,ParametersConfig,ConceptualModelConfig,GaugesConfig,OutputsConfigsrc/hapi/catchment.pyCatchment.from_yamlsrc/hapi/inputs.pyMeteoInputs.from_configsrc/hapi/run.pyRun.from_yaml(override, refuses)Usage Example
Verification
hapi.configreaches 100% line and branch coveragereplaces
/review-roundspasses (22 + 25 findings, all resolved) and a SonarCloud sweepdocs/examples/run-configuration.mdwalks through a configuration end to endImplemented in #214.