[SciPy-User] a small example of scipy.ndimage.map_coordinates

denis denis-bz-gg@t-online...
Fri Oct 2 11:52:18 CDT 2009


Folks,
  here is a small tutorial example of scipy.ndimage.map_coordinates:

Say Cities is an n x 2 array of [latitide,longitude] coordinates, like
    Paris = [48.9, 2.4]
    Rome = [41.9, 12.5]
    Greenwich = [51.5, 0]
    Cities = np.array([ Paris, Rome, Greenwich ])

and A is a 91 x 360 array of temperatures at integer [lat,long] --
A[0] along the equator, A[:,0] along the prime meridian through
Greenwich.
Then
................................................................................
    z = scipy.ndimage.map_coordinates( A, Cities.T, order=order )
................................................................................

is the 3 temperatures at Paris, Rome and Greenwich -- approximately,
depending on order.
The transpose Cities.T is used because map_coordinates takes columns,
not rows.
("RuntimeError: invalid shape for coordinate array"
may mean that you forgot the .T .)

If order is 0, map_coordinates rounds [lat,long] to the nearest
integers: the temperature at Paris is approximated by A[50,2].
If 1, it does bilinear interpolation in the square with corners
A[48,2], A[48,3], A[49,2], A[49,3] for Paris.
If 2, it does quadratic interpolation over the 9 points A[48:51, 1:4].
And so on, up to order 5; the default is order=3 (Catmull-Rom ?)
Order 1, bilinear, is much faster than 2 or 3.

What happens to A[51,-1] etc. west of Greenwich ?  See the mode=
option.

Of course the values in A may be arrays -- colors, sounds, anything
that can be blended or interpolated -- not just scalars.

Links:

http://docs.scipy.org/doc/scipy/reference/tutorial/ndimage.html
http://www.scipy.org/Cookbook/Interpolation
http://en.wikipedia.org/wiki/Multivariate_interpolation ff.

For an introduction to interpolation methods, see ... NR ?

For the reverse problem of turning scattered data to a regular grid,
see
http://matplotlib.sourceforge.net/api/mlab_api.html#matplotlib.mlab.griddata
.


More information about the SciPy-User mailing list