File: interpolate.rst

package info (click to toggle)
scipy 1.16.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 236,088 kB
  • sloc: cpp: 503,720; python: 345,302; ansic: 195,677; javascript: 89,566; fortran: 56,210; cs: 3,081; f90: 1,150; sh: 857; makefile: 771; pascal: 284; csh: 135; lisp: 134; xml: 56; perl: 51
file content (92 lines) | stat: -rw-r--r-- 7,347 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
.. _tutorial-interpolate:

========================================
Interpolation (:mod:`scipy.interpolate`)
========================================

.. sectionauthor:: Travis E. Oliphant

.. sectionauthor:: Pauli Virtanen

.. sectionauthor:: Evgeni Burovski

.. currentmodule:: scipy.interpolate


There are several general facilities available in SciPy for interpolation and
smoothing for data in 1, 2, and higher dimensions. The choice of a specific
interpolation routine depends on the data: whether it is one-dimensional,
is given on a structured grid, or is unstructured. One other factor is the
desired smoothness of the interpolator. In short, routines recommended *for
interpolation* can be summarized as follows:

+------------------+-------------------------+------------------------------+------------------------+---------------------------------------+
|                  | **kind**                | **routine**                  | **continuity**         | **comment**                           |
+==================+=========================+==============================+========================+=======================================+
|                  | linear                  | `numpy.interp`               | piecewise continuous   | Alternatively,                        |
|                  |                         |                              |                        | ``make_interp_spline(..., k=1)``      |
+                  +-------------------------+------------------------------+------------------------+---------------------------------------+
|                  | cubic spline            | `CubicSpline`                | 2nd derivative         |                                       |
+                  +-------------------------+------------------------------+------------------------+---------------------------------------+
|       1D         | monotone cubic spline   | `PchipInterpolator`          | 1st derivative         | non-overshooting                      |
+                  +-------------------------+------------------------------+------------------------+---------------------------------------+
|                  | non-cubic spline        | `make_interp_spline`         | (k-1)th derivative     | ``k=3`` is equivalent to `CubicSpline`|
+                  +-------------------------+------------------------------+------------------------+---------------------------------------+
|                  | nearest                 | `interp1d`                   |                        | kind='nearest', 'previous', 'next'    |
+------------------+-------------------------+------------------------------+------------------------+---------------------------------------+
| N-D curve        | nearest, linear, spline | `make_interp_spline`         | (k-1)th derivative     | use N-dim `y` array                   |
+------------------+-------------------------+------------------------------+------------------------+---------------------------------------+
|                  | nearest                 |                              |                        |  method='nearest'                     |
+                  +-------------------------+                              +                        +---------------------------------------+
| N-D regular      | linear                  | `RegularGridInterpolator`    |                        |  method='linear'                      |
+ (*rectilinear*)  +-------------------------+                              +------------------------+---------------------------------------+
| grid             | splines                 |                              | 2nd derivatives        |  method='cubic', 'quintic'            |
+                  +-------------------------+                              +------------------------+---------------------------------------+
|                  | monotone splines        |                              | 1st derivatives        |  method='pchip'                       |
+------------------+-------------------------+------------------------------+------------------------+---------------------------------------+
|                  | nearest                 | `NearestNDInterpolator`      |                        |                                       |
+                  +-------------------------+------------------------------+                        +                                       +
|  N-D scattered   | linear                  | `LinearNDInterpolator`       |                        | alias: `griddata`                     |
+                  +-------------------------+------------------------------+------------------------+                                       +
|                  | cubic (2D only)         | `CloughTocher2DInterpolator` | 1st derivatives        |                                       |
+                  +-------------------------+------------------------------+------------------------+---------------------------------------+
|                  | radial basis function   | `RBFInterpolator`            |                        |                                       |
+------------------+-------------------------+------------------------------+------------------------+---------------------------------------+


Smoothing and approximation of data
===================================

+-------------------------------+-------------------------+-------------------------------+
|                               | `make_smoothing_spline` |  classic smoothing splines,   |
|                               |                         |  GCV penalty                  |
| 1D spline functions           +-------------------------+-------------------------------+
|                               | `make_splrep`           | automated/semi-automated knot |
|                               |                         | selection                     |
+-------------------------------+-------------------------+-------------------------------+
| spine curves in N-D           | `make_splprep`          |                               |
+-------------------------------+-------------------------+-------------------------------+
| unconstrained least squares   | `make_lsq_spline`       |                               |
| spline fit                    |                         |                               |
+-------------------------------+-------------------------+-------------------------------+
| 2D smoothing surfaces         | `bisplrep`              | scattered data                |
+-------------------------------+-------------------------+-------------------------------+
|                               | `RectBivariateSpline`   | gridded data                  |
+-------------------------------+-------------------------+-------------------------------+
| Radial basis functions in N-D | `RBFInterpolator`       |                               |
+-------------------------------+-------------------------+-------------------------------+


**Further details are given in the links below**


.. toctree::
   :maxdepth: 3

   interpolate/1D
   interpolate/splines_and_polynomials
   interpolate/smoothing_splines
   interpolate/ND_regular_grid
   interpolate/ND_unstructured
   interpolate/extrapolation_examples
   interpolate/interp_transition_guide.md