API reference

convinterp

Every entry below is the docstring of the installed package, printed at render time, so this page is as current as the version the site was rendered against (shown on the Python page).

Functions

convolution_interpolation

Interpolate data on a uniform grid in any number of dimensions, or differentiate or integrate it.

Parameters

  • knots (array_like, or tuple of array_like): For 1D data, the uniformly spaced, increasing knots. For N-D data, a tuple of N such arrays, one per axis of values.
  • values (array_like): The data at the knots: a 1D array, or an N-D array whose axis d runs along knots[d].
  • kernel (str, default “auto”): The interpolation kernel: “a0” (nearest neighbour), “a1” (linear), “a3”, “a4”, “a5”, “a7”, or the high-order kernels “b5”, “b7”, “b9”, “b11”, “b13”. “auto” chooses by the number of dimensions N, as the Julia package does: “b7” for N ≤ 2, “b5” for N = 3, “a4” for N = 4 and 5, “a3” beyond (a stencil has (2·eqs)^N coefficients, so higher dimensions use narrower kernels).
  • bc (str, (str, str), or sequence of (str, str), default “detect”): Boundary conditions: one for every boundary, one (left, right) pair for every axis, or one (left, right) pair per axis. Each is “poly” (polynomial extrapolation), “linear”, “quadratic”, or “detect” (polynomial where the data allow it, otherwise linear).
  • derivative (int or sequence of int, default 0): Derivative order: one order for every axis, or one per axis. 0 is the interpolant itself, 1 its first derivative, and so on. A negative order −m is the m-fold integral along that axis, anchored at the axis’s first knot: it is zero there, and so are all lower integrals. Orders can be mixed across axes, e.g. (-1, 1) integrates along the first axis and differentiates along the second. Derivatives are available up to order 1 for “a3” to “a7”, 3 for “b5”, 5 for “b7”, 6 for “b9” and 7 for “b11” and “b13”; integrals up to order 2 for “a0” and “a1”, 4 for “a3” to “a7”, 6 for “b5” and 8 for “b7” to “b13”. In N-D, integrals precompute tables of (Π_d (1 + m_d) − 1) times the size of the data, over the integral orders m_d; above 2 GiB a ValueError is raised.

Returns

  • Interpolation: Call it with one coordinate per axis, inside the data range: numbers, or arrays that broadcast against each other.

Example

>>> import numpy as np
>>> from convinterp import convolution_interpolation
>>> x = np.linspace(0.0, 2 * np.pi, 50)                            # uniform grid
>>> itp = convolution_interpolation(x, np.sin(x))                  # interpolant of the data
>>> round(itp(1.0), 6)                                             # sin(1)
0.841471
>>> d_itp = convolution_interpolation(x, np.sin(x), derivative=1)  # its first derivative
>>> round(d_itp(1.0), 6)                                           # cos(1)
0.540302
>>> i_itp = convolution_interpolation(x, np.sin(x), derivative=-1) # its integral from x[0] = 0
>>> round(i_itp(1.0), 6)                                           # 1 − cos(1)
0.459698
>>> y = np.linspace(0.0, 1.0, 30)                                  # a second axis
>>> data = np.sin(x)[:, None] * np.exp(y)[None, :]                 # data on the 2D grid
>>> itp2 = convolution_interpolation((x, y), data)                 # 2D interpolant
>>> round(itp2(1.0, 0.5), 6)                                       # sin(1)·exp(0.5)
1.387351
>>> dxy = convolution_interpolation((x, y), data, derivative=(1, 1))  # ∂²/∂x∂y
>>> round(dxy(1.0, 0.5), 6)                                        # cos(1)·exp(0.5)
0.890808
>>> ixy = convolution_interpolation((x, y), data, derivative=(-1, -1))  # ∫∫ from (0, 0)
>>> round(ixy(1.0, 0.5), 6)                                        # (1 − cos(1))·(exp(0.5) − 1)
0.298216

Types

Interpolation

A convolution interpolant. Call it with one coordinate per axis: numbers or arrays.

Create one with convolution_interpolation.