MCPcopy Create free account
hub / github.com/ColdGrub1384/Pyto / interpgrid

Function interpgrid

site-packages/matplotlib/streamplot.py:592–629  ·  view source on GitHub ↗

Fast 2D, linear interpolation on an integer grid

(a, xi, yi)

Source from the content-addressed store, hash-verified

590# ========================
591
592def interpgrid(a, xi, yi):
593 """Fast 2D, linear interpolation on an integer grid"""
594
595 Ny, Nx = np.shape(a)
596 if isinstance(xi, np.ndarray):
597 x = xi.astype(int)
598 y = yi.astype(int)
599 # Check that xn, yn don't exceed max index
600 xn = np.clip(x + 1, 0, Nx - 1)
601 yn = np.clip(y + 1, 0, Ny - 1)
602 else:
603 x = int(xi)
604 y = int(yi)
605 # conditional is faster than clipping for integers
606 if x == (Nx - 1):
607 xn = x
608 else:
609 xn = x + 1
610 if y == (Ny - 1):
611 yn = y
612 else:
613 yn = y + 1
614
615 a00 = a[y, x]
616 a01 = a[y, xn]
617 a10 = a[yn, x]
618 a11 = a[yn, xn]
619 xt = xi - x
620 yt = yi - y
621 a0 = a00 * (1 - xt) + a01 * xt
622 a1 = a10 * (1 - xt) + a11 * xt
623 ai = a0 * (1 - yt) + a1 * yt
624
625 if not isinstance(xi, np.ndarray):
626 if np.ma.is_masked(ai):
627 raise TerminateTrajectory
628
629 return ai
630
631
632def _gen_starting_points(shape):

Callers 2

streamplotFunction · 0.85
forward_timeFunction · 0.85

Calls 4

clipMethod · 0.80
is_maskedMethod · 0.80
shapeMethod · 0.45
astypeMethod · 0.45

Tested by

no test coverage detected