def remove_repeated_time_index(ds):  # {{{
    """
    Remove repeated times from xarray dataset.

    Parameters
    ----------
    ds : ``xarray.DataSet`` object
        The data set potentially containing repeated time indices.

    Returns
    -------
    ds : ``xarray.DataSet`` object
        A copy of the original data set with any repeated time indices removed.
    """
    # Authors
    # -------
    # Phillip J. Wolfram, Xylar Asay-Davis

    # get repeated indices
    times = ds.Time.values
    indices = list(range(len(times)))
    uniqueTimes = set()
    remove = []
    for timeIndex, time in enumerate(times):
        if time not in uniqueTimes:
            uniqueTimes.add(time)
        else:
            remove.append(timeIndex)

    # remove repeaded indices, working backwards from the last
    remove.reverse()
    for timeIndex in remove:
        indices.pop(timeIndex)

    # remove repeated indices
    ds = ds.isel(Time=indices)

    return ds