def get_grid_offset(function, axis):
    """
    For a function, return the grid offset for a specified axis.

    Parameters
    ----------
    function : devito Function
        The function to get the offset of
    axis : int
        The axis for which offset should be recovered
    """
    if function.is_Staggered:
        stagger = function.staggered
        if isinstance(stagger, tuple):
            if function.space_dimensions[axis] in stagger:
                return 0.5
            elif -function.space_dimensions[axis] in stagger:
                return -0.5
        else:
            if function.space_dimensions[axis] == stagger:
                return 0.5
            elif -function.space_dimensions[axis] == stagger:
                return -0.5
    return 0.