Skip to content

Commit

Permalink
Include computation of Nash-Sutcliffe eficiency index
Browse files Browse the repository at this point in the history
  • Loading branch information
hectornieto committed Apr 25, 2022
1 parent 4fdc784 commit 55a348e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion model_evaluation/double_collocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
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

0 comments on commit 55a348e

Please # to comment.