def _weighted_std(f, w):
    """
    Compute standard deviation of forecast errors with spatially varying weights.
    Values close to zero are omitted.
    """
    mask = np.abs(f - 1.0) > 1e-4
    n = np.count_nonzero(mask)
    if n > 0:
        c = (w[mask].size - 1.0) / n
        return np.sqrt(np.sum(w[mask] * (f[mask] - 1.0) ** 2.0) / (c * np.sum(w[mask])))
    else:
        return np.nan
Compute standard deviation of forecast errors with spatially varying weights.
Values close to zero are omitted.
pysteps/nowcasts/linda.py