def reformat_slice(
        sl_in: slice,
        limit_in: int,
        mirror: bool) -> slice:
    """
    Reformat the slice, with optional reverse operation.

    Note that the mirror operation doesn't run the slice backwards across the
    same elements, but rather creates a mirror image of the slice. This is
    to properly accommodate the data segment reverse symmetry transform.

    Parameters
    ----------
    sl_in : slice
        From prior processing, it is expected that `sl_in.step` is populated,
        and `sl_in.start` is non-negative, and `sl_in.stop` is non-negative or
        `None` (only in th event that `sl_in.step < 0`.
    limit_in : int
        The upper limit for the axis to which this slice pertains.
    mirror : bool
        Create the mirror image slice?

    Returns
    -------
    slice
    """

    if sl_in.step is None:
        raise ValueError('input slice has unpopulated step value')
    if sl_in.start is not None and sl_in.start < 0:
        raise ValueError('input slice has negative start value')
    if sl_in.stop is not None and sl_in.stop < 0:
        raise ValueError('input slice has negative stop value')

    if mirror:
        # make the mirror image of the slice, the step maintains the same sign,
        # and will be reversed by the format function
        if sl_in.step > 0:
            start_in = 0 if sl_in.start is None else sl_in.start
            stop_in = limit_in if sl_in.stop is None else sl_in.stop
            if sl_in.step > (stop_in - start_in):
                step_in = stop_in - start_in
            else:
                step_in = sl_in.step

            # what is the last included location?
            count = int((stop_in - start_in)/float(step_in))
            final_location = start_in + count*step_in
            return slice(limit_in - final_location, limit_in - start_in, step_in)
        else:
            start_in = limit_in - 1 if sl_in.start is None else sl_in.start
            stop_in = -1 if sl_in.stop is None else sl_in.stop

            if sl_in.step < (stop_in - start_in):
                step_in = stop_in - start_in
            else:
                step_in = sl_in.step
            count = int((stop_in - start_in) / float(step_in))
            final_location = start_in + count*step_in
            return slice(limit_in - final_location, limit_in - start_in, step_in)
    else:
        return sl_in