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

Function test_trirefine

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

Source from the content-addressed store, hash-verified

1016
1017
1018def test_trirefine():
1019 # Testing subdiv=2 refinement
1020 n = 3
1021 subdiv = 2
1022 x = np.linspace(-1., 1., n+1)
1023 x, y = np.meshgrid(x, x)
1024 x = x.ravel()
1025 y = y.ravel()
1026 mask = np.zeros(2*n**2, dtype=bool)
1027 mask[n**2:] = True
1028 triang = mtri.Triangulation(x, y, triangles=meshgrid_triangles(n+1),
1029 mask=mask)
1030 refiner = mtri.UniformTriRefiner(triang)
1031 refi_triang = refiner.refine_triangulation(subdiv=subdiv)
1032 x_refi = refi_triang.x
1033 y_refi = refi_triang.y
1034
1035 n_refi = n * subdiv**2
1036 x_verif = np.linspace(-1., 1., n_refi+1)
1037 x_verif, y_verif = np.meshgrid(x_verif, x_verif)
1038 x_verif = x_verif.ravel()
1039 y_verif = y_verif.ravel()
1040 ind1d = np.isin(np.around(x_verif*(2.5+y_verif), 8),
1041 np.around(x_refi*(2.5+y_refi), 8))
1042 assert_array_equal(ind1d, True)
1043
1044 # Testing the mask of the refined triangulation
1045 refi_mask = refi_triang.mask
1046 refi_tri_barycenter_x = np.sum(refi_triang.x[refi_triang.triangles],
1047 axis=1) / 3.
1048 refi_tri_barycenter_y = np.sum(refi_triang.y[refi_triang.triangles],
1049 axis=1) / 3.
1050 tri_finder = triang.get_trifinder()
1051 refi_tri_indices = tri_finder(refi_tri_barycenter_x,
1052 refi_tri_barycenter_y)
1053 refi_tri_mask = triang.mask[refi_tri_indices]
1054 assert_array_equal(refi_mask, refi_tri_mask)
1055
1056 # Testing that the numbering of triangles does not change the
1057 # interpolation result.
1058 x = np.asarray([0.0, 1.0, 0.0, 1.0])
1059 y = np.asarray([0.0, 0.0, 1.0, 1.0])
1060 triang = [mtri.Triangulation(x, y, [[0, 1, 3], [3, 2, 0]]),
1061 mtri.Triangulation(x, y, [[0, 1, 3], [2, 0, 3]])]
1062 z = np.hypot(x - 0.3, y - 0.4)
1063 # Refining the 2 triangulations and reordering the points
1064 xyz_data = []
1065 for i in range(2):
1066 refiner = mtri.UniformTriRefiner(triang[i])
1067 refined_triang, refined_z = refiner.refine_field(z, subdiv=1)
1068 xyz = np.dstack((refined_triang.x, refined_triang.y, refined_z))[0]
1069 xyz = xyz[np.lexsort((xyz[:, 1], xyz[:, 0]))]
1070 xyz_data += [xyz]
1071 assert_array_almost_equal(xyz_data[0], xyz_data[1])
1072
1073
1074@pytest.mark.parametrize('interpolator',

Callers

nothing calls this directly

Calls 4

refine_triangulationMethod · 0.95
get_trifinderMethod · 0.95
refine_fieldMethod · 0.95
meshgrid_trianglesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…