def get_small_grids_around_coord(datagrid, xgrid, ygrid, x, y, nx, ny):
    """

    gives back a nx x ny matrix around (x, y) from xgrid, ygrid, datagrid


    ################################
    #        -> x
    #   |              2nx+1
    # y v            <-------->
    #           ____________________
    #          |      ________      |
    #  2ny+1 ^ |     |        |     |
    #        | |     |   x    |     |
    #        v |     |________|     |
    #          |____________________|
    #
    ################################

    Parameters
    ----------
    griddata 2d arr
    xgrid 2d arr
    ygrid 2d arr
    x x-coordinate of a point of interest
    y y-coordinate of a point of interest
    nx
    ny

    Returns
    -------
    xgrid_around_coord: 2d arr with shape (2nx+1, 2ny+1)
    ygrid_around_coord: 2d arr with shape (2nx+1, 2ny+1)
    datagrid_around_coord: 2d arr with shape (2nx+1, 2ny+1)

    """

    def get_proper_indices_for_x(a, ncolumns):
        if a < 0:
            return 0
        elif a >= ncolumns:
            return int(ncolumns - 1)
        else:
            return int(a)

    def get_proper_indices_for_y(a, nrows):
        if a < 0:
            return 0
        elif a >= nrows:
            return int(nrows - 1)
        else:
            return int(a)
    nrows, ncolumns = datagrid.shape
    datagrid_around_coord = datagrid[get_proper_indices_for_y(y - ny, nrows): get_proper_indices_for_y(y + ny, nrows),
                            get_proper_indices_for_x(x - nx, ncolumns): get_proper_indices_for_x(x + nx, ncolumns)]
    xgrid_around_coord = xgrid[get_proper_indices_for_y(y - ny, nrows): get_proper_indices_for_y(y + ny, nrows),
                         get_proper_indices_for_x(x - nx, ncolumns): get_proper_indices_for_x(x + nx, ncolumns)]
    ygrid_around_coord = ygrid[get_proper_indices_for_y(y - ny, nrows): get_proper_indices_for_y(y + ny, nrows),
                         get_proper_indices_for_x(x - nx, ncolumns): get_proper_indices_for_x(x + nx, ncolumns)]
    return xgrid_around_coord, ygrid_around_coord, datagrid_around_coord