kge_2012

postprocessinglib.evaluation.metrics.kge_2012(observed: DataFrame, simulated: Union[DataFrame, List[DataFrame]], stations: list[int] = [], scale: list[float] = [1.0, 1.0, 1.0], return_kge_components: bool = False) DataFrame

Calculates the Kling-Gupta Efficiency of the data

Parameters:
  • observed (pd.DataFrame) – Observed values[1: Datetime ; 2+: Streamflow Values]

  • simulated (pd.DataFrame or list[pd.DataFrame]) – Simulated values[1: Datetime ; 2+: Streamflow Values]

  • stations (list[int]) – numbers pointing to the location of the stations in the list of stations. Values can be any number from 1 to number of stations in the data

  • scale (list[float, float, float]) – Scale factor for correlation[0], alpha[1], and beta[2] components in the calculation of KGE

  • return_kge_components (bool, default False) – If True, returns a MultiIndex DataFrame with (KGE, r, alpha, beta) x (model#). If False, returns the original KGE-only DataFrame (backward compatible).

Returns:

the Kling-Gupta Efficiency of the data

Return type:

pd.DataFrame

Note

This is different from the regular kge in that this uses the coefficient of Variation as its bias term (i.e., std/mean) as opposed to just the mean

Example

Calculate the Kling-Gupta Efficiency

>>> import numpy as np
>>> import pandas as pd
>>> from postprocessinglib.evaluation import metrics
>>> # Create your index as an array
>>> index = np.array([1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990])
>>> .
>>> # Create a test dataframe
>>> test_df = pd.DataFrame(data = np.random.rand(10, 4), columns = ("obs1", "sim1", "obs2", "sim2"), index = index)
>>> print(test_df)
          obs1      sim1      obs2      sim2
1981  0.966878  0.348580  0.053977  0.043133
1982  0.188252  0.739990  0.941848  0.580866
1983  0.430902  0.292824  0.963190  0.798885
1984  0.718644  0.098746  0.031072  0.446317
1985  0.586581  0.479616  0.541689  0.639898
1986  0.380978  0.193639  0.737498  0.025509
1987  0.072452  0.095210  0.188173  0.357554
1988  0.833037  0.542694  0.913704  0.963027
1989  0.434239  0.817284  0.425448  0.865841
1990  0.698412  0.484796  0.693588  0.981778
>>> # Generate the observed and simulated Dataframes
>>> obs = test_df.iloc[:, [0, 2]]
>>> sim = test_df.iloc[:, [1, 3]]
>>> .
>>> Calculate the Kling-Gupta Efficiency
>>> kge_2012 = metrics.kge_2012(observed = obs, simulated = sim)
>>> print(kge_2012)
                model1
    Station 1  -0.0210
    Station 2  0.48940

JUPYTER NOTEBOOK Examples