pywatershed_config¶
pywatershed_config
¶
Define the pywatershed run configuration schema and YAML loader.
Provide Pydantic models that validate the YAML configuration for the
hydro-param pywatershed run command. This is a Phase 2 (model-specific)
config that consumes pre-existing SIR output from the generic Phase 1
pipeline. It does NOT configure the Phase 1 pipeline itself.
The configuration covers nine sections: domain file paths, simulation time period, SIR output location, static dataset declarations, forcing time series, climate normals, manual parameter overrides, calibration seed generation, and output file layout.
Notes
Version 4.0 adds three data sections (static_datasets, forcing,
climate_normals) that declare which pipeline datasets provide each
pywatershed parameter. This creates a consumer-oriented, self-documenting
contract between the Phase 1 pipeline and the Phase 2 derivation plugin.
See Also
hydro_param.sir_accessor.SIRAccessor : Lazy SIR variable loader. hydro_param.plugins.DerivationContext : Derivation step context. hydro_param.cli.pws_run_cmd : Two-phase workflow consumer.
ParameterEntry
¶
Bases: BaseModel
Declare the SIR data source for a single pywatershed parameter.
Each entry maps a pywatershed parameter to the pipeline dataset, source variable(s), and zonal statistic that produced the SIR data.
Exactly one of variable (single) or variables (list) must be
provided for entries backed by SIR data. Both may be None only
for entries whose source is not a pipeline dataset (e.g.,
waterbody parameters derived from fabric overlay).
| PARAMETER | DESCRIPTION |
|---|---|
source
|
Pipeline dataset registry name (e.g.,
TYPE:
|
variable
|
Source variable name when a single variable is used.
TYPE:
|
variables
|
Source variable names when multiple variables contribute
(e.g.,
TYPE:
|
statistic
|
Zonal statistic applied (
TYPE:
|
year
|
NLCD year(s) for multi-epoch land cover.
TYPE:
|
time_period
|
Temporal range
TYPE:
|
description
|
Human-readable description of what this parameter represents.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If both |
TopographyDatasets
¶
Bases: BaseModel
Topography parameters derived from DEM zonal statistics.
| PARAMETER | DESCRIPTION |
|---|---|
available
|
Curated datasets available in the registry for this category.
TYPE:
|
hru_elev
|
Mean HRU elevation.
TYPE:
|
hru_slope
|
Mean HRU land surface slope.
TYPE:
|
hru_aspect
|
Mean HRU aspect.
TYPE:
|
SoilsDatasets
¶
Bases: BaseModel
Soil parameters derived from soil property datasets.
| PARAMETER | DESCRIPTION |
|---|---|
available
|
Curated datasets available in the registry for this category.
TYPE:
|
soil_type
|
Soil type classification (1=sand, 2=loam, 3=clay).
TYPE:
|
sat_threshold
|
Gravity reservoir storage capacity (from porosity).
TYPE:
|
soil_moist_max
|
Maximum available water-holding capacity.
TYPE:
|
soil_rechr_max_frac
|
Recharge zone storage as fraction of soil_moist_max.
TYPE:
|
LandcoverDatasets
¶
Bases: BaseModel
Land cover parameters for vegetation type, density, and interception.
| PARAMETER | DESCRIPTION |
|---|---|
available
|
Curated datasets available in the registry for this category.
TYPE:
|
cov_type
|
Vegetation cover type.
TYPE:
|
hru_percent_imperv
|
Impervious surface fraction.
TYPE:
|
covden_sum
|
Summer vegetation cover density (0--1 fraction).
TYPE:
|
covden_win
|
Winter vegetation cover density (0--1 fraction).
TYPE:
|
srain_intcp
|
Summer rain interception storage capacity (inches).
TYPE:
|
wrain_intcp
|
Winter rain interception storage capacity (inches).
TYPE:
|
snow_intcp
|
Snow interception storage capacity (inches).
TYPE:
|
SnowDatasets
¶
Bases: BaseModel
Snow parameters from depletion curve classification and historical SWE data.
| PARAMETER | DESCRIPTION |
|---|---|
available
|
Curated datasets available in the registry for this category.
TYPE:
|
hru_deplcrv
|
Snow depletion curve class per HRU. Source is typically the GFv1.1
CV_INT raster (categorical majority). Indexes into the SDC table
to populate
TYPE:
|
snarea_thresh
|
Snow depletion threshold (calibration seed from historical max SWE).
TYPE:
|
WaterbodyDatasets
¶
Bases: BaseModel
Depression storage and HRU type from waterbody overlay.
| PARAMETER | DESCRIPTION |
|---|---|
available
|
Curated datasets available in the registry for this category.
TYPE:
|
hru_type
|
HRU type (0=inactive, 1=land, 2=lake, 3=swale).
TYPE:
|
dprst_frac
|
Fraction of HRU with surface depressions.
TYPE:
|
StaticDatasetsConfig
¶
Bases: BaseModel
Static dataset declarations grouped by domain category.
Each category contains explicit parameter fields that map to SIR data produced by the Phase 1 pipeline.
| PARAMETER | DESCRIPTION |
|---|---|
topography
|
DEM-derived parameters (elevation, slope, aspect).
TYPE:
|
soils
|
Soil property parameters.
TYPE:
|
landcover
|
Land cover and impervious surface parameters.
TYPE:
|
snow
|
Historical snow parameters.
TYPE:
|
waterbodies
|
Depression storage and HRU type.
TYPE:
|
ForcingConfig
¶
Bases: BaseModel
Temporal forcing time series declarations.
The Phase 2 derivation plugin converts forcing data from SIR units (metric: mm, degC) to PRMS units (inches, degF) during output formatting. pywatershed expects one-variable-per-NetCDF.
| PARAMETER | DESCRIPTION |
|---|---|
available
|
Temporal-capable datasets available in the registry.
TYPE:
|
prcp
|
Daily precipitation.
TYPE:
|
tmax
|
Daily maximum temperature.
TYPE:
|
tmin
|
Daily minimum temperature.
TYPE:
|
ClimateNormalsConfig
¶
Bases: BaseModel
Long-term climate statistics for derived parameters.
Can use the same source as forcing, or a different one (e.g., forcing from CONUS404-BA but normals from gridMET).
| PARAMETER | DESCRIPTION |
|---|---|
available
|
Temporal-capable datasets available in the registry.
TYPE:
|
jh_coef
|
Jensen-Haise PET coefficient (monthly, from tmax/tmin normals).
TYPE:
|
transp_beg
|
Month transpiration begins (from monthly mean tmin threshold).
TYPE:
|
transp_end
|
Month transpiration ends (from monthly mean tmin threshold).
TYPE:
|
PwsDomainConfig
¶
Bases: BaseModel
Define the spatial domain for pywatershed model setup.
Point to pre-existing fabric and segment files on disk. hydro-param does NOT fetch or subset fabrics — use pynhd or pygeohydro upstream.
| ATTRIBUTE | DESCRIPTION |
|---|---|
fabric_path |
Path to the HRU fabric file (GeoPackage or GeoParquet).
TYPE:
|
segment_path |
Path to the segment/flowline file for routing topology.
TYPE:
|
waterbody_path |
Path to NHDPlus waterbody polygon file (GeoPackage or GeoParquet)
for depression storage overlay (step 6). Must contain an
TYPE:
|
id_field |
Feature ID column name in the fabric (default
TYPE:
|
segment_id_field |
Segment ID column name in the segment fabric (default
TYPE:
|
Notes
The fabric_path must point to a pre-existing file produced by
pynhd, pygeohydro, or similar upstream tools.
PwsTimeConfig
¶
Bases: BaseModel
Define the simulation time period for pywatershed.
| ATTRIBUTE | DESCRIPTION |
|---|---|
start |
Simulation start date in ISO format (e.g.,
TYPE:
|
end |
Simulation end date in ISO format (e.g.,
TYPE:
|
timestep |
Temporal resolution. Only daily is currently supported, which matches PRMS's native timestep.
TYPE:
|
PwsParameterOverrides
¶
Bases: BaseModel
Specify manual overrides for derived parameter values.
Allow users to inject known-good values (e.g., from calibration) that bypass the standard derivation pipeline. Overrides are applied after all other derivation steps complete.
| ATTRIBUTE | DESCRIPTION |
|---|---|
values |
Parameter name to scalar or per-HRU value mapping. Scalars are broadcast to all HRUs. List values must match the number of HRUs in the fabric.
TYPE:
|
from_file |
Path to a NetCDF or CSV file containing override values. Not yet implemented.
TYPE:
|
PwsCalibrationConfig
¶
Bases: BaseModel
Configure calibration seed generation for PRMS parameters.
PRMS calibration parameters (e.g., carea_max, soil_moist_max,
K_coef) need physically plausible initial values. This config
controls whether and how those seeds are generated.
| ATTRIBUTE | DESCRIPTION |
|---|---|
generate_seeds |
Whether to generate calibration seed values. Default
TYPE:
|
seed_method |
TYPE:
|
preserve_from_existing |
Parameter names to preserve from an existing parameter file rather than re-deriving. Useful for retaining calibrated values during fabric updates.
TYPE:
|
PwsOutputConfig
¶
Bases: BaseModel
Specify output file layout for pywatershed model setup.
Control the directory structure and filenames for the four output components: static parameters, climate forcing, solar tables, and simulation control.
| ATTRIBUTE | DESCRIPTION |
|---|---|
path |
Root output directory. Created if it does not exist.
Default
TYPE:
|
format |
Output format.
TYPE:
|
parameter_file |
Filename for static parameters (default
TYPE:
|
forcing_dir |
Subdirectory for climate forcing files (default
TYPE:
|
control_file |
Filename for simulation control (default
TYPE:
|
soltab_file |
Filename for solar radiation tables (default
TYPE:
|
PywatershedRunConfig
¶
Bases: BaseModel
Define the top-level configuration for pywatershed model setup.
A consumer-oriented, self-documenting contract between the Phase 1
pipeline and the Phase 2 pywatershed derivation plugin. Three data
sections (static_datasets, forcing, climate_normals)
declare which pipeline datasets provide each pywatershed parameter.
| PARAMETER | DESCRIPTION |
|---|---|
target_model
|
Target model identifier (fixed to
TYPE:
|
version
|
Config schema version (
TYPE:
|
domain
|
Domain fabric file paths and ID field names.
TYPE:
|
time
|
Simulation time period.
TYPE:
|
sir_path
|
Path to the Phase 1 pipeline output directory containing
TYPE:
|
static_datasets
|
Static dataset declarations grouped by domain category.
TYPE:
|
forcing
|
Temporal forcing time series declarations.
TYPE:
|
climate_normals
|
Long-term climate statistics for derived parameters.
TYPE:
|
parameter_overrides
|
Manual parameter value overrides.
TYPE:
|
calibration
|
Calibration seed generation options.
TYPE:
|
output
|
Output directory structure and filenames.
TYPE:
|
See Also
load_pywatershed_config : YAML loader for this schema. hydro_param.cli.pws_run_cmd : Two-phase workflow consumer.
declared_entries
¶
Collect all declared ParameterEntry objects from the config.
Walk static_datasets, forcing, and climate_normals
sections and return a flat dictionary keyed by parameter name.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, ParameterEntry]
|
Parameter name to entry mapping for all non-None entries. |
Source code in src/hydro_param/pywatershed_config.py
validate_available_fields
¶
Check that available dataset names exist in the registry.
Load the bundled dataset registry (including user-local overlays
from ~/.hydro-param/datasets/) and verify that every name in
each category's available list is a known dataset. Unknown
entries emit a UserWarning rather than raising.
Warnings
UserWarning
For each dataset name in an available list that is not
found in the current registry.
Source code in src/hydro_param/pywatershed_config.py
load_pywatershed_config
¶
Load and validate a pywatershed run configuration from YAML.
Parse the YAML file and construct a fully validated
PywatershedRunConfig with Pydantic's strict type coercion.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Path to the YAML config file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PywatershedRunConfig
|
Validated configuration ready for |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If path does not exist. |
YAMLError
|
If the file contains invalid YAML. |
ValidationError
|
If the config fails schema validation (missing required fields, type mismatches, extra fields). |
Notes
Path fields (sir_path, domain.fabric_path, etc.) are
returned as-is from the YAML. Relative paths are resolved against
the config file's parent directory by the CLI consumer
(pws_run_cmd), not by this loader.