def spatial_window(alpha, delta, spx, spy, alpha_axis, delta_axis):
    """
    Compute a 2D window centered at (alpha,delta) within alpha_axis and delta_axis.

    spatial_window() returns a tuple (alpha_window,delta_window), where each element
    are the lower and upper indices for each axis. The window correspond to a window
    of freq +- spx or freq +- spy depending on the axis. This window is limited by
    the axis borders. Equispaced axes are assumed.
    @rtype : tuple
    @param alpha: RA center
    @param delta: DEC center
    @param spx: Semiaxis X
    @param spy: Semiaxis Y
    @param alpha_axis: a equispaced array of elements
    @param delta_axis: a equispaced array of elements
    """
    dlta_x = alpha_axis[1] - alpha_axis[0]
    dlta_y = delta_axis[1] - delta_axis[0]
    xbord = [int(round((alpha - spx - alpha_axis[0]) / dlta_x)), int(round(
        (alpha + spx - alpha_axis[0]) / dlta_x))]
    ybord = [int(round((delta - spy - delta_axis[0]) / dlta_y)), int(round(
        (delta + spy - delta_axis[0]) / dlta_y))]
    if xbord[0] < 0:
        xbord[0] = 0
    if ybord[0] < 0:
        ybord[0] = 0
    if xbord[1] > len(alpha_axis):
        xbord[1] = len(alpha_axis)
    if ybord[1] > len(delta_axis):
        ybord[1] = len(delta_axis)
    return ybord, xbord
