def _get_axis(array, axis, fname):
    """
    axis = _get_axis(array, axis, fname)

    Checks that ``axis`` is a valid axis of ``array`` and normalises it.

    Parameters
    ----------
    array : ndarray
    axis : int
    fname : str
        Function name. Used in error messages

    Returns
    -------
    axis : int
        The positive index of the axis to use
    """
    if axis < 0:
        axis += len(array.shape)
    if not 0 <= axis < len(array.shape):
        raise ValueError(
            'mahotas.%s: `axis` is out of bounds (maximum was %s, got %s)' %
            (fname, array.ndim, axis))
    return axis
