code: def interpgrid(a, xi, yi):
      """Fast 2D, linear interpolation on an integer grid"""
  
      Ny, Nx = np.shape(a)
      if isinstance(xi, np.ndarray):
          x = xi.astype(int)
          y = yi.astype(int)
          # Check that xn, yn don't exceed max index
          xn = np.clip(x + 1, 0, Nx - 1)
          yn = np.clip(y + 1, 0, Ny - 1)
      else:
          x = int(xi)
          y = int(yi)
          # conditional is faster than clipping for integers
          if x == (Nx - 2):
              xn = x
          else:
              xn = x + 1
          if y == (Ny - 2):
              yn = y
          else:
              yn = y + 1
  
      a00 = a[y, x]
      a01 = a[y, xn]
      a10 = a[yn, x]
      a11 = a[yn, xn]
      xt = xi - x
      yt = yi - y
      a0 = a00 * (1 - xt) + a01 * xt
      a1 = a10 * (1 - xt) + a11 * xt
      ai = a0 * (1 - yt) + a1 * yt
  
      if not isinstance(xi, np.ndarray):
          if np.ma.is_masked(ai):
              raise TerminateTrajectory
  
      return ai
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import six
  from six.moves import xrange
  import numpy
  import matplotlib
  import matplotlib.cm
  import matplotlib.colors
  import matplotlib.collections
  import matplotlib.lines
  import matplotlib.patches
label_desc: Use image node_id 5 for calling a global function with example usage: interpgrid(a, xi, yi) and returns: ai