(ds, need_bounds=False, periodic=None, append=None)
return grid, lon.shape
Convert xarray DataSet or dictionary to ESMF.Grid object.

    Parameters
    ----------
    ds : xarray DataSet or dictionary
        Contains variables ``lon``, ``lat``,
        and optionally ``lon_b``, ``lat_b`` if need_bounds=True.

        Shape should be ``(n_lat, n_lon)`` or ``(n_y, n_x)``,
        as normal C or Python ordering. Will be then tranposed to F-ordered.

    need_bounds : bool, optional
        Need cell boundary values?

    periodic : bool, optional
        Periodic in longitude?

    Returns
    -------
    grid : ESMF.Grid object
Convert xarray DataSet or dictionary to ESMF.Grid object.
Convert xarray DataSet or dictionary to ESMF . Grid object .
def ds_to_ESMFgrid(ds, need_bounds=False, periodic=None, append=None):
    '''
    Convert xarray DataSet or dictionary to ESMF.Grid object.

    Parameters
    ----------
    ds : xarray DataSet or dictionary
        Contains variables ``lon``, ``lat``,
        and optionally ``lon_b``, ``lat_b`` if need_bounds=True.

        Shape should be ``(n_lat, n_lon)`` or ``(n_y, n_x)``,
        as normal C or Python ordering. Will be then tranposed to F-ordered.

    need_bounds : bool, optional
        Need cell boundary values?

    periodic : bool, optional
        Periodic in longitude?

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

    '''

    # use np.asarray(dr) instead of dr.values, so it also works for dictionary
    lon = np.asarray(ds['lon'])
    lat = np.asarray(ds['lat'])
    lon, lat = as_2d_mesh(lon, lat)

    # tranpose the arrays so they become Fortran-ordered
    grid = esmf_grid(lon.T, lat.T, periodic=periodic)

    if need_bounds:
        lon_b = np.asarray(ds['lon_b'])
        lat_b = np.asarray(ds['lat_b'])
        lon_b, lat_b = as_2d_mesh(lon_b, lat_b)
        add_corner(grid, lon_b.T, lat_b.T)

    return grid, lon.shape
def ds_to_ESMFgrid ( ds , need_bounds = False , periodic = None , append = None ) : # use np.asarray(dr) instead of dr.values, so it also works for dictionary lon = np . asarray ( ds [ 'lon' ] ) lat = np . asarray ( ds [ 'lat' ] ) lon , lat = as_2d_mesh ( lon , lat ) # tranpose the arrays so they become Fortran-ordered grid = esmf_grid ( lon . T , lat . T , periodic = periodic ) if need_bounds : lon_b = np . asarray ( ds [ 'lon_b' ] ) lat_b = np . asarray ( ds [ 'lat_b' ] ) lon_b , lat_b = as_2d_mesh ( lon_b , lat_b ) add_corner ( grid , lon_b . T , lat_b . T ) return grid , lon . shape