(lon, lat, periodic=False)
return grid
Create an ESMF.Grid object, for contrusting ESMF.Field and ESMF.Regrid

    Parameters
    ----------
    lon, lat : 2D numpy array
         Longitute/Latitude of cell centers.

         Recommend Fortran-ordering to match ESMPy internal.

         Shape should be ``(Nlon, Nlat)`` for rectilinear grid,
         or ``(Nx, Ny)`` for general quadrilateral grid.

    periodic : bool, optional
        Periodic in longitude? Default to False.
        Only useful for source grid.

    Returns
    -------
    grid : ESMF.Grid object
Create an ESMF.Grid object, for contrusting ESMF.Field and ESMF.Regrid
Create an ESMF . Grid object for contrusting ESMF . Field and ESMF . Regrid
def esmf_grid(lon, lat, periodic=False):
    '''
    Create an ESMF.Grid object, for contrusting ESMF.Field and ESMF.Regrid

    Parameters
    ----------
    lon, lat : 2D numpy array
         Longitute/Latitude of cell centers.

         Recommend Fortran-ordering to match ESMPy internal.

         Shape should be ``(Nlon, Nlat)`` for rectilinear grid,
         or ``(Nx, Ny)`` for general quadrilateral grid.

    periodic : bool, optional
        Periodic in longitude? Default to False.
        Only useful for source grid.

    Returns
    -------
    grid : ESMF.Grid object
    '''

    # ESMPy expects Fortran-ordered array.
    # Passing C-ordered array will slow down performance.
    for a in [lon, lat]:
        warn_f_contiguous(a)

    warn_lat_range(lat)

    # ESMF.Grid can actually take 3D array (lon, lat, radius),
    # but regridding only works for 2D array
    assert lon.ndim == 2, "Input grid must be 2D array"
    assert lon.shape == lat.shape, "lon and lat must have same shape"

    staggerloc = ESMF.StaggerLoc.CENTER  # actually just integer 0

    if periodic:
        num_peri_dims = 1
    else:
        num_peri_dims = None

    # ESMPy documentation claims that if staggerloc and coord_sys are None,
    # they will be set to default values (CENTER and SPH_DEG).
    # However, they actually need to be set explicitly,
    # otherwise grid._coord_sys and grid._staggerloc will still be None.
    grid = ESMF.Grid(np.array(lon.shape), staggerloc=staggerloc,
                     coord_sys=ESMF.CoordSys.SPH_DEG,
                     num_peri_dims=num_peri_dims)

    # The grid object points to the underlying Fortran arrays in ESMF.
    # To modify lat/lon coordinates, need to get pointers to them
    lon_pointer = grid.get_coords(coord_dim=0, staggerloc=staggerloc)
    lat_pointer = grid.get_coords(coord_dim=1, staggerloc=staggerloc)

    # Use [...] to avoid overwritting the object. Only change array values.
    lon_pointer[...] = lon
    lat_pointer[...] = lat

    return grid
def esmf_grid ( lon , lat , periodic = False ) : # ESMPy expects Fortran-ordered array. # Passing C-ordered array will slow down performance. for a in [ lon , lat ] : warn_f_contiguous ( a ) warn_lat_range ( lat ) # ESMF.Grid can actually take 3D array (lon, lat, radius), # but regridding only works for 2D array assert lon . ndim == 2 , "Input grid must be 2D array" assert lon . shape == lat . shape , "lon and lat must have same shape" staggerloc = ESMF . StaggerLoc . CENTER # actually just integer 0 if periodic : num_peri_dims = 1 else : num_peri_dims = None # ESMPy documentation claims that if staggerloc and coord_sys are None, # they will be set to default values (CENTER and SPH_DEG). # However, they actually need to be set explicitly, # otherwise grid._coord_sys and grid._staggerloc will still be None. grid = ESMF . Grid ( np . array ( lon . shape ) , staggerloc = staggerloc , coord_sys = ESMF . CoordSys . SPH_DEG , num_peri_dims = num_peri_dims ) # The grid object points to the underlying Fortran arrays in ESMF. # To modify lat/lon coordinates, need to get pointers to them lon_pointer = grid . get_coords ( coord_dim = 0 , staggerloc = staggerloc ) lat_pointer = grid . get_coords ( coord_dim = 1 , staggerloc = staggerloc ) # Use [...] to avoid overwritting the object. Only change array values. lon_pointer [ ... ] = lon lat_pointer [ ... ] = lat return grid