(filename, n_in, n_out)
return weights
Read regridding weights into a scipy sparse COO matrix.

    Parameters
    ----------
    filename : str
        Offline weight file generated by ESMPy.

    N_in, N_out : integers
        ``(N_out, N_in)`` will be the shape of the returning sparse matrix.
        They are the total number of grid boxes in input and output grids::

              N_in = Nx_in * Ny_in
              N_out = Nx_out * Ny_out

        We need them because the shape cannot always be infered from the
        largest column and row indices, due to unmapped grid boxes.

    Returns
    -------
    A : scipy sparse COO matrix.
Read regridding weights into a scipy sparse COO matrix.
Read regridding weights into a scipy sparse COO matrix .
def read_weights(filename, n_in, n_out):
    '''
    Read regridding weights into a scipy sparse COO matrix.

    Parameters
    ----------
    filename : str
        Offline weight file generated by ESMPy.

    N_in, N_out : integers
        ``(N_out, N_in)`` will be the shape of the returning sparse matrix.
        They are the total number of grid boxes in input and output grids::

              N_in = Nx_in * Ny_in
              N_out = Nx_out * Ny_out

        We need them because the shape cannot always be infered from the
        largest column and row indices, due to unmapped grid boxes.

    Returns
    -------
    A : scipy sparse COO matrix.

    '''
    ds_w = xr.open_dataset(filename)

    col = ds_w['col'].values - 1  # Python starts with 0
    row = ds_w['row'].values - 1
    S = ds_w['S'].values

    weights = sps.coo_matrix((S, (row, col)), shape=[n_out, n_in])
    return weights
def read_weights ( filename , n_in , n_out ) : ds_w = xr . open_dataset ( filename ) col = ds_w [ 'col' ] . values - 1 # Python starts with 0 row = ds_w [ 'row' ] . values - 1 S = ds_w [ 'S' ] . values weights = sps . coo_matrix ( ( S , ( row , col ) ) , shape = [ n_out , n_in ] ) return weights