(grid, lon_b, lat_b)
Add corner information to ESMF.Grid for conservative regridding.

    Not needed for other methods like bilinear or nearest neighbour.

    Parameters
    ----------
    grid : ESMF.Grid object
        Generated by ``esmf_grid()``. Will be modified in-place.

    lon_b, lat_b : 2D numpy array
        Longitute/Latitude of cell corner
        Recommend Fortran-ordering to match ESMPy internal.
        Shape should be ``(Nlon+1, Nlat+1)``, or ``(Nx+1, Ny+1)``
Add corner information to ESMF.Grid for conservative regridding.
Add corner information to ESMF . Grid for conservative regridding .
def add_corner(grid, lon_b, lat_b):
    '''
    Add corner information to ESMF.Grid for conservative regridding.

    Not needed for other methods like bilinear or nearest neighbour.

    Parameters
    ----------
    grid : ESMF.Grid object
        Generated by ``esmf_grid()``. Will be modified in-place.

    lon_b, lat_b : 2D numpy array
        Longitute/Latitude of cell corner
        Recommend Fortran-ordering to match ESMPy internal.
        Shape should be ``(Nlon+1, Nlat+1)``, or ``(Nx+1, Ny+1)``
    '''

    # codes here are almost the same as esmf_grid(),
    # except for the "staggerloc" keyword
    staggerloc = ESMF.StaggerLoc.CORNER  # actually just integer 3

    for a in [lon_b, lat_b]:
        warn_f_contiguous(a)

    warn_lat_range(lat_b)

    assert lon_b.ndim == 2, "Input grid must be 2D array"
    assert lon_b.shape == lat_b.shape, "lon_b and lat_b must have same shape"
    assert np.array_equal(lon_b.shape, grid.max_index+1), (
           "lon_b should be size (Nx+1, Ny+1)")
    assert (grid.num_peri_dims == 0) and (grid.periodic_dim is None), (
           "Cannot add corner for periodic grid")

    grid.add_coords(staggerloc=staggerloc)

    lon_b_pointer = grid.get_coords(coord_dim=0, staggerloc=staggerloc)
    lat_b_pointer = grid.get_coords(coord_dim=1, staggerloc=staggerloc)

    lon_b_pointer[...] = lon_b
    lat_b_pointer[...] = lat_b
def add_corner ( grid , lon_b , lat_b ) : # codes here are almost the same as esmf_grid(), # except for the "staggerloc" keyword staggerloc = ESMF . StaggerLoc . CORNER # actually just integer 3 for a in [ lon_b , lat_b ] : warn_f_contiguous ( a ) warn_lat_range ( lat_b ) assert lon_b . ndim == 2 , "Input grid must be 2D array" assert lon_b . shape == lat_b . shape , "lon_b and lat_b must have same shape" assert np . array_equal ( lon_b . shape , grid . max_index + 1 ) , ( "lon_b should be size (Nx+1, Ny+1)" ) assert ( grid . num_peri_dims == 0 ) and ( grid . periodic_dim is None ) , ( "Cannot add corner for periodic grid" ) grid . add_coords ( staggerloc = staggerloc ) lon_b_pointer = grid . get_coords ( coord_dim = 0 , staggerloc = staggerloc ) lat_b_pointer = grid . get_coords ( coord_dim = 1 , staggerloc = staggerloc ) lon_b_pointer [ ... ] = lon_b lat_b_pointer [ ... ] = lat_b