Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9f965f6

Browse files
committed
Merge branch 'develop' of https://github.com/pypest/pyemu into develop
2 parents 9224273 + 11c6de4 commit 9f965f6

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

autotest/metrics_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ def res_and_ens_test():
6565
assert fcns['mse'](m,o) == 0.0
6666
assert fcns['mae'](m,o) == 0.0
6767
assert fcns['pbias'](m,o) == 0.0
68+
assert fcns['bias'](m,o) == 0.0
69+
assert fcns['relative_bias'](m,o) == 0.0
70+
assert fcns['standard_error'](m,o) == 0.0
71+
assert fcns['volumetric_efficiency'](m,o) == 1.0
6872
assert fcns['kge'](m,o) == 1.0
6973

7074
if __name__ == "__main__":

pyemu/utils/metrics.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,42 @@ def _MAE(mod, obs):
4848
"""
4949
return np.mean(np.abs(obs - mod))
5050

51+
def _STANDARD_ERROR(mod, obs):
52+
"""
53+
Calculate Standard Error as defined in TSPROC manual
54+
https://pubs.usgs.gov/tm/tm7c7/pdf/TM7_C7_112712.pdf
55+
56+
Args:
57+
obs: numpy array of observed values
58+
mod: numpy array of modeled values
59+
"""
60+
return np.sqrt(np.sum((mod-obs)**2)/(len(obs)-1))
61+
62+
def _RELATIVE_STANDARD_ERROR(mod, obs):
63+
"""
64+
Calculate Relative Standard Error as defined in TSPROC manual
65+
https://pubs.usgs.gov/tm/tm7c7/pdf/TM7_C7_112712.pdf
66+
67+
Args:
68+
obs: numpy array of observed values
69+
mod: numpy array of modeled values
70+
"""
71+
return _STANDARD_ERROR(mod, obs) / np.sqrt(np.sum((obs-np.nanmean(obs))**2)/(len(obs)-1))
72+
73+
74+
75+
76+
77+
def _VOLUMETRIC_EFFICIENCY(mod, obs):
78+
"""
79+
Calculate Volumetric Efficiency as defined in TSPROC manual
80+
https://pubs.usgs.gov/tm/tm7c7/pdf/TM7_C7_112712.pdf
81+
82+
Args:
83+
obs: numpy array of observed values
84+
mod: numpy array of modeled values
85+
"""
86+
return 1 - ((np.sum(np.abs(mod-obs)))/(np.sum(obs)))
5187

5288
def _MSE(mod, obs):
5389
"""
@@ -147,6 +183,27 @@ def _PBIAS(mod, obs):
147183
"""
148184
return 100 * ((np.sum(mod - obs)) / (np.sum(obs)))
149185

186+
def _BIAS(mod, obs):
187+
"""
188+
Calculate Bias as defined in TSPROC manual
189+
https://pubs.usgs.gov/tm/tm7c7/pdf/TM7_C7_112712.pdf
190+
191+
Args:
192+
obs: numpy array of observed values
193+
mod: numpy array of modeled values
194+
"""
195+
return ((np.sum(mod - obs)) / (np.sum(obs)))/len(obs)
196+
197+
def _RELATIVE_BIAS(mod, obs):
198+
"""
199+
Calculate Relative Bias as defined in TSPROC manual
200+
https://pubs.usgs.gov/tm/tm7c7/pdf/TM7_C7_112712.pdf
201+
202+
Args:
203+
obs: numpy array of observed values
204+
mod: numpy array of modeled values
205+
"""
206+
return _BIAS(mod, obs) / np.nanmean(obs)
150207

151208
def _KGE(mod, obs):
152209
"""
@@ -174,6 +231,8 @@ def _KGE(mod, obs):
174231
# available metrics to calculate
175232
ALLMETRICS = {
176233
"pbias": _PBIAS,
234+
"bias": _BIAS,
235+
"relative_bias": _RELATIVE_BIAS,
177236
"rmse": _RMSE,
178237
"mse": _MSE,
179238
"nse": _NSE,
@@ -184,6 +243,10 @@ def _KGE(mod, obs):
184243
"nrmse_mean": _NRMSE_MEAN,
185244
"nrmse_iq": _NRMSE_IQ,
186245
"nrmse_maxmin": _NRMSE_MAXMIN,
246+
"standard_error": _STANDARD_ERROR,
247+
"volumetric_efficiency": _VOLUMETRIC_EFFICIENCY,
248+
"relative_standard_error": _RELATIVE_STANDARD_ERROR
249+
187250
}
188251

189252

0 commit comments

Comments
 (0)