diff --git a/model_evaluation/double_collocation.py b/model_evaluation/double_collocation.py index a58776d..6d12ca1 100644 --- a/model_evaluation/double_collocation.py +++ b/model_evaluation/double_collocation.py @@ -308,6 +308,7 @@ def remove_nans(obs, pre): obs, pre : array_like Observed and predicted arrays with filtered Nans. """ + obs, pre = obs.astype(float), pre.astype(float) valid = np.logical_and(np.isfinite(obs), np.isfinite(pre)) obs = obs[valid] pre = pre[valid] @@ -336,4 +337,24 @@ def density_plot(x, y, ax, **scatter_kwargs): method="splinef2d", bounds_error=False) - ax.scatter(x,y, c=z, **scatter_kwargs) \ No newline at end of file + ax.scatter(x,y, c=z, **scatter_kwargs) + +def nse(obs, pre): + """Nash-Sutcliffe efficiency + Parameters + ---------- + obs, pre : array_like + Arrays of N elements of spatially-collocated observed and predicted systems. + N is the sample size. + + Returns + ------- + e : array_like + Nash-Sutcliffe efficiency index + """ + + obs, pre = remove_nans(obs, pre) + mean_obs = np.mean(obs) + e = 1. - np.sum((obs - pre)**2) / np.sum((obs - mean_obs)**2) + return e +