(self, ds_in, ds_out, method, periodic=False,
                 filename=None, reuse_weights=False, ignore_degenerate=None,
                 locstream_in=False, locstream_out=False)
Make xESMF regridder

        Parameters
        ----------
        ds_in, ds_out : xarray DataSet, or dictionary
            Contain input and output grid coordinates. Look for variables
            ``lon``, ``lat``, and optionally ``lon_b``, ``lat_b`` for
            conservative method.

            Shape can be 1D (n_lon,) and (n_lat,) for rectilinear grids,
            or 2D (n_y, n_x) for general curvilinear grids.
            Shape of bounds should be (n+1,) or (n_y+1, n_x+1).

        method : str
            Regridding method. Options are

            - 'bilinear'
            - 'conservative', **need grid corner information**
            - 'patch'
            - 'nearest_s2d'
            - 'nearest_d2s'

        periodic : bool, optional
            Periodic in longitude? Default to False.
            Only useful for global grids with non-conservative regridding.
            Will be forced to False for conservative regridding.

        filename : str, optional
            Name for the weight file. The default naming scheme is::

                {method}_{Ny_in}x{Nx_in}_{Ny_out}x{Nx_out}.nc

            e.g. bilinear_400x600_300x400.nc

        reuse_weights : bool, optional
            Whether to read existing weight file to save computing time.
            False by default (i.e. re-compute, not reuse).

        ignore_degenerate : bool, optional
            If False (default), raise error if grids contain degenerated cells
            (i.e. triangles or lines, instead of quadrilaterals)

        locstream_in: bool, optional
            input is a LocStream (list of locations)

        locstream_out: bool, optional
            output is a LocStream (list of locations)

        Returns
        -------
        regridder : xESMF regridder object
Make xESMF regridder
Make xESMF regridder
def __init__(self, ds_in, ds_out, method, periodic=False,
                 filename=None, reuse_weights=False, ignore_degenerate=None,
                 locstream_in=False, locstream_out=False):
        """
        Make xESMF regridder

        Parameters
        ----------
        ds_in, ds_out : xarray DataSet, or dictionary
            Contain input and output grid coordinates. Look for variables
            ``lon``, ``lat``, and optionally ``lon_b``, ``lat_b`` for
            conservative method.

            Shape can be 1D (n_lon,) and (n_lat,) for rectilinear grids,
            or 2D (n_y, n_x) for general curvilinear grids.
            Shape of bounds should be (n+1,) or (n_y+1, n_x+1).

        method : str
            Regridding method. Options are

            - 'bilinear'
            - 'conservative', **need grid corner information**
            - 'patch'
            - 'nearest_s2d'
            - 'nearest_d2s'

        periodic : bool, optional
            Periodic in longitude? Default to False.
            Only useful for global grids with non-conservative regridding.
            Will be forced to False for conservative regridding.

        filename : str, optional
            Name for the weight file. The default naming scheme is::

                {method}_{Ny_in}x{Nx_in}_{Ny_out}x{Nx_out}.nc

            e.g. bilinear_400x600_300x400.nc

        reuse_weights : bool, optional
            Whether to read existing weight file to save computing time.
            False by default (i.e. re-compute, not reuse).

        ignore_degenerate : bool, optional
            If False (default), raise error if grids contain degenerated cells
            (i.e. triangles or lines, instead of quadrilaterals)

        locstream_in: bool, optional
            input is a LocStream (list of locations)

        locstream_out: bool, optional
            output is a LocStream (list of locations)

        Returns
        -------
        regridder : xESMF regridder object

        """

        # record basic switches
        if method == 'conservative':
            self.need_bounds = True
            periodic = False  # bound shape will not be N+1 for periodic grid
        else:
            self.need_bounds = False

        self.method = method
        self.periodic = periodic
        self.reuse_weights = reuse_weights
        self.ignore_degenerate = ignore_degenerate
        self.locstream_in = locstream_in
        self.locstream_out = locstream_out

        methods_avail_ls_in = ['nearest_s2d', 'nearest_d2s']
        methods_avail_ls_out = ['bilinear', 'patch'] + methods_avail_ls_in

        if locstream_in and self.method not in methods_avail_ls_in:
            raise ValueError(f'locstream input is only available for method in {methods_avail_ls_in}')
        if locstream_out and self.method not in methods_avail_ls_out:
            raise ValueError(f'locstream output is only available for method in {methods_avail_ls_out}')

        # construct ESMF grid, with some shape checking
        if locstream_in:
            self._grid_in, shape_in = ds_to_ESMFlocstream(ds_in)
        else:
            self._grid_in, shape_in = ds_to_ESMFgrid(ds_in,
                                                     need_bounds=self.need_bounds,
                                                     periodic=periodic
                                                     )
        if locstream_out:
            self._grid_out, shape_out = ds_to_ESMFlocstream(ds_out)
        else:
            self._grid_out, shape_out = ds_to_ESMFgrid(ds_out,
                                                       need_bounds=self.need_bounds
                                                       )

        # record output grid and metadata
        self._lon_out = np.asarray(ds_out['lon'])
        self._lat_out = np.asarray(ds_out['lat'])

        if self._lon_out.ndim == 2:
            try:
                self.lon_dim = self.lat_dim = ds_out['lon'].dims
            except:
                self.lon_dim = self.lat_dim = ('y', 'x')

            self.out_horiz_dims = self.lon_dim

        elif self._lon_out.ndim == 1:
            try:
                self.lon_dim, = ds_out['lon'].dims
                self.lat_dim, = ds_out['lat'].dims
            except:
                self.lon_dim = 'lon'
                self.lat_dim = 'lat'

            self.out_horiz_dims = (self.lat_dim, self.lon_dim)

        # record grid shape information
        self.shape_in = shape_in
        self.shape_out = shape_out
        self.n_in = shape_in[0] * shape_in[1]
        self.n_out = shape_out[0] * shape_out[1]

        if filename is None:
            self.filename = self._get_default_filename()
        else:
            self.filename = filename

        # get weight matrix
        self._write_weight_file()
        self.weights = read_weights(self.filename, self.n_in, self.n_out)
def __init__ ( self , ds_in , ds_out , method , periodic = False , filename = None , reuse_weights = False , ignore_degenerate = None , locstream_in = False , locstream_out = False ) : # record basic switches if method == 'conservative' : self . need_bounds = True periodic = False # bound shape will not be N+1 for periodic grid else : self . need_bounds = False self . method = method self . periodic = periodic self . reuse_weights = reuse_weights self . ignore_degenerate = ignore_degenerate self . locstream_in = locstream_in self . locstream_out = locstream_out methods_avail_ls_in = [ 'nearest_s2d' , 'nearest_d2s' ] methods_avail_ls_out = [ 'bilinear' , 'patch' ] + methods_avail_ls_in if locstream_in and self . method not in methods_avail_ls_in : raise ValueError ( f'locstream input is only available for method in {methods_avail_ls_in}' ) if locstream_out and self . method not in methods_avail_ls_out : raise ValueError ( f'locstream output is only available for method in {methods_avail_ls_out}' ) # construct ESMF grid, with some shape checking if locstream_in : self . _grid_in , shape_in = ds_to_ESMFlocstream ( ds_in ) else : self . _grid_in , shape_in = ds_to_ESMFgrid ( ds_in , need_bounds = self . need_bounds , periodic = periodic ) if locstream_out : self . _grid_out , shape_out = ds_to_ESMFlocstream ( ds_out ) else : self . _grid_out , shape_out = ds_to_ESMFgrid ( ds_out , need_bounds = self . need_bounds ) # record output grid and metadata self . _lon_out = np . asarray ( ds_out [ 'lon' ] ) self . _lat_out = np . asarray ( ds_out [ 'lat' ] ) if self . _lon_out . ndim == 2 : try : self . lon_dim = self . lat_dim = ds_out [ 'lon' ] . dims except : self . lon_dim = self . lat_dim = ( 'y' , 'x' ) self . out_horiz_dims = self . lon_dim elif self . _lon_out . ndim == 1 : try : self . lon_dim , = ds_out [ 'lon' ] . dims self . lat_dim , = ds_out [ 'lat' ] . dims except : self . lon_dim = 'lon' self . lat_dim = 'lat' self . out_horiz_dims = ( self . lat_dim , self . lon_dim ) # record grid shape information self . shape_in = shape_in self . shape_out = shape_out self . n_in = shape_in [ 0 ] * shape_in [ 1 ] self . n_out = shape_out [ 0 ] * shape_out [ 1 ] if filename is None : self . filename = self . _get_default_filename ( ) else : self . filename = filename # get weight matrix self . _write_weight_file ( ) self . weights = read_weights ( self . filename , self . n_in , self . n_out )