This project applies Particle Swarm Optimization (PSO) to calibrate parameters of the WRF-Hydro hydrological model, aiming to improve simulation accuracy and hydrologic response.
.
├── core/ # Core modules including objective function, optimization process, etc.
│ ├── NSGA2.py
│ ├── ObjFun.py
│ ├── Optimize.py
│ ├── SenAna.py
│ ├── SurrModel.py
│ └── runner/ # Simulation runner and job scheduler
├── jobs/ # Generated simulation configuration files (.yaml)
├── models/ # WRF-Hydro model files
├── params/ # Parameter configuration files
│ ├── calib_params.tbl
│ ├── run_params.yaml
│ └── sens_params.tbl
├── pic/ # Output figures (e.g., sensitivity plots, optimization results)
├── util/ # Utility scripts
│ ├── jobs.py # Job configuration tools
│ ├── sample.py # Parameter sampling
│ ├── visual.py # Visualization tools
├── run_pso.py # Main PSO calibration script
├── runhydro.sh # Shell script to launch the workflow
Activate the Anaconda environment:
source ~/anaconda3/etc/profile.d/conda.sh
conda activate psoEnsure the following dependencies are installed:
pyswarmsSALibnumpypandasxarrayloggingseabornpandasxesmf# creat precip forcing filesjoblibyaml- Custom modules:
core,util
#!/bin/bash
cp -r ../run_source ./run_source
source ~/anaconda3/etc/profile.d/conda.sh
conda activate pso
echo "The environment is activated and script is running."
nohup python3 run_pso.py > ./run_pso.log 2>&1 &
echo "Python script is running in the background. Check the log file for output."
ps aux | grep run_pso.pyThis script performs:
- Copying source templates
- Activating
condaenvironment - Launching
run_pso.pyand saving logs - Checking background process
Workflow overview:
- Define calibration parameters (e.g.,
BEXP,DKSAT,MannN, etc.) - Generate initial samples
- Run model simulations and manage jobs
- Read results and calculate objective metrics (KGE + NSE)
- Iteratively optimize via PSO
- Save optimal parameters and objective value
Results will be saved in:
pso_results.txt: readable text formatpso_results.npz: NumPy format for analysis
- Parameter configuration located in
params/ obsdirspecifies observed streamflow directory (e.g.,./Qobs)sim_infosets WRF-Hydro working directory and meta-info- Objective function used:
0.5 * KGE(-1) + 0.5 * NSE(-1)
Author: shihx2003
Email: [email protected]
- This project relies on the PBS job scheduler and a complete configuration of the WRF-Hydro model.
- Recommended to run on HPC or server environment for performance.
Parts of this README documentation were generated with the help of ChatGPT.