Interpolation is a used for many astronomical applications. Interpolation is required to combine sub-pixel dithered images or spectroscopy, sample grids of stellar evolution or stellar atmosphere models, calculate extinction from observed extinction curves, and many many more applications. The scipy.interpolate package in python has some nice built-in interpolation functions and I have gathered a few links describing the capabilities (in addition to the documentation). I would recommend using splrep/splev over interp1d for speed.
- Scipy cookbook on interpolation
- A slideshow outlining the interpolation capabilities in Scipy
- A thread explaining terms in spline interpolation/smoothing
Within Scipy, there is an integrate package with several different functions that perform definite or indefinite integrals. I have only played with these briefly; however, I tested both the scipy.integrate.quad() and scipy.integrate.romberg() functions. These all work in roughly the same way by taking a user-defined function, and the upper and lower boundaries of the integral. Here is a brief example:
from scipy import integrate def myfunc(x, a, b): return (x**b) + a # These are the arguments that will be passed as a and b to myfunc() args = (1.0, -2.0) # Integrate myfunc() from 0.5 to 1.5 results = integrate.quad(myfunc, 0.5, 1.5, args) print 'Integral = ', results, ' with error = ', results
The well-established Fortran QUADPACK integration code lies underneath quad() while romberg() appears to be a python only implementation (??). While I would much rather use quad() for its robustness, it only supports user-functions that accept single value floats; while romberg() will pass in vectors of values. For some of my applications, myfunc() is computationally intensive, so there is an order of magnitude speed gain by having a properly vectorized myfunc() used in vector-form by the integration code. Only with romberg() have I matched the speed of IDL’s qpint1d (from Markwardt library, also based on QUADPACK, but vectorized) for identical myfunc().