pastas.forecast.get_overall_mean_and_variance#

pastas.forecast.get_overall_mean_and_variance(df: pandas.DataFrame) tuple[pandas.DataFrame, pandas.DataFrame]#

Method to get the overall mean and variance of the forecast ensemble.

Parameters:

df (pandas.DataFrame) – DataFrame containing the forecasts. The columns are a MultiIndex with the first level the ensemble member, the second level the parameter member, and the third level the mean and the variance of each forecast member. The index is a DatetimeIndex with the time steps of the forecasts.

Returns:

  • overall_mean (pandas.Series) – Series with the mean of the forecasts.

  • overall_variance (pandas.Series) – Series with the variance of the forecasts.

Notes

This method is used to get the overall mean and variance of the forecasts. The mean and variance are calculated from the ensemble members and parameter members using the law of total variance.

Example

Simple example showing how to use the get_overall_mean_and_variance function:

import pastas as ps
import pandas as pd
import numpy as np
from pastas.forecast import get_overall_mean_and_variance

# Create a sample DataFrame with forecasts
index = pd.date_range("2023-01-01", periods=10, freq="D")
data = np.random.rand(10, 6)
columns = pd.MultiIndex.from_product(
    [range(3), range(2), ["mean", "var"]],
    names=["ensemble_member", "param_member", "forecast"],
)
df = pd.DataFrame(data=data, index=index, columns=columns)

# Call the function to get the overall mean and variance
mean, var = get_overall_mean_and_variance(df)
print(mean)