def interpolate_nearest ( self , xi , yi , zdata ) : if zdata . size != self . npoints : raise ValueError ( 'zdata should be same size as mesh' ) zdata = self . _shuffle_field ( zdata ) ist = np . ones_like ( xi , dtype = np . int32 ) ist , dist = _tripack . nearnds ( xi , yi , ist , self . _x , self . _y , self . lst , self . lptr , self . lend ) return zdata [ ist - 1 ]
nearest neighbor interpolation code in python
Nearest - neighbour interpolation . Calls nearnd to find the index of the closest neighbours to xi yi
def interpolate_nearest(self, xi, yi, zdata):
        """
        Nearest-neighbour interpolation.
        Calls nearnd to find the index of the closest neighbours to xi,yi

        Parameters
        ----------
         xi : float / array of floats, shape (l,)
            x coordinates on the Cartesian plane
         yi : float / array of floats, shape (l,)
            y coordinates on the Cartesian plane

        Returns
        -------
         zi : float / array of floats, shape (l,)
            nearest-neighbour interpolated value(s) of (xi,yi)
        """
        if zdata.size != self.npoints:
            raise ValueError('zdata should be same size as mesh')

        zdata = self._shuffle_field(zdata)

        ist = np.ones_like(xi, dtype=np.int32)
        ist, dist = _tripack.nearnds(xi, yi, ist, self._x, self._y,
                                     self.lst, self.lptr, self.lend)
        return zdata[ist - 1]