MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / interpgrid

Function interpgrid

lib/matplotlib/streamplot.py:690–727  ·  view source on GitHub ↗

Fast 2D, linear interpolation on an integer grid

(a, xi, yi)

Source from the content-addressed store, hash-verified

688# ========================
689
690def interpgrid(a, xi, yi):
691 """Fast 2D, linear interpolation on an integer grid"""
692
693 Ny, Nx = np.shape(a)
694 if isinstance(xi, np.ndarray):
695 x = xi.astype(int)
696 y = yi.astype(int)
697 # Check that xn, yn don't exceed max index
698 xn = np.clip(x + 1, 0, Nx - 1)
699 yn = np.clip(y + 1, 0, Ny - 1)
700 else:
701 x = int(xi)
702 y = int(yi)
703 # conditional is faster than clipping for integers
704 if x == (Nx - 1):
705 xn = x
706 else:
707 xn = x + 1
708 if y == (Ny - 1):
709 yn = y
710 else:
711 yn = y + 1
712
713 a00 = a[y, x]
714 a01 = a[y, xn]
715 a10 = a[yn, x]
716 a11 = a[yn, xn]
717 xt = xi - x
718 yt = yi - y
719 a0 = a00 * (1 - xt) + a01 * xt
720 a1 = a10 * (1 - xt) + a11 * xt
721 ai = a0 * (1 - yt) + a1 * yt
722
723 if not isinstance(xi, np.ndarray):
724 if np.ma.is_masked(ai):
725 raise TerminateTrajectory
726
727 return ai
728
729
730def _gen_starting_points(shape):

Callers 2

streamplotFunction · 0.85
forward_timeFunction · 0.85

Calls 2

shapeMethod · 0.45
clipMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…