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

Function test_triinterp_colinear

lib/matplotlib/tests/test_triangulation.py:713–772  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

711
712
713def test_triinterp_colinear():
714 # Tests interpolating inside a triangulation with horizontal colinear
715 # points (refer also to the tests :func:`test_trifinder` ).
716 #
717 # These are not valid triangulations, but we try to deal with the
718 # simplest violations (i. e. those handled by default TriFinder).
719 #
720 # Note that the LinearTriInterpolator and the CubicTriInterpolator with
721 # kind='min_E' or 'geom' still pass a linear patch test.
722 # We also test interpolation inside a flat triangle, by forcing
723 # *tri_index* in a call to :meth:`_interpolate_multikeys`.
724
725 # If +ve, triangulation is OK, if -ve triangulation invalid,
726 # if zero have colinear points but should pass tests anyway.
727 delta = 0.
728
729 x0 = np.array([1.5, 0, 1, 2, 3, 1.5, 1.5])
730 y0 = np.array([-1, 0, 0, 0, 0, delta, 1])
731
732 # We test different affine transformations of the initial figure; to
733 # avoid issues related to round-off errors we only use integer
734 # coefficients (otherwise the Triangulation might become invalid even with
735 # delta == 0).
736 transformations = [[1, 0], [0, 1], [1, 1], [1, 2], [-2, -1], [-2, 1]]
737 for transformation in transformations:
738 x_rot = transformation[0]*x0 + transformation[1]*y0
739 y_rot = -transformation[1]*x0 + transformation[0]*y0
740 (x, y) = (x_rot, y_rot)
741 z = 1.23*x - 4.79*y
742 triangles = [[0, 2, 1], [0, 3, 2], [0, 4, 3], [1, 2, 5], [2, 3, 5],
743 [3, 4, 5], [1, 5, 6], [4, 6, 5]]
744 triang = mtri.Triangulation(x, y, triangles)
745 xs = np.linspace(np.min(triang.x), np.max(triang.x), 20)
746 ys = np.linspace(np.min(triang.y), np.max(triang.y), 20)
747 xs, ys = np.meshgrid(xs, ys)
748 xs = xs.ravel()
749 ys = ys.ravel()
750 mask_out = (triang.get_trifinder()(xs, ys) == -1)
751 zs_target = np.ma.array(1.23*xs - 4.79*ys, mask=mask_out)
752
753 linear_interp = mtri.LinearTriInterpolator(triang, z)
754 cubic_min_E = mtri.CubicTriInterpolator(triang, z)
755 cubic_geom = mtri.CubicTriInterpolator(triang, z, kind='geom')
756
757 for interp in (linear_interp, cubic_min_E, cubic_geom):
758 zs = interp(xs, ys)
759 assert_array_almost_equal(zs_target, zs)
760
761 # Testing interpolation inside the flat triangle number 4: [2, 3, 5]
762 # by imposing *tri_index* in a call to :meth:`_interpolate_multikeys`
763 itri = 4
764 pt1 = triang.triangles[itri, 0]
765 pt2 = triang.triangles[itri, 1]
766 xs = np.linspace(triang.x[pt1], triang.x[pt2], 10)
767 ys = np.linspace(triang.y[pt1], triang.y[pt2], 10)
768 zs_target = 1.23*xs - 4.79*ys
769 for interp in (linear_interp, cubic_min_E, cubic_geom):
770 zs, = interp._interpolate_multikeys(

Callers

nothing calls this directly

Calls 4

get_trifinderMethod · 0.95
minMethod · 0.80
maxMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…