def count_out_distribution(df, key, reference="canopy", n_sigma=2):
    """
    Count the number of real values out of the uncertainty band.

    The provided dataframe needs to contain the keys "{key}_{reference}", "{key}_mean" and "{key}_sigma".

    :param df: data frame containing all relevant data
    :type df: pd.DataFrame
    :param key: name of variable to use: "GPP" | "NEE" | "Reco"
    :type key: str
    :param reference: postfix of the target value
    :type reference: str
    :param n_sigma: width of the uncertainty band to consider
    :type n_sigma: float
    :return: number of target values out of mean ± n_sigma * sigma
    :rtype: int
    """
    ref = key + "_" + reference
    mean = key + "_mean"
    sigma = key + "_sigma"

    lower = df[mean] - n_sigma * df[sigma]
    upper = df[mean] + n_sigma * df[sigma]

    above = df[ref] > upper
    below = df[ref] < lower
    return sum(above) + sum(below)