Skip to content

Instantly share code, notes, and snippets.

@pritamd47
Created February 15, 2022 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pritamd47/dd512a1892c208d030a61fe370fed4d6 to your computer and use it in GitHub Desktop.
Save pritamd47/dd512a1892c208d030a61fe370fed4d6 to your computer and use it in GitHub Desktop.
Compute statistics for observed and modeled time-series relevant to hydrological modeling
import scipy.stats as stats
import numpy as np
def get_stats(obs, mod):
corr, corr_p = stats.pearsonr(obs, mod)
nse = 1 - (np.sum((obs - mod)**2)/np.sum((obs - np.mean(obs))**2))
nse1 = 1 - (np.sum(np.abs(obs - mod))/np.sum(np.abs(obs - np.mean(obs))))
rmse = np.sqrt(np.sum((obs-mod)**2)/len(mod))
mae = np.sum(np.abs(mod-obs))/len(mod)
return {'pearson-r': corr, 'pearson-r p-val': corr_p, 'nse': nse, 'nse1': nse1, 'rmse': rmse, 'mae': mae}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment