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

thouska / spotpy / 22064487714

16 Feb 2026 01:24PM UTC coverage: 66.773% (-1.0%) from 67.817%
22064487714

push

github

thouska
Reomve running isort in github action

3768 of 5643 relevant lines covered (66.77%)

2.0 hits per line

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

97.73
/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
import os
3✔
11

12
from spotpy.examples.hymod_python.hymod import hymod
3✔
13
from spotpy.objectivefunctions import rmse
3✔
14
from spotpy.parameter import Uniform
3✔
15
import datetime as dt
3✔
16

17

18
class spot_setup(object):
3✔
19
    cmax = Uniform(low=1.0, high=500, optguess=412.33)
3✔
20
    bexp = Uniform(low=0.1, high=2.0, optguess=0.1725)
3✔
21
    alpha = Uniform(low=0.1, high=0.99, optguess=0.8127)
3✔
22
    Ks = Uniform(low=0.001, high=0.10, optguess=0.0404)
3✔
23
    Kq = Uniform(low=0.1, high=0.99, optguess=0.5592)
3✔
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):
3✔
28
        # Just a way to keep this example flexible and applicable to various examples
29
        self.obj_func = obj_func
3✔
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)
3✔
32
        # Load Observation data from file
33
        self.PET, self.Precip = [], []
3✔
34
        self.date, self.trueObs = [], []
3✔
35
        # Find Path to Hymod on users system
36
        self.owd = os.path.dirname(os.path.realpath(__file__))
3✔
37
        self.hymod_path = self.owd + os.sep + "hymod_python"
3✔
38
        climatefile = open(self.hymod_path + os.sep + "hymod_input.csv", "r")
3✔
39
        headerline = climatefile.readline()[:-1]
3✔
40

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

55
    def simulation(self, x):
3✔
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])
3✔
58
        sim = []
3✔
59
        for val in data:
3✔
60
            sim.append(val * self.Factor)
3✔
61
        # The first year of simulation data is ignored (warm-up)
62
        return sim[366:]
3✔
63

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

67
    def objectivefunction(self, simulation, evaluation, params=None):
3✔
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:
3✔
71
            # This is used if not overwritten by user
72
            like = rmse(evaluation, simulation)
3✔
73
        else:
74
            # Way to ensure flexible spot setup class
75
            like = self.obj_func(evaluation, simulation)
3✔
76
        return like
3✔
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