• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thouska / spotpy / 7709518362

30 Jan 2024 10:11AM UTC coverage: 77.332% (-0.2%) from 77.518%
7709518362

push

github

thouska
Merge branch 'master' of https://github.com/thouska/spotpy

4162 of 5382 relevant lines covered (77.33%)

3.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/spotpy/examples/hymod_python/hymod.py
1
# -*- coding: utf-8 -*-
2
"""
6✔
3
Copyright (c) 2015 by Tobias Houska
4

5
This file is part of Statistical Parameter Estimation Tool (SPOTPY).
6

7
:author: Tobias Houska and Benjamin Manns
8

9
:paper: Houska, T., Kraft, P., Chamorro-Chavez, A. and Breuer, L.: 
10
SPOTting Model Parameters Using a Ready-Made Python Package, 
11
PLoS ONE, 10(12), e0145180, doi:10.1371/journal.pone.0145180, 2015.
12
"""
13

14
# from numba import jit
15

16

17
def hymod(Precip, PET, cmax, bexp, alpha, Rs, Rq):
6✔
18
    """
19
    See https://www.proc-iahs.net/368/180/2015/piahs-368-180-2015.pdf for a scientific paper:
20

21
    Quan, Z.; Teng, J.; Sun, W.; Cheng, T. & Zhang, J. (2015): Evaluation of the HYMOD model
22
    for rainfall–runoff simulation using the GLUE method. Remote Sensing and GIS for Hydrology
23
    and Water Resources, 180 - 185, IAHS Publ. 368. DOI: 10.5194/piahs-368-180-2015.
24

25
    :param cmax:
26
    :param bexp:
27
    :param alpha:
28
    :param Rs:
29
    :param Rq:
30
    :return: Dataset of water in hymod (has to be calculated in litres)
31
    :rtype: list
32
    """
33

34
    # HYMOD PROGRAM IS SIMPLE RAINFALL RUNOFF MODEL
35
    x_loss = 0.0
4✔
36
    # Initialize slow tank state
37
    x_slow = 2.3503 / (Rs * 22.5)
4✔
38
    x_slow = 0  # --> works ok if calibration data starts with low discharge
4✔
39
    # Initialize state(s) of quick tank(s)
40
    x_quick = [0, 0, 0]
4✔
41
    t = 0
4✔
42
    output = []
4✔
43
    # START PROGRAMMING LOOP WITH DETERMINING RAINFALL - RUNOFF AMOUNTS
44

45
    while t <= len(Precip) - 1:
4✔
46
        Pval = Precip[t]
4✔
47
        PETval = PET[t]
4✔
48
        # Compute excess precipitation and evaporation
49
        ER1, ER2, x_loss = excess(x_loss, cmax, bexp, Pval, PETval)
4✔
50
        # Calculate total effective rainfall
51
        ET = ER1 + ER2
4✔
52
        #  Now partition ER between quick and slow flow reservoirs
53
        UQ = alpha * ET
4✔
54
        US = (1 - alpha) * ET
4✔
55
        # Route slow flow component with single linear reservoir
56
        x_slow, QS = linres(x_slow, US, Rs)
4✔
57
        # Route quick flow component with linear reservoirs
58
        inflow = UQ
4✔
59

60
        for i in range(3):
4✔
61
            # Linear reservoir
62
            x_quick[i], outflow = linres(x_quick[i], inflow, Rq)
4✔
63
            inflow = outflow
4✔
64

65
        # Compute total flow for timestep
66
        output.append(QS + outflow)
4✔
67
        t = t + 1
4✔
68

69
    return output
4✔
70

71

72
# @jit
73
def power(X, Y):
6✔
74
    X = abs(X)  # Needed to capture invalid overflow with netgative values
4✔
75
    return X**Y
4✔
76

77

78
# @jit
79
def linres(x_slow, inflow, Rs):
6✔
80
    # Linear reservoir
81
    x_slow = (1 - Rs) * x_slow + (1 - Rs) * inflow
4✔
82
    outflow = (Rs / (1 - Rs)) * x_slow
4✔
83
    return x_slow, outflow
4✔
84

85

86
# @jit
87
def excess(x_loss, cmax, bexp, Pval, PETval):
6✔
88
    # this function calculates excess precipitation and evaporation
89
    xn_prev = x_loss
4✔
90
    ct_prev = cmax * (
4✔
91
        1 - power((1 - ((bexp + 1) * (xn_prev) / cmax)), (1 / (bexp + 1)))
92
    )
93
    # Calculate Effective rainfall 1
94
    ER1 = max((Pval - cmax + ct_prev), 0.0)
4✔
95
    Pval = Pval - ER1
4✔
96
    dummy = min(((ct_prev + Pval) / cmax), 1)
4✔
97
    xn = (cmax / (bexp + 1)) * (1 - power((1 - dummy), (bexp + 1)))
4✔
98

99
    # Calculate Effective rainfall 2
100
    ER2 = max(Pval - (xn - xn_prev), 0)
4✔
101

102
    # Alternative approach
103
    evap = (
4✔
104
        1 - (((cmax / (bexp + 1)) - xn) / (cmax / (bexp + 1)))
105
    ) * PETval  # actual ET is linearly related to the soil moisture state
106
    xn = max(xn - evap, 0)  # update state
4✔
107

108
    return ER1, ER2, xn
4✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc