Lumped Model Calibration
To calibrate the HBV lumped model inside Hapi you need to follow the same steps of running the lumped model with few extra steps to define the requirement of the calibration algorithm.
1import pandas as pd
2import datetime as dt
3import Hapi.rrm.hbv_bergestrom92 as HBVLumped
4from Hapi.rrm.calibration import Calibration
5from Hapi.rrm.routing import Routing
6from Hapi.run import Run
7import Hapi.statistics.performancecriteria as PC
8
9Parameterpath = Comp + "/data/lumped/Coello_Lumped2021-03-08_muskingum.txt"
10MeteoDataPath = Comp + "/data/lumped/meteo_data-MSWEP.csv"
11Path = Comp + "/data/lumped/"
12
13start = "2009-01-01"
14end = "2011-12-31"
15name = "Coello"
16
17Coello = Calibration(name, start, end)
18Coello.readLumpedInputs(MeteoDataPath)
19
20
21# catchment area
22AreaCoeff = 1530
23# temporal resolution
24# [Snow pack, Soil moisture, Upper zone, Lower Zone, Water content]
25InitialCond = [0,10,10,10,0]
26# no snow subroutine
27Snow = 0
28Coello.readLumpedModel(HBVLumped, AreaCoeff, InitialCond)
29
30# Calibration boundaries
31UB = pd.read_csv(Path + "/lumped/UB-3.txt", index_col = 0, header = None)
32parnames = UB.index
33UB = UB[1].tolist()
34LB = pd.read_csv(Path + "/lumped/LB-3.txt", index_col = 0, header = None)
35LB = LB[1].tolist()
36
37Maxbas = True
38Coello.readParametersBounds(UB, LB, Snow, Maxbas=Maxbas)
39
40parameters = []
41# Routing
42Route = 1
43RoutingFn = Routing.TriangularRouting1
44
45Basic_inputs = dict(Route=Route, RoutingFn=RoutingFn, InitialValues = parameters)
46
47### Objective function
48# outlet discharge
49Coello.readDischargeGauges(Path+"Qout_c.csv", fmt="%Y-%m-%d")
50
51OF_args=[]
52OF=PC.RMSE
53
54Coello.readObjectiveFn(PC.RMSE, OF_args)
after defining all the components of the lumped model, we have to define the calibration arguments
1ApiObjArgs = dict(hms=100, hmcr=0.95, par=0.65, dbw=2000, fileout=1, xinit =0,
2 filename=Path + "/Lumped_History"+str(dt.datetime.now())[0:10]+".txt")
3
4for i in range(len(ApiObjArgs)):
5 print(list(ApiObjArgs.keys())[i], str(ApiObjArgs[list(ApiObjArgs.keys())[i]]))
6
7# pll_type = 'POA'
8pll_type = None
9
10ApiSolveArgs = dict(store_sol=True, display_opts=True, store_hst=True, hot_start=False)
11
12OptimizationArgs=[ApiObjArgs, pll_type, ApiSolveArgs]
Run Calibration
1cal_parameters = Coello.lumpedCalibration(Basic_inputs, OptimizationArgs, printError=None)
2
3print("Objective Function = " + str(round(cal_parameters[0],2)))
4print("Parameters are " + str(cal_parameters[1]))
5print("Time = " + str(round(cal_parameters[2]['time']/60,2)) + " min")