• 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

97.67
/src/spotpy/examples/spot_setup_hymod_python.py
1
"""
2
Copyright 2015 by Tobias Houska
3
This file is part of Statistical Parameter Estimation Tool (SPOTPY).
4

5
:author: Tobias Houska
6

7
This example implements the python version of hymod into SPOTPY.
8
"""
9

10

11
import os
6✔
12

13
from spotpy.examples.hymod_python.hymod import hymod
6✔
14
from spotpy.objectivefunctions import rmse
6✔
15
from spotpy.parameter import Uniform
6✔
16

17

18
class spot_setup(object):
6✔
19
    cmax = Uniform(low=1.0, high=500, optguess=412.33)
6✔
20
    bexp = Uniform(low=0.1, high=2.0, optguess=0.1725)
6✔
21
    alpha = Uniform(low=0.1, high=0.99, optguess=0.8127)
6✔
22
    Ks = Uniform(low=0.001, high=0.10, optguess=0.0404)
6✔
23
    Kq = Uniform(low=0.1, high=0.99, optguess=0.5592)
6✔
24
    # fake1 =spotpy.parameter.Uniform(low=0.1 , high=10, optguess=0.5592)
25
    # fake2 =spotpy.parameter.Uniform(low=0.1 , high=10, optguess=0.5592)
26

27
    def __init__(self, obj_func=None):
6✔
28
        # Just a way to keep this example flexible and applicable to various examples
29
        self.obj_func = obj_func
4✔
30
        # Transform [mm/day] into [l s-1], where 1.783 is the catchment area
31
        self.Factor = 1.783 * 1000 * 1000 / (60 * 60 * 24)
4✔
32
        # Load Observation data from file
33
        self.PET, self.Precip = [], []
4✔
34
        self.date, self.trueObs = [], []
4✔
35
        # Find Path to Hymod on users system
36
        self.owd = os.path.dirname(os.path.realpath(__file__))
4✔
37
        self.hymod_path = self.owd + os.sep + "hymod_python"
4✔
38
        climatefile = open(self.hymod_path + os.sep + "hymod_input.csv", "r")
4✔
39
        headerline = climatefile.readline()[:-1]
4✔
40

41
        # Read model forcing in working storage (this is done only ones)
42
        if ";" in headerline:
4✔
43
            self.delimiter = ";"
4✔
44
        else:
45
            self.delimiter = ","
×
46
        self.header = headerline.split(self.delimiter)
4✔
47
        for line in climatefile:
4✔
48
            values = line.strip().split(self.delimiter)
4✔
49
            self.date.append(str(values[0]))
4✔
50
            self.Precip.append(float(values[1]))
4✔
51
            self.PET.append(float(values[2]))
4✔
52
            self.trueObs.append(float(values[3]))
4✔
53
        climatefile.close()
4✔
54

55
    def simulation(self, x):
6✔
56
        # Here the model is actualy startet with one paramter combination
57
        data = hymod(self.Precip, self.PET, x[0], x[1], x[2], x[3], x[4])
4✔
58
        sim = []
4✔
59
        for val in data:
4✔
60
            sim.append(val * self.Factor)
4✔
61
        # The first year of simulation data is ignored (warm-up)
62
        return sim[366:]
4✔
63

64
    def evaluation(self):
6✔
65
        return self.trueObs[366:]
4✔
66

67
    def objectivefunction(self, simulation, evaluation, params=None):
6✔
68
        # SPOTPY expects to get one or multiple values back,
69
        # that define the performance of the model run
70
        if not self.obj_func:
4✔
71
            # This is used if not overwritten by user
72
            like = rmse(evaluation, simulation)
4✔
73
        else:
74
            # Way to ensure flexible spot setup class
75
            like = self.obj_func(evaluation, simulation)
4✔
76
        return like
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