()
| 426 | |
| 427 | |
| 428 | def test_triinterp(): |
| 429 | # Test points within triangles of masked triangulation. |
| 430 | x, y = np.meshgrid(np.arange(4), np.arange(4)) |
| 431 | x = x.ravel() |
| 432 | y = y.ravel() |
| 433 | z = 1.23*x - 4.79*y |
| 434 | triangles = [[0, 1, 4], [1, 5, 4], [1, 2, 5], [2, 6, 5], [2, 3, 6], |
| 435 | [3, 7, 6], [4, 5, 8], [5, 9, 8], [5, 6, 9], [6, 10, 9], |
| 436 | [6, 7, 10], [7, 11, 10], [8, 9, 12], [9, 13, 12], [9, 10, 13], |
| 437 | [10, 14, 13], [10, 11, 14], [11, 15, 14]] |
| 438 | mask = np.zeros(len(triangles)) |
| 439 | mask[8:10] = 1 |
| 440 | triang = mtri.Triangulation(x, y, triangles, mask) |
| 441 | linear_interp = mtri.LinearTriInterpolator(triang, z) |
| 442 | cubic_min_E = mtri.CubicTriInterpolator(triang, z) |
| 443 | cubic_geom = mtri.CubicTriInterpolator(triang, z, kind='geom') |
| 444 | |
| 445 | xs = np.linspace(0.25, 2.75, 6) |
| 446 | ys = [0.25, 0.75, 2.25, 2.75] |
| 447 | xs, ys = np.meshgrid(xs, ys) # Testing arrays with array.ndim = 2 |
| 448 | for interp in (linear_interp, cubic_min_E, cubic_geom): |
| 449 | zs = interp(xs, ys) |
| 450 | assert_array_almost_equal(zs, (1.23*xs - 4.79*ys)) |
| 451 | |
| 452 | # Test points outside triangulation. |
| 453 | xs = [-0.25, 1.25, 1.75, 3.25] |
| 454 | ys = xs |
| 455 | xs, ys = np.meshgrid(xs, ys) |
| 456 | for interp in (linear_interp, cubic_min_E, cubic_geom): |
| 457 | zs = linear_interp(xs, ys) |
| 458 | assert_array_equal(zs.mask, [[True]*4]*4) |
| 459 | |
| 460 | # Test mixed configuration (outside / inside). |
| 461 | xs = np.linspace(0.25, 1.75, 6) |
| 462 | ys = [0.25, 0.75, 1.25, 1.75] |
| 463 | xs, ys = np.meshgrid(xs, ys) |
| 464 | for interp in (linear_interp, cubic_min_E, cubic_geom): |
| 465 | zs = interp(xs, ys) |
| 466 | matest.assert_array_almost_equal(zs, (1.23*xs - 4.79*ys)) |
| 467 | mask = (xs >= 1) * (xs <= 2) * (ys >= 1) * (ys <= 2) |
| 468 | assert_array_equal(zs.mask, mask) |
| 469 | |
| 470 | # 2nd order patch test: on a grid with an 'arbitrary shaped' triangle, |
| 471 | # patch test shall be exact for quadratic functions and cubic |
| 472 | # interpolator if *kind* = user |
| 473 | (a, b, c) = (1.23, -4.79, 0.6) |
| 474 | |
| 475 | def quad(x, y): |
| 476 | return a*(x-0.5)**2 + b*(y-0.5)**2 + c*x*y |
| 477 | |
| 478 | def gradient_quad(x, y): |
| 479 | return (2*a*(x-0.5) + c*y, 2*b*(y-0.5) + c*x) |
| 480 | |
| 481 | x = np.array([0.2, 0.33367, 0.669, 0., 1., 1., 0.]) |
| 482 | y = np.array([0.3, 0.80755, 0.4335, 0., 0., 1., 1.]) |
| 483 | triangles = np.array([[0, 1, 2], [3, 0, 4], [4, 0, 2], [4, 2, 5], |
| 484 | [1, 5, 2], [6, 5, 1], [6, 1, 0], [6, 0, 3]]) |
| 485 | triang = mtri.Triangulation(x, y, triangles) |
nothing calls this directly
no test coverage detected
searching dependent graphs…