Note
Go to the end to download the full example code.
HBV Model Example
import time
import numpy as np
import pandas as pd
from SeqMetrics import RegressionMetrics
import rain2flow
from rain2flow import hbv
print(time.asctime(), "\n")
print("np: ", np.__version__)
print("pd: ", pd.__version__)
print("rain2flow: ", rain2flow.__version__)
Mon Feb 16 12:16:49 2026
np: 2.0.1
pd: 3.0.0
rain2flow: 0.1.0
Read the data from disk which contains pcp, temp and pet columns.
data = pd.read_csv('data.csv',
comment='#', parse_dates=['date'], index_col='date')
specify the model parameters.
parameters = {
"BETA": 2.254272145204868,
"CFMAX": 2.634558463081481,
"CFR": 0.05316989970760903,
"CWH": 0.06320640559590592,
"FC": 938.4151865045613,
"K0": 0.5533421892716448,
"K1": 0.25566454560982704,
"K2": 0.18448187501298327,
"LP": 0.9976204042760504,
"MAXBAS": 4.399887139522522,
"PCORR": 1.991169069794055,
"PERC": 5.256982141549575,
"SFCF": 1.9656441421578075,
"TT": 1.0041306252448585,
"UZL": 36.983252412038695
}
# run the model
sim = hbv(
data['pcp'].values,
data['temp'].values,
data['pet'].values,
parameters=parameters)
evaluate the model performance using KGE, NSE and PBIAS metrics.
kge : 0.8411
nse : 0.7452
pbias : 7.4699
Total running time of the script: (0 minutes 0.762 seconds)