70
70
71
71
import sys
72
72
import warnings
73
- from typing import Callable , Iterable , List , Optional , Set , Tuple , Union
73
+ from typing import Any , Callable , Iterable , List , Optional , Set , Tuple , Union
74
74
75
75
import numpy as np
76
76
import pandas as pd
79
79
from .settings import options
80
80
81
81
82
- def bias (obs , model ) -> float :
82
+ def bias (obs , model ) -> Any :
83
83
r"""Bias (mean error)
84
84
85
85
$$
@@ -93,7 +93,7 @@ def bias(obs, model) -> float:
93
93
return np .mean (model - obs )
94
94
95
95
96
- def max_error (obs , model ) -> float :
96
+ def max_error (obs , model ) -> Any :
97
97
r"""Max (absolute) error
98
98
99
99
$$
@@ -109,15 +109,15 @@ def max_error(obs, model) -> float:
109
109
110
110
def mae (
111
111
obs : np .ndarray , model : np .ndarray , weights : Optional [np .ndarray ] = None
112
- ) -> float :
112
+ ) -> Any :
113
113
"""alias for mean_absolute_error"""
114
114
assert obs .size == model .size
115
115
return mean_absolute_error (obs , model , weights )
116
116
117
117
118
118
def mean_absolute_error (
119
119
obs : np .ndarray , model : np .ndarray , weights : Optional [np .ndarray ] = None
120
- ) -> float :
120
+ ) -> Any :
121
121
r"""Mean Absolute Error (MAE)
122
122
123
123
$$
@@ -133,12 +133,12 @@ def mean_absolute_error(
133
133
return error
134
134
135
135
136
- def mape (obs : np .ndarray , model : np .ndarray ) -> float :
136
+ def mape (obs : np .ndarray , model : np .ndarray ) -> Any :
137
137
"""alias for mean_absolute_percentage_error"""
138
138
return mean_absolute_percentage_error (obs , model )
139
139
140
140
141
- def mean_absolute_percentage_error (obs : np .ndarray , model : np .ndarray ) -> float :
141
+ def mean_absolute_percentage_error (obs : np .ndarray , model : np .ndarray ) -> Any :
142
142
r"""Mean Absolute Percentage Error (MAPE)
143
143
144
144
$$
@@ -161,7 +161,7 @@ def mean_absolute_percentage_error(obs: np.ndarray, model: np.ndarray) -> float:
161
161
162
162
def urmse (
163
163
obs : np .ndarray , model : np .ndarray , weights : Optional [np .ndarray ] = None
164
- ) -> float :
164
+ ) -> Any :
165
165
r"""Unbiased Root Mean Squared Error (uRMSE)
166
166
167
167
$$
@@ -190,7 +190,7 @@ def rmse(
190
190
model : np .ndarray ,
191
191
weights : Optional [np .ndarray ] = None ,
192
192
unbiased : bool = False ,
193
- ) -> float :
193
+ ) -> Any :
194
194
"""alias for root_mean_squared_error"""
195
195
return root_mean_squared_error (obs , model , weights , unbiased )
196
196
@@ -200,7 +200,7 @@ def root_mean_squared_error(
200
200
model : np .ndarray ,
201
201
weights : Optional [np .ndarray ] = None ,
202
202
unbiased : bool = False ,
203
- ) -> float :
203
+ ) -> Any :
204
204
r"""Root Mean Squared Error (RMSE)
205
205
206
206
$$
@@ -234,12 +234,12 @@ def root_mean_squared_error(
234
234
return error
235
235
236
236
237
- def nse (obs : np .ndarray , model : np .ndarray ) -> float :
237
+ def nse (obs : np .ndarray , model : np .ndarray ) -> Any :
238
238
"""alias for nash_sutcliffe_efficiency"""
239
239
return nash_sutcliffe_efficiency (obs , model )
240
240
241
241
242
- def nash_sutcliffe_efficiency (obs : np .ndarray , model : np .ndarray ) -> float :
242
+ def nash_sutcliffe_efficiency (obs : np .ndarray , model : np .ndarray ) -> Any :
243
243
r"""Nash-Sutcliffe Efficiency (NSE)
244
244
245
245
$$
@@ -261,12 +261,12 @@ def nash_sutcliffe_efficiency(obs: np.ndarray, model: np.ndarray) -> float:
261
261
262
262
if len (obs ) == 0 :
263
263
return np .nan
264
- error = 1 - (np .sum ((obs - model ) ** 2 ) / np .sum ((obs - np .mean (obs )) ** 2 ))
264
+ error = 1 - (np .sum ((obs - model ) ** 2 ) / np .sum ((obs - np .mean (obs )) ** 2 )) # type: ignore
265
265
266
266
return error
267
267
268
268
269
- def kling_gupta_efficiency (obs : np .ndarray , model : np .ndarray ) -> float :
269
+ def kling_gupta_efficiency (obs : np .ndarray , model : np .ndarray ) -> Any :
270
270
r"""
271
271
Kling-Gupta Efficiency (KGE)
272
272
@@ -306,12 +306,12 @@ def kling_gupta_efficiency(obs: np.ndarray, model: np.ndarray) -> float:
306
306
return res
307
307
308
308
309
- def kge (obs : np .ndarray , model : np .ndarray ) -> float :
309
+ def kge (obs : np .ndarray , model : np .ndarray ) -> Any :
310
310
"""alias for kling_gupta_efficiency"""
311
311
return kling_gupta_efficiency (obs , model )
312
312
313
313
314
- def r2 (obs : np .ndarray , model : np .ndarray ) -> float :
314
+ def r2 (obs : np .ndarray , model : np .ndarray ) -> Any :
315
315
r"""Coefficient of determination (R2)
316
316
317
317
Pronounced 'R-squared'; the proportion of the variation in the dependent variable that is predictable from the independent variable(s), i.e. the proportion of explained variance.
@@ -339,18 +339,18 @@ def r2(obs: np.ndarray, model: np.ndarray) -> float:
339
339
return np .nan
340
340
341
341
residual = model - obs
342
- SSr = np .sum (residual ** 2 )
343
- SSt = np .sum ((obs - obs .mean ()) ** 2 )
342
+ SSr : Any = np .sum (residual ** 2 )
343
+ SSt : Any = np .sum ((obs - obs .mean ()) ** 2 )
344
344
345
345
return 1 - SSr / SSt
346
346
347
347
348
- def mef (obs : np .ndarray , model : np .ndarray ) -> float :
348
+ def mef (obs : np .ndarray , model : np .ndarray ) -> Any :
349
349
"""alias for model_efficiency_factor"""
350
350
return model_efficiency_factor (obs , model )
351
351
352
352
353
- def model_efficiency_factor (obs : np .ndarray , model : np .ndarray ) -> float :
353
+ def model_efficiency_factor (obs : np .ndarray , model : np .ndarray ) -> Any :
354
354
r"""Model Efficiency Factor (MEF)
355
355
356
356
Scale independent RMSE, standardized by Stdev of observations
@@ -373,12 +373,12 @@ def model_efficiency_factor(obs: np.ndarray, model: np.ndarray) -> float:
373
373
return rmse (obs , model ) / obs .std ()
374
374
375
375
376
- def cc (obs : np .ndarray , model : np .ndarray , weights = None ) -> float :
376
+ def cc (obs : np .ndarray , model : np .ndarray , weights = None ) -> Any :
377
377
"""alias for corrcoef"""
378
378
return corrcoef (obs , model , weights )
379
379
380
380
381
- def corrcoef (obs , model , weights = None ) -> float :
381
+ def corrcoef (obs , model , weights = None ) -> Any :
382
382
r"""Pearson’s Correlation coefficient (CC)
383
383
384
384
$$
@@ -405,12 +405,12 @@ def corrcoef(obs, model, weights=None) -> float:
405
405
return C [0 , 1 ] / np .sqrt (C [0 , 0 ] * C [1 , 1 ])
406
406
407
407
408
- def rho (obs : np .ndarray , model : np .ndarray ) -> float :
408
+ def rho (obs : np .ndarray , model : np .ndarray ) -> Any :
409
409
"""alias for spearmanr"""
410
410
return spearmanr (obs , model )
411
411
412
412
413
- def spearmanr (obs : np .ndarray , model : np .ndarray ) -> float :
413
+ def spearmanr (obs : np .ndarray , model : np .ndarray ) -> Any :
414
414
r"""Spearman rank correlation coefficient
415
415
416
416
The rank correlation coefficient is similar to the Pearson correlation coefficient but
@@ -442,12 +442,12 @@ def spearmanr(obs: np.ndarray, model: np.ndarray) -> float:
442
442
return scipy .stats .spearmanr (obs , model )[0 ]
443
443
444
444
445
- def si (obs : np .ndarray , model : np .ndarray ) -> float :
445
+ def si (obs : np .ndarray , model : np .ndarray ) -> Any :
446
446
"""alias for scatter_index"""
447
447
return scatter_index (obs , model )
448
448
449
449
450
- def scatter_index (obs : np .ndarray , model : np .ndarray ) -> float :
450
+ def scatter_index (obs : np .ndarray , model : np .ndarray ) -> Any :
451
451
r"""Scatter index (SI)
452
452
453
453
Which is the same as the unbiased-RMSE normalized by the absolute mean of the observations.
@@ -468,7 +468,7 @@ def scatter_index(obs: np.ndarray, model: np.ndarray) -> float:
468
468
return np .sqrt (np .mean (residual ** 2 )) / np .mean (np .abs (obs ))
469
469
470
470
471
- def scatter_index2 (obs : np .ndarray , model : np .ndarray ) -> float :
471
+ def scatter_index2 (obs : np .ndarray , model : np .ndarray ) -> Any :
472
472
r"""Alternative formulation of the scatter index (SI)
473
473
474
474
$$
@@ -483,17 +483,17 @@ def scatter_index2(obs: np.ndarray, model: np.ndarray) -> float:
483
483
return np .nan
484
484
485
485
return np .sqrt (
486
- np .sum (((model - model .mean ()) - (obs - obs .mean ())) ** 2 ) / np .sum (obs ** 2 )
486
+ np .sum (((model - model .mean ()) - (obs - obs .mean ())) ** 2 ) / np .sum (obs ** 2 ) # type: ignore
487
487
)
488
488
489
489
490
- def ev (obs : np .ndarray , model : np .ndarray ) -> float :
490
+ def ev (obs : np .ndarray , model : np .ndarray ) -> Any :
491
491
"""alias for explained_variance"""
492
492
assert obs .size == model .size
493
493
return explained_variance (obs , model )
494
494
495
495
496
- def explained_variance (obs : np .ndarray , model : np .ndarray ) -> float :
496
+ def explained_variance (obs : np .ndarray , model : np .ndarray ) -> Any :
497
497
r"""EV: Explained variance
498
498
499
499
EV is the explained variance and measures the proportion
@@ -520,10 +520,10 @@ def explained_variance(obs: np.ndarray, model: np.ndarray) -> float:
520
520
if len (obs ) == 0 :
521
521
return np .nan
522
522
523
- nominator = np .sum ((obs - obs .mean ()) ** 2 ) - np .sum (
523
+ nominator : Any = np .sum ((obs - obs .mean ()) ** 2 ) - np .sum ( # type: ignore
524
524
((obs - obs .mean ()) - (model - model .mean ())) ** 2
525
525
)
526
- denominator = np .sum ((obs - obs .mean ()) ** 2 )
526
+ denominator : Any = np .sum ((obs - obs .mean ()) ** 2 )
527
527
528
528
return nominator / denominator
529
529
@@ -534,7 +534,7 @@ def pr(
534
534
inter_event_level : float = 0.7 ,
535
535
AAP : Union [int , float ] = 2 ,
536
536
inter_event_time : str = "36h" ,
537
- ) -> float :
537
+ ) -> Any :
538
538
"""alias for peak_ratio"""
539
539
assert obs .size == model .size
540
540
return peak_ratio (obs , model , inter_event_level , AAP , inter_event_time )
@@ -546,7 +546,7 @@ def peak_ratio(
546
546
inter_event_level : float = 0.7 ,
547
547
AAP : Union [int , float ] = 2 ,
548
548
inter_event_time : str = "36h" ,
549
- ) -> float :
549
+ ) -> Any :
550
550
r"""Peak Ratio
551
551
552
552
PR is the mean of the largest-N individual ratios of identified peaks in the
@@ -633,7 +633,7 @@ def peak_ratio(
633
633
return res
634
634
635
635
636
- def willmott (obs : np .ndarray , model : np .ndarray ) -> float :
636
+ def willmott (obs : np .ndarray , model : np .ndarray ) -> Any :
637
637
r"""Willmott's Index of Agreement
638
638
639
639
A scaled representation of the predictive accuracy of the model against observations. A value of 1 indicates a perfect match, and 0 indicates no agreement at all.
@@ -662,13 +662,15 @@ def willmott(obs: np.ndarray, model: np.ndarray) -> float:
662
662
return np .nan
663
663
664
664
residual = model - obs
665
- nominator = np .sum (residual ** 2 )
666
- denominator = np .sum ((np .abs (model - obs .mean ()) + np .abs (obs - obs .mean ())) ** 2 )
665
+ nominator : Any = np .sum (residual ** 2 )
666
+ denominator : Any = np .sum (
667
+ (np .abs (model - obs .mean ()) + np .abs (obs - obs .mean ())) ** 2
668
+ )
667
669
668
670
return 1 - nominator / denominator
669
671
670
672
671
- def hit_ratio (obs : np .ndarray , model : np .ndarray , a = 0.1 ) -> float :
673
+ def hit_ratio (obs : np .ndarray , model : np .ndarray , a = 0.1 ) -> Any :
672
674
r"""Fraction within obs ± acceptable deviation
673
675
674
676
$$
@@ -693,7 +695,7 @@ def hit_ratio(obs: np.ndarray, model: np.ndarray, a=0.1) -> float:
693
695
return np .mean (np .abs (obs - model ) < a )
694
696
695
697
696
- def lin_slope (obs : np .ndarray , model : np .ndarray , reg_method = "ols" ) -> float :
698
+ def lin_slope (obs : np .ndarray , model : np .ndarray , reg_method = "ols" ) -> Any :
697
699
r"""Slope of the regression line.
698
700
699
701
$$
@@ -736,11 +738,11 @@ def _linear_regression(
736
738
return slope , intercept
737
739
738
740
739
- def _std_obs (obs : np .ndarray , model : np .ndarray ) -> float :
741
+ def _std_obs (obs : np .ndarray , model : np .ndarray ) -> Any :
740
742
return obs .std ()
741
743
742
744
743
- def _std_mod (obs : np .ndarray , model : np .ndarray ) -> float :
745
+ def _std_mod (obs : np .ndarray , model : np .ndarray ) -> Any :
744
746
return model .std ()
745
747
746
748
@@ -894,7 +896,7 @@ def _c_residual(obs: np.ndarray, model: np.ndarray) -> np.ndarray:
894
896
return resi
895
897
896
898
897
- def c_bias (obs : np .ndarray , model : np .ndarray ) -> float :
899
+ def c_bias (obs : np .ndarray , model : np .ndarray ) -> Any :
898
900
"""Circular bias (mean error)
899
901
900
902
Parameters
@@ -924,7 +926,7 @@ def c_bias(obs: np.ndarray, model: np.ndarray) -> float:
924
926
return circmean (resi , low = - 180.0 , high = 180.0 )
925
927
926
928
927
- def c_max_error (obs : np .ndarray , model : np .ndarray ) -> float :
929
+ def c_max_error (obs : np .ndarray , model : np .ndarray ) -> Any :
928
930
"""Circular max error
929
931
930
932
Parameters
@@ -962,7 +964,7 @@ def c_mean_absolute_error(
962
964
obs : np .ndarray ,
963
965
model : np .ndarray ,
964
966
weights : Optional [np .ndarray ] = None ,
965
- ) -> float :
967
+ ) -> Any :
966
968
"""Circular mean absolute error
967
969
968
970
Parameters
@@ -990,7 +992,7 @@ def c_mae(
990
992
obs : np .ndarray ,
991
993
model : np .ndarray ,
992
994
weights : Optional [np .ndarray ] = None ,
993
- ) -> float :
995
+ ) -> Any :
994
996
"""alias for circular mean absolute error"""
995
997
return c_mean_absolute_error (obs , model , weights )
996
998
@@ -999,7 +1001,7 @@ def c_root_mean_squared_error(
999
1001
obs : np .ndarray ,
1000
1002
model : np .ndarray ,
1001
1003
weights : Optional [np .ndarray ] = None ,
1002
- ) -> float :
1004
+ ) -> Any :
1003
1005
"""Circular root mean squared error
1004
1006
1005
1007
Parameters
@@ -1026,7 +1028,7 @@ def c_rmse(
1026
1028
obs : np .ndarray ,
1027
1029
model : np .ndarray ,
1028
1030
weights : Optional [np .ndarray ] = None ,
1029
- ) -> float :
1031
+ ) -> Any :
1030
1032
"""alias for circular root mean squared error"""
1031
1033
return c_root_mean_squared_error (obs , model , weights )
1032
1034
@@ -1035,7 +1037,7 @@ def c_unbiased_root_mean_squared_error(
1035
1037
obs : np .ndarray ,
1036
1038
model : np .ndarray ,
1037
1039
weights : Optional [np .ndarray ] = None ,
1038
- ) -> float :
1040
+ ) -> Any :
1039
1041
"""Circular unbiased root mean squared error
1040
1042
1041
1043
Parameters
@@ -1065,7 +1067,7 @@ def c_urmse(
1065
1067
obs : np .ndarray ,
1066
1068
model : np .ndarray ,
1067
1069
weights : Optional [np .ndarray ] = None ,
1068
- ) -> float :
1070
+ ) -> Any :
1069
1071
"""alias for circular unbiased root mean squared error"""
1070
1072
return c_unbiased_root_mean_squared_error (obs , model , weights )
1071
1073
0 commit comments