# cylin928/hydrocnhs architecture

> Architecture diagram of the GitHub repository cylin928/hydrocnhs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cylin928/hydrocnhs
- Repository: https://github.com/cylin928/hydrocnhs

## Overview

HydroCNHS is a Python framework for semi-distributed hydrological simulation coupled with human/agent behavior. The main workflow is to configure a basin model, run rainfall–runoff and routing with optional agent interventions, and collect results; sediment simulation and calibration extend that workflow. The graph preserves the documented Dam, RiverDiv, Conveying, and InSitu APIs, plus model-building and analysis capabilities. Some integrations are documented but their implementation was not sampled, so those relationships are cited to the README; unsampled call details are not inferred.

Main entry points: [`src/hydrocnhs/hydrocnhs.py`](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/hydrocnhs.py) (Coupled simulator), [`src/hydrocnhs/model_builder.py`](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/model_builder.py) (Model builder), [`src/hydrocnhs/abm_script.py`](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/abm_script.py) (Agent templates), [`src/hydrocnhs/calibration/convertor.py`](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/calibration/convertor.py) (Parameter convertor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_configuration["Model configuration"]
  node_builder["Model builder<br/>[model_builder.py]"]
  node_config_utils["Configuration utilities<br/>[util.py]"]
end

subgraph group_simulation["Hydrological simulation"]
  node_simulator["Coupled simulator<br/>[hydrocnhs.py]"]
  node_abcd["ABCD runoff<br/>[abcd.py]"]
  node_gwlf["GWLF runoff<br/>[gwlf.py]"]
  node_pet["Hamon PET<br/>[pet_hamon.py]"]
  node_routing["Flow routing<br/>[routing.py]"]
  node_sediment["Sediment model<br/>[sediment.py]"]
end

subgraph group_agents["Human and agent models"]
  node_abm_runtime["Agent runtime<br/>[abm.py]"]
  node_abm_templates["Agent templates<br/>[abm_script.py]"]
  node_dam_api["Dam API<br/>[hydrocnhs.py]"]
  node_riverdiv_api["RiverDiv API<br/>[hydrocnhs.py]"]
  node_conveying_api["Conveying API<br/>[hydrocnhs.py]"]
  node_insitu_api["InSitu API<br/>[hydrocnhs.py]"]
end

subgraph group_calibration["Calibration"]
  node_convertor["Parameter convertor<br/>[convertor.py]"]
  node_ga["Genetic algorithm<br/>[ga_deap.py]"]
end

subgraph group_analysis["Results and analysis"]
  node_collector["Data collector<br/>[data_collector.py]"]
  node_indicators["Performance indicators<br/>[indicators.py]"]
  node_visual["Visualization<br/>[visual.py]"]
  node_results["Simulation results"]
end

node_user(("Modeler"))

node_user -->|"configures model"| node_builder
node_builder -->|"creates templates"| node_abm_templates
node_user -->|"runs model"| node_simulator
node_simulator -->|"runs runoff"| node_abcd
node_simulator -->|"runs runoff"| node_gwlf
node_simulator -->|"calculates PET"| node_pet
node_simulator -->|"routes flow"| node_routing
node_simulator -->|"runs sediment"| node_sediment
node_simulator -.->|"runs agents"| node_abm_runtime
node_simulator -->|"integrates actions"| node_dam_api
node_simulator -->|"integrates actions"| node_riverdiv_api
node_simulator -->|"integrates actions"| node_conveying_api
node_simulator -->|"integrates actions"| node_insitu_api
node_abm_templates -->|"uses runtime"| node_abm_runtime
node_user -->|"sets parameters"| node_convertor
node_convertor -.->|"formats parameters"| node_ga
node_ga -.->|"evaluates model"| node_simulator
node_simulator -->|"collects outputs"| node_collector
node_simulator -->|"produces results"| node_results
node_results -->|"analyzes results"| node_indicators
node_indicators -->|"supports plotting"| node_visual
node_collector -.->|"stores outputs"| node_results

click node_builder "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/model_builder.py"
click node_config_utils "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/util.py"
click node_simulator "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/hydrocnhs.py"
click node_abcd "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/rainfall_runoff_model/abcd.py"
click node_gwlf "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/rainfall_runoff_model/gwlf.py"
click node_pet "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/rainfall_runoff_model/pet_hamon.py"
click node_routing "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/routing.py"
click node_sediment "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/water_quality_model/sediment.py"
click node_abm_runtime "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/abm.py"
click node_abm_templates "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/abm_script.py"
click node_dam_api "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/hydrocnhs.py"
click node_riverdiv_api "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/hydrocnhs.py"
click node_conveying_api "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/hydrocnhs.py"
click node_insitu_api "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/hydrocnhs.py"
click node_convertor "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/calibration/convertor.py"
click node_ga "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/calibration/ga_deap.py"
click node_collector "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/data_collector.py"
click node_indicators "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/indicators.py"
click node_visual "https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/visual.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_builder,node_config_utils toneBlue
class node_simulator,node_abcd,node_gwlf,node_pet,node_routing,node_sediment toneAmber
class node_abm_runtime,node_abm_templates,node_dam_api,node_riverdiv_api,node_conveying_api,node_insitu_api toneMint
class node_convertor,node_ga toneRose
class node_collector,node_indicators,node_visual,node_results,node_user toneIndigo
```

## Components

### Model configuration

- [Model builder](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/model_builder.py): `src/hydrocnhs/model_builder.py`
- [Configuration utilities](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/util.py): `src/hydrocnhs/util.py`

### Hydrological simulation

- [Coupled simulator](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/hydrocnhs.py): `src/hydrocnhs/hydrocnhs.py`
- [ABCD runoff](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/rainfall_runoff_model/abcd.py): `src/hydrocnhs/rainfall_runoff_model/abcd.py`
- [GWLF runoff](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/rainfall_runoff_model/gwlf.py): `src/hydrocnhs/rainfall_runoff_model/gwlf.py`
- [Hamon PET](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/rainfall_runoff_model/pet_hamon.py): `src/hydrocnhs/rainfall_runoff_model/pet_hamon.py`
- [Flow routing](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/routing.py): `src/hydrocnhs/routing.py`
- [Sediment model](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/water_quality_model/sediment.py): `src/hydrocnhs/water_quality_model/sediment.py`

### Human and agent models

- [Agent runtime](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/abm.py): `src/hydrocnhs/abm.py`
- [Agent templates](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/abm_script.py): `src/hydrocnhs/abm_script.py`
- [Dam API](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/hydrocnhs.py): `src/hydrocnhs/hydrocnhs.py`
- [RiverDiv API](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/hydrocnhs.py): `src/hydrocnhs/hydrocnhs.py`
- [Conveying API](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/hydrocnhs.py): `src/hydrocnhs/hydrocnhs.py`
- [InSitu API](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/hydrocnhs.py): `src/hydrocnhs/hydrocnhs.py`

### Calibration

- [Parameter convertor](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/calibration/convertor.py): `src/hydrocnhs/calibration/convertor.py`
- [Genetic algorithm](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/calibration/ga_deap.py): `src/hydrocnhs/calibration/ga_deap.py`

### Results and analysis

- [Data collector](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/data_collector.py): `src/hydrocnhs/data_collector.py`
- [Performance indicators](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/indicators.py): `src/hydrocnhs/indicators.py`
- [Visualization](https://github.com/cylin928/hydrocnhs/blob/main/src/hydrocnhs/visual.py): `src/hydrocnhs/visual.py`
- **Simulation results**

### Other components

- **Modeler**

## Connections

- Modeler → Model builder: configures model (evidence: `README.md`)
- Model builder → Agent templates: creates templates (evidence: `src/hydrocnhs/model_builder.py`)
- Modeler → Coupled simulator: runs model (evidence: `README.md`)
- Coupled simulator → ABCD runoff: runs runoff (evidence: `src/hydrocnhs/hydrocnhs.py`)
- Coupled simulator → GWLF runoff: runs runoff (evidence: `src/hydrocnhs/hydrocnhs.py`)
- Coupled simulator → Hamon PET: calculates PET (evidence: `src/hydrocnhs/hydrocnhs.py`)
- Coupled simulator → Flow routing: routes flow (evidence: `src/hydrocnhs/hydrocnhs.py`)
- Coupled simulator → Sediment model: runs sediment (evidence: `src/hydrocnhs/hydrocnhs.py`)
- Coupled simulator → Agent runtime: runs agents
- Coupled simulator → Dam API: integrates actions (evidence: `README.md`)
- Coupled simulator → RiverDiv API: integrates actions (evidence: `README.md`)
- Coupled simulator → Conveying API: integrates actions (evidence: `README.md`)
- Coupled simulator → InSitu API: integrates actions (evidence: `README.md`)
- Agent templates → Agent runtime: uses runtime (evidence: `src/hydrocnhs/abm_script.py`)
- Modeler → Parameter convertor: sets parameters (evidence: `README.md`)
- Parameter convertor → Genetic algorithm: formats parameters
- Genetic algorithm → Coupled simulator: evaluates model
- Coupled simulator → Data collector: collects outputs (evidence: `src/hydrocnhs/hydrocnhs.py`)
- Coupled simulator → Simulation results: produces results (evidence: `README.md`)
- Simulation results → Performance indicators: analyzes results (evidence: `README.md`)
- Performance indicators → Visualization: supports plotting (evidence: `src/hydrocnhs/visual.py`)
- Data collector → Simulation results: stores outputs
