From 080d56f8eabf11f0214be738aa5c57e7a33ebddf Mon Sep 17 00:00:00 2001 From: thouska Date: Mon, 27 Feb 2023 16:01:24 +0100 Subject: [PATCH] WIP fix black style and testing issues in analyser --- src/spotpy/analyser.py | 15 +++------------ src/spotpy/examples/hymod_python/hymod.py | 8 ++++---- tests/test_analyser.py | 4 ++-- tutorials/tutorial_sceua_hymod.py | 2 -- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/spotpy/analyser.py b/src/spotpy/analyser.py index 173871d9..fa23811c 100644 --- a/src/spotpy/analyser.py +++ b/src/spotpy/analyser.py @@ -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 ") @@ -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 ") @@ -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: diff --git a/src/spotpy/examples/hymod_python/hymod.py b/src/spotpy/examples/hymod_python/hymod.py index dc4d0af1..d6dab063 100644 --- a/src/spotpy/examples/hymod_python/hymod.py +++ b/src/spotpy/examples/hymod_python/hymod.py @@ -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): @@ -69,13 +69,13 @@ 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 @@ -83,7 +83,7 @@ def linres(x_slow, inflow, Rs): 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 diff --git a/tests/test_analyser.py b/tests/test_analyser.py index fec141cd..35d72873 100644 --- a/tests/test_analyser.py +++ b/tests/test_analyser.py @@ -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) diff --git a/tutorials/tutorial_sceua_hymod.py b/tutorials/tutorial_sceua_hymod.py index 73e89386..18072f32 100644 --- a/tutorials/tutorial_sceua_hymod.py +++ b/tutorials/tutorial_sceua_hymod.py @@ -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