def positive_index(index, size):
    """
    Return a positive index from any index. If the index is positive, it is
    returned. If negative, size+index will be returned.

    Parameters
    ----------
    index : int
        The input index.
    size : int
        The size of the indexed dimension.

    Returns
    -------
    int
        A positive index corresponding to the input index.

    Raises
    ------
    ValueError
        If the given index is not valid for the given size.
    """

    if not -size <= index <= size:
        raise ValueError(
            "Invalid index {} for size {}".format(index, size))

    if index < 0:
        index = size + index

    return index