HBV rainfall runoff model#
HBVBergestrom92#
hapi.rrm.hbv_bergestrom92.HBVBergestrom92
#
Bases: BaseConceptualModel
HBV Bergestrom 1992 lumped conceptual hydrological model.
This class implements the HBV-96 model variant based on Bergstrom (1992), featuring two groundwater reservoirs (upper and lower zones) with three linear outflow equations for surface runoff, interflow, and baseflow.
The model inherits from
:class:~hapi.rrm.base_model.BaseConceptualModel and implements
the precipitation, snow, soil, response,
routing, and simulate methods.
Examples:
>>> from hapi.rrm.hbv_bergestrom92 import HBVBergestrom92
>>> model = HBVBergestrom92()
Source code in src/hapi/rrm/hbv_bergestrom92.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | |
__init__()
#
Initialize the HBVBergestrom92 model.
Source code in src/hapi/rrm/hbv_bergestrom92.py
56 57 58 | |
precipitation(prec, temp, tt, rfcf, sfcf)
staticmethod
#
Partition precipitation into rainfall and snowfall.
If the temperature is lower than or equal to the threshold
tt, all precipitation is considered snowfall. If the
temperature is higher than tt, all precipitation is
considered rainfall. Correction factors are applied to each
component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prec
|
float
|
Precipitation [mm]. |
required |
temp
|
float
|
Measured temperature [C]. |
required |
tt
|
float
|
Lower temperature threshold [C]. |
required |
rfcf
|
float
|
Rainfall correction factor [-]. |
required |
sfcf
|
float
|
Snowfall correction factor [-]. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
A tuple of |
Examples:
>>> from hapi.rrm.hbv_bergestrom92 import HBVBergestrom92
>>> rf, sf = HBVBergestrom92.precipitation(
... prec=10.0, temp=-2.0, tt=0.0, rfcf=1.0, sfcf=0.8
... )
>>> rf
0.0
>>> sf
8.0
When temperature exceeds the threshold, all precipitation becomes rainfall:
>>> rf, sf = HBVBergestrom92.precipitation(
... prec=10.0, temp=5.0, tt=0.0, rfcf=1.0, sfcf=0.8
... )
>>> rf
10.0
>>> sf
0.0
Source code in src/hapi/rrm/hbv_bergestrom92.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
response(lz_old, uz_int_1, perc, k, k1, k2, uzl)
staticmethod
#
Compute the runoff response from upper and lower zones.
The response routine transforms the current values of upper and lower zone storages into discharge. It also controls the recharge of the lower zone tank (baseflow).
perc defines the maximum percolation rate from the upper
to the lower groundwater box. Runoff from the groundwater
boxes is computed as the sum of two or three linear outflow
equations depending on whether the upper zone storage is
above the threshold value uzl.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lz_old
|
float
|
Previous lower zone value [mm]. |
required |
uz_int_1
|
float
|
Previous upper zone value before percolation [mm]. |
required |
perc
|
float
|
Percolation value [mm/timestep]. |
required |
k
|
float
|
Direct runoff (surface) recession coefficient [-]. |
required |
k1
|
float
|
Upper zone (interflow) recession coefficient [-]. |
required |
k2
|
float
|
Lower zone (baseflow) recession coefficient [-]. |
required |
uzl
|
float
|
Upper zone threshold value [mm]. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float, float]
|
A tuple of
|
Examples:
>>> from hapi.rrm.hbv_bergestrom92 import HBVBergestrom92
>>> q_uz, q_lz, uz_new, lz_new = HBVBergestrom92.response(
... lz_old=30.0, uz_int_1=20.0, perc=1.0, k=0.005,
... k1=0.03, k2=0.015, uzl=10.0,
... )
>>> q_uz > 0
True
>>> q_lz > 0
True
>>> uz_new >= 0
True
>>> lz_new >= 0
True
Source code in src/hapi/rrm/hbv_bergestrom92.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
routing(q, maxbas=1)
#
Apply triangular transfer function routing to discharge.
Routes the discharge signal through a triangular transfer
function defined by the maxbas parameter. The transfer
function weights are generated by :meth:tf.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
ndarray
|
Discharge array [mm/timestep]. |
required |
maxbas
|
int
|
Transfer function length in time steps. Must be >= 1. Defaults to 1. |
1
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Routed discharge array with the same
shape as |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If |
Examples:
>>> from hapi.rrm.hbv_bergestrom92 import HBVBergestrom92
>>> import numpy as np
>>> model = HBVBergestrom92()
>>> q = np.array([0.0, 1.0, 2.0, 3.0, 2.0, 1.0])
>>> q_r = model.routing(q, maxbas=1)
>>> len(q_r) == len(q)
True
Source code in src/hapi/rrm/hbv_bergestrom92.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
simulate(prec, temp, et, ll_temp, par, init_st=None, q_init=None, snow=0) -> tuple[np.ndarray, np.ndarray, np.ndarray]
#
Run the HBV Bergestrom92 model simulation.
Executes the HBV model for the number of time steps in the precipitation input. The model sequentially calls the precipitation, snow, soil, and response routines at each time step, updating state variables accordingly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prec
|
array_like
|
Average precipitation [mm/timestep],
array of length |
required |
temp
|
array_like
|
Average temperature [C], array of
length |
required |
et
|
array_like
|
Potential evapotranspiration
[mm/timestep], array of length |
required |
ll_temp
|
array_like
|
Long term average temperature [C],
array of length |
required |
par
|
array_like
|
Parameter vector. When |
required |
init_st
|
array_like
|
Initial model states
|
None
|
q_init
|
float
|
Initial discharge value. If not specified, it is computed from initial states and parameters. |
None
|
snow
|
int
|
Flag indicating whether snow processes are
active. Use |
0
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray, ndarray]
|
A tuple of |
Examples:
>>> from hapi.rrm.hbv_bergestrom92 import HBVBergestrom92
>>> import numpy as np
>>> np.random.seed(42)
>>> model = HBVBergestrom92()
>>> n = 10
>>> prec = np.random.uniform(0, 20, n)
>>> temp = np.random.uniform(15, 30, n)
>>> et = np.random.uniform(0, 5, n)
>>> ll_temp = np.full(n, 20.0)
>>> par = [1.0, 200.0, 2.0, 1.0, 0.9, 0.005, 0.03,
... 0.015, 10.0, 1.0]
>>> q_uz, q_lz, st = model.simulate(
... prec, temp, et, ll_temp, par, snow=0,
... )
>>> q_uz.shape == (n + 1,)
True
>>> st.shape == (n + 1, 5)
True
Source code in src/hapi/rrm/hbv_bergestrom92.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | |
snow(temp, rf, sf, wc_old, sp_old, tt, cfmax, cfr, cwh)
staticmethod
#
Compute snow accumulation, melt, and infiltration.
The snow pack consists of two states: water content (wc)
and snow pack (sp). The water content corresponds to the
liquid part of the water in the snow, while the snow pack
corresponds to the solid part.
If the temperature is higher than the melting point, the snow pack will melt and the solid snow will become liquid. In the opposite case, the liquid part of the snow will refreeze and turn into solid. The water that cannot be stored by the solid part of the snow pack will drain into the soil as infiltration.
Snowmelt is calculated with the degree-day method using
cfmax. Meltwater and rainfall are retained within the
snowpack until they exceed the fraction cwh of the water
equivalent of the snow. Liquid water within the snowpack
refreezes using cfr.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temp
|
float
|
Temperature [C]. |
required |
rf
|
float
|
Rainfall [mm]. |
required |
sf
|
float
|
Snowfall [mm]. |
required |
wc_old
|
float
|
Water content in previous state [mm]. |
required |
sp_old
|
float
|
Snow pack in previous state [mm]. |
required |
tt
|
float
|
Temperature threshold for melting [C]. |
required |
cfmax
|
float
|
Day degree factor [mm/C/timestep]. |
required |
cfr
|
float
|
Refreezing factor [-]. |
required |
cwh
|
float
|
Capacity for water holding in snow pack as a fraction [-]. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float]
|
A tuple of
|
Examples:
>>> from hapi.rrm.hbv_bergestrom92 import HBVBergestrom92
>>> inf, wc_new, sp_new = HBVBergestrom92.snow(
... temp=5.0, rf=3.0, sf=0.0, wc_old=2.0,
... sp_old=10.0, tt=0.0, cfmax=3.0, cfr=0.05,
... cwh=0.1,
... )
>>> sp_new
0.0
>>> inf > 0
True
Source code in src/hapi/rrm/hbv_bergestrom92.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
soil(temp, inf, ep, sm_old, uz_old, tm, fc, beta, e_corr, lp)
staticmethod
#
Compute soil moisture balance and upper zone recharge.
The model checks the amount of water that can infiltrate the soil from liquid precipitation and snow pack melting. A part of the water is stored as soil moisture, while the rest becomes runoff routed to the upper zone tank.
Actual evaporation from the soil box equals the potential
evaporation if SM/FC is above LP, while a linear
reduction is used when SM/FC is below LP.
Groundwater recharge is added to the upper groundwater box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temp
|
float
|
Temperature [C]. |
required |
inf
|
float
|
Actual infiltration [mm]. |
required |
ep
|
float
|
Potential evapotranspiration [mm]. |
required |
sm_old
|
float
|
Previous soil moisture value [mm]. |
required |
uz_old
|
float
|
Previous upper zone value [mm]. |
required |
tm
|
float
|
Average long term temperature [C]. |
required |
fc
|
float
|
Field capacity [mm]. |
required |
beta
|
float
|
Shape coefficient for effective precipitation separation [-]. |
required |
e_corr
|
float
|
Evapotranspiration correction factor [-]. |
required |
lp
|
float
|
Wilting point as a fraction of field capacity [-]. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
A tuple of
|
Examples:
>>> from hapi.rrm.hbv_bergestrom92 import HBVBergestrom92
>>> sm_new, uz_int_1 = HBVBergestrom92.soil(
... temp=20.0, inf=5.0, ep=3.0, sm_old=50.0,
... uz_old=10.0, tm=18.0, fc=200.0, beta=2.0,
... e_corr=1.0, lp=0.9,
... )
>>> sm_new > 0
True
>>> uz_int_1 > uz_old
True
Source code in src/hapi/rrm/hbv_bergestrom92.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
tf(maxbas)
staticmethod
#
Generate transfer function weights for triangular routing.
Computes a set of normalized weights based on a triangular
transfer function. The weights grow linearly for the first
half of the maxbas interval and recede linearly for the
second half.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
maxbas
|
int
|
Number of time steps for the triangular transfer function. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Normalized weights for the transfer function, summing to 1.0. |
Examples:
>>> from hapi.rrm.hbv_bergestrom92 import HBVBergestrom92
>>> import numpy as np
>>> w = HBVBergestrom92.tf(3)
>>> np.isclose(w.sum(), 1.0)
True
>>> len(w)
3
Source code in src/hapi/rrm/hbv_bergestrom92.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | |