Skip to content

Commit

Permalink
WIP fix black style and testing issues in analyser
Browse files Browse the repository at this point in the history
  • Loading branch information
thouska committed Feb 27, 2023
1 parent 7fe764e commit 080d56f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
15 changes: 3 additions & 12 deletions src/spotpy/analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,7 @@ def get_maxlikeindex(results, like_index=1, verbose=True):
value and value of the maximum objectivefunction of your result array
:rtype: int and float
"""
try:
likes = results["like"]
except ValueError:
likes = results["like" + str(like_index)]
likes = results["like" + str(like_index)]
maximum = np.nanmax(likes)
value = str(round(maximum, 4))
text = str("Run number ")
Expand All @@ -202,10 +199,7 @@ def get_minlikeindex(results, like_index=1, verbose=True):
value and value of the minimum objectivefunction of your result array
:rtype: int and float
"""
try:
likes = results["like"]
except ValueError:
likes = results["like" + str(like_index)]
likes = results["like" + str(like_index)]
minimum = np.nanmin(likes)
value = str(round(minimum, 4))
text = str("Run number ")
Expand Down Expand Up @@ -401,10 +395,7 @@ def get_best_parameterset(results, like_index=1, maximize=True):
:return: Best parameter set
:rtype: array
"""
try:
likes = results["like"]
except ValueError:
likes = results["like" + str(like_index)]
likes = results["like" + str(like_index)]
if maximize:
best = np.nanmax(likes)
else:
Expand Down
8 changes: 4 additions & 4 deletions src/spotpy/examples/hymod_python/hymod.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
PLoS ONE, 10(12), e0145180, doi:10.1371/journal.pone.0145180, 2015.
"""

from numba import jit
#from numba import jit


def hymod(Precip, PET, cmax, bexp, alpha, Rs, Rq):
Expand Down Expand Up @@ -69,21 +69,21 @@ def hymod(Precip, PET, cmax, bexp, alpha, Rs, Rq):
return output


@jit
#@jit
def power(X, Y):
X = abs(X) # Needed to capture invalid overflow with netgative values
return X**Y


@jit
#@jit
def linres(x_slow, inflow, Rs):
# Linear reservoir
x_slow = (1 - Rs) * x_slow + (1 - Rs) * inflow
outflow = (Rs / (1 - Rs)) * x_slow
return x_slow, outflow


@jit
#@jit
def excess(x_loss, cmax, bexp, Pval, PETval):
# this function calculates excess precipitation and evaporation
xn_prev = x_loss
Expand Down
4 changes: 2 additions & 2 deletions tests/test_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def test_calc_like(self):

def test_get_best_parameterset(self):
get_best_parameterset_true = spotpy.analyser.get_best_parameterset(
self.results, True
self.results, maximize=True
)
get_best_parameterset_false = spotpy.analyser.get_best_parameterset(
self.results, False
self.results, maximize=False
)
self.assertEqual(len(get_best_parameterset_true[0]), 3)
self.assertEqual(type(get_best_parameterset_true[0]), np.void)
Expand Down
2 changes: 0 additions & 2 deletions tutorials/tutorial_sceua_hymod.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
"""

import matplotlib.pyplot as plt
import numpy as np

import spotpy
from spotpy.examples.spot_setup_hymod_python import spot_setup

if __name__ == "__main__":
parallel = "seq" # Runs everthing in sequential mode
np.random.seed(2000) # Makes the results reproduceable

# Initialize the Hymod example
# In this case, we tell the setup which algorithm we want to use, so
Expand Down

0 comments on commit 080d56f

Please sign in to comment.