calculate_metrics

postprocessinglib.evaluation.metrics.calculate_metrics(observed: DataFrame, simulated: Union[DataFrame, List[DataFrame]], metrices: list[str], stations: list[int] = [], format: str = '', out: str = 'metrics_out', metric_options: dict | None = None) DataFrame

Calculate the requested metrics.

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

  • simulated (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

  • metrices (List[str]) – List of metrics to be calculated

  • format (str) – used to indicate that you want the output to be saved to a output file who’s name is specified by the ‘out’ parameter

  • out (str) – used in tandem with the ‘format’ parameter to specify the name of the output file. it is ‘metrics_out.{format}’ by default

  • metric_options (dict | None) –

    Per-metric keyword options passed to each metric function. For example:

    {
        "KGE": {"return_kge_components": True},
        "KGE 2012": {"return_kge_components": True},
    }
    

Returns:

Dataframe containing each metric to be evaluated and its result

Return type:

pd.DataFrame

Example

Calculation of a list of metrics

>>> from postprocessinglib.evaluation import metrics, data
>>> path = 'MESH_output_streamflow_1.csv'
>>> DATAFRAMES = data.generate_dataframes(csv_fpath=path, warm_up=365)
>>> list_of_metrices = ["MSE", "NSE", "KGE 2012"]
>>> print(metrics.calculate_metrics(observed=DATAFRAMES["DF_OBSERVED"], simulated=DATAFRAMES["DF_SIMULATED"], metrices=list_of_metrics))
    {'MSE': [1890, 665.9], 'NSE': [0.09948, -3.583], 'KGE 2012': [0.3130, -0.1483]}

JUPYTER NOTEBOOK Examples