import warnings


def resample_nanmean(data, dim='time', resample='M', nmin=15, **kwargs):
    """ Resample Dataset and apply a minimum for resampling mean

    Args:
        data (DataArray, Dataset): Input fields
        dim (str): datetime dimension
        resample (str): upsampling frequency
        nmin (int): minimum of samples per frequency
        **kwargs:

    Returns:
        DataArray, Dataset : means on freq
    """
    with warnings.catch_warnings():
        warnings.simplefilter("ignore", category=RuntimeWarning)
        dd = data.resample(**{dim: resample}).count(dim)
        return data.resample(**{dim: resample}).mean(dim).where(dd > nmin)