Return the number of consecutive true values in array for runs at least as long as given duration.

        Parameters
        ----------
        da: N-dimensional Xarray data array  (boolean)
          Input data array
        window : int
          Minimum run length.
        dim : Xarray dimension (default = 'time')
          Dimension along which to calculate consecutive run


        Returns
        -------
        out : N-dimensional xarray data array (int)
          Total number of true values part of a consecutive runs of at least `window` long.

def windowed_run_count(da, window, dim='time'):
    """Return the number of consecutive true values in array for runs at least as long as given duration.

        Parameters
        ----------
        da: N-dimensional Xarray data array  (boolean)
          Input data array
        window : int
          Minimum run length.
        dim : Xarray dimension (default = 'time')
          Dimension along which to calculate consecutive run


        Returns
        -------
        out : N-dimensional xarray data array (int)
          Total number of true values part of a consecutive runs of at least `window` long.
        """
    d = rle(da, dim=dim)
    out = d.where(d >= window, 0).sum(dim=dim)
    return out