def ar_acf(gamma, n=None):
    """
    Compute theoretical autocorrelation function (ACF) from the AR(p) model
    with lag-l, l=1,2,...,p temporal autocorrelation coefficients.

    Parameters
    ----------
    gamma: array-like
        Array of length p containing the lag-l, l=1,2,...p, temporal
        autocorrelation coefficients.
        The correlation coefficients are assumed to be in ascending
        order with respect to time lag.
    n: int
        Desired length of ACF array. Must be greater than len(gamma).

    Returns
    -------
    out: array-like
        Array containing the ACF values.
    """
    ar_order = len(gamma)
    if n == ar_order or n is None:
        return gamma
    elif n < ar_order:
        raise ValueError(
            "n=%i, but must be larger than the order of the AR process %i"
            % (n, ar_order)
        )

    phi = estimate_ar_params_yw(gamma)[:-1]

    acf = gamma.copy()
    for t in range(0, n - ar_order):
        # Retrieve gammas (in reverse order)
        gammas = acf[t : t + ar_order][::-1]
        # Compute next gamma
        gamma_ = np.sum(gammas * phi)
        acf.append(gamma_)

    return acf
Compute theoretical autocorrelation function (ACF) from the AR(p) model
with lag-l, l=1,2,...,p temporal autocorrelation coefficients.

Parameters
----------
gamma: array-like
Array of length p containing the lag-l, l=1,2,...p, temporal
autocorrelation coefficients.
The correlation coefficients are assumed to be in ascending
order with respect to time lag.
n: int
Desired length of ACF array. Must be greater than len(gamma).

Returns
-------
out: array-like
Array containing the ACF values.
pysteps/timeseries/autoregression.py