matplotlib.tri._triinterpolate

Interpolation inside triangular grids.

Classes

class matplotlib.tri._triinterpolate.TriInterpolator(triangulation, z, trifinder=None)

Abstract base class for classes used to interpolate on a triangular grid.

Derived classes implement the following methods:

  • __call__(x, y), where x, y are array-like point coordinates of the same shape, and that returns a masked array of the same shape containing the interpolated z-values.

  • gradient(x, y), where x, y are array-like point coordinates of the same shape, and that returns a list of 2 masked arrays of the same shape containing the 2 derivatives of the interpolator (derivatives of interpolated z values with respect to x and y).

Inheritance

digraph inheritanceb71282bcf6 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "TriInterpolator" [URL="#matplotlib.tri._triinterpolate.TriInterpolator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Abstract base class for classes used to interpolate on a triangular grid."]; }
class matplotlib.tri._triinterpolate.LinearTriInterpolator(triangulation, z, trifinder=None)

Linear interpolator on a triangular grid.

Each triangle is represented by a plane so that an interpolated value at point (x, y) lies on the plane of the triangle containing (x, y). Interpolated values are therefore continuous across the triangulation, but their first derivatives are discontinuous at edges between triangles.

Parameters:
  • triangulation (~matplotlib.tri.Triangulation) – The triangulation to interpolate over.

  • z ((npoints,) array-like) – Array of values, defined at grid points, to interpolate between.

  • trifinder (~matplotlib.tri.TriFinder, optional) – If this is not specified, the Triangulation’s default TriFinder will be used by calling .Triangulation.get_trifinder.

`__call__` (x, y) : Returns interpolated values at (x, y) points.
`gradient` (x, y) : Returns interpolated derivatives at (x, y) points.

Inheritance

digraph inheritancead09dc6577 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "LinearTriInterpolator" [URL="#matplotlib.tri._triinterpolate.LinearTriInterpolator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Linear interpolator on a triangular grid."]; "TriInterpolator" -> "LinearTriInterpolator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TriInterpolator" [URL="#matplotlib.tri._triinterpolate.TriInterpolator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Abstract base class for classes used to interpolate on a triangular grid."]; }
gradient(x, y)

Returns a list of 2 masked arrays containing interpolated derivatives at the specified (x, y) points.

Parameters:
  • x (array-like) – x and y coordinates of the same shape and any number of dimensions.

  • y (array-like) – x and y coordinates of the same shape and any number of dimensions.

Returns:

dzdx, dzdy – 2 masked arrays of the same shape as x and y; values corresponding to (x, y) points outside of the triangulation are masked out. The first returned array contains the values of \(\frac{\partial z}{\partial x}\) and the second those of \(\frac{\partial z}{\partial y}\).

Return type:

np.ma.array

class matplotlib.tri._triinterpolate.CubicTriInterpolator(triangulation, z, kind='min_E', trifinder=None, dz=None)

Cubic interpolator on a triangular grid.

In one-dimension - on a segment - a cubic interpolating function is defined by the values of the function and its derivative at both ends. This is almost the same in 2D inside a triangle, except that the values of the function and its 2 derivatives have to be defined at each triangle node.

The CubicTriInterpolator takes the value of the function at each node - provided by the user - and internally computes the value of the derivatives, resulting in a smooth interpolation. (As a special feature, the user can also impose the value of the derivatives at each node, but this is not supposed to be the common usage.)

Parameters:
  • triangulation (~matplotlib.tri.Triangulation) – The triangulation to interpolate over.

  • z ((npoints,) array-like) – Array of values, defined at grid points, to interpolate between.

  • kind ({'min_E', 'geom', 'user'}, optional) –

    Choice of the smoothing algorithm, in order to compute the interpolant derivatives (defaults to ‘min_E’):

    • if ‘min_E’: (default) The derivatives at each node is computed to minimize a bending energy.

    • if ‘geom’: The derivatives at each node is computed as a weighted average of relevant triangle normals. To be used for speed optimization (large grids).

    • if ‘user’: The user provides the argument dz, no computation is hence needed.

  • trifinder (~matplotlib.tri.TriFinder, optional) – If not specified, the Triangulation’s default TriFinder will be used by calling .Triangulation.get_trifinder.

  • dz (tuple of array-likes (dzdx, dzdy), optional) – Used only if kind =’user’. In this case dz must be provided as (dzdx, dzdy) where dzdx, dzdy are arrays of the same shape as z and are the interpolant first derivatives at the triangulation points.

`__call__` (x, y) : Returns interpolated values at (x, y) points.
`gradient` (x, y) : Returns interpolated derivatives at (x, y) points.

Notes

This note is a bit technical and details how the cubic interpolation is computed.

The interpolation is based on a Clough-Tocher subdivision scheme of the triangulation mesh (to make it clearer, each triangle of the grid will be divided in 3 child-triangles, and on each child triangle the interpolated function is a cubic polynomial of the 2 coordinates). This technique originates from FEM (Finite Element Method) analysis; the element used is a reduced Hsieh-Clough-Tocher (HCT) element. Its shape functions are described in [1]. The assembled function is guaranteed to be C1-smooth, i.e. it is continuous and its first derivatives are also continuous (this is easy to show inside the triangles but is also true when crossing the edges).

In the default case (kind =’min_E’), the interpolant minimizes a curvature energy on the functional space generated by the HCT element shape functions - with imposed values but arbitrary derivatives at each node. The minimized functional is the integral of the so-called total curvature (implementation based on an algorithm from [2] - PCG sparse solver):

\[E(z) = \frac{1}{2} \int_{\Omega} \left( \left( \frac{\partial^2{z}}{\partial{x}^2} \right)^2 + \left( \frac{\partial^2{z}}{\partial{y}^2} \right)^2 + 2\left( \frac{\partial^2{z}}{\partial{y}\partial{x}} \right)^2 \right) dx\,dy\]

If the case kind =’geom’ is chosen by the user, a simple geometric approximation is used (weighted average of the triangle normal vectors), which could improve speed on very large grids.

References

Inheritance

digraph inheritance3f0b33ddc8 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "CubicTriInterpolator" [URL="#matplotlib.tri._triinterpolate.CubicTriInterpolator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Cubic interpolator on a triangular grid."]; "TriInterpolator" -> "CubicTriInterpolator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TriInterpolator" [URL="#matplotlib.tri._triinterpolate.TriInterpolator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Abstract base class for classes used to interpolate on a triangular grid."]; }
gradient(x, y)

Returns a list of 2 masked arrays containing interpolated derivatives at the specified (x, y) points.

Parameters:
  • x (array-like) – x and y coordinates of the same shape and any number of dimensions.

  • y (array-like) – x and y coordinates of the same shape and any number of dimensions.

Returns:

dzdx, dzdy – 2 masked arrays of the same shape as x and y; values corresponding to (x, y) points outside of the triangulation are masked out. The first returned array contains the values of \(\frac{\partial z}{\partial x}\) and the second those of \(\frac{\partial z}{\partial y}\).

Return type:

np.ma.array