def _log_slope(log_k, log_power_spectrum):
    """
    Calculate the log-slope of the power spectrum given an array of logarithmic wavenumbers
    and an array of logarithmic power spectrum values.
    """
    lk_min = log_k.min()
    lk_max = log_k.max()
    lk_range = lk_max - lk_min
    lk_min += (1 / 6) * lk_range
    lk_max -= (1 / 6) * lk_range
    selected = (lk_min <= log_k) & (log_k <= lk_max)
    lk_sel = log_k[selected]
    ps_sel = log_power_spectrum[selected]
    alpha = np.polyfit(lk_sel, ps_sel, 1)[0]
    alpha = -alpha
    return alpha
Calculate the log-slope of the power spectrum given an array of logarithmic wavenumbers
and an array of logarithmic power spectrum values.
pysteps/downscaling/rainfarm.py