def _masked_convolution(field, kernel):
    """Compute "masked" convolution where non-finite values are ignored."""
    mask = np.isfinite(field)

    field = field.copy()
    field[~mask] = 0.0

    field_c = np.ones(field.shape) * np.nan
    field_c[mask] = convolve(field, kernel, mode="same")[mask]
    field_c[mask] /= convolve(mask.astype(float), kernel, mode="same")[mask]

    return field_c
Compute "masked" convolution where non-finite values are ignored.
pysteps/nowcasts/linda.py