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

Mon Oct 5 03:01:02 CDT 2009

```Hi, did you send this to the list because you want to add it to the docs
(like here http://docs.scipy.org/doc/scipy/reference/tutorial/ndimage.html)
?

case go to http://docs.scipy.org/numpy/accounts/register/ and let us know

Cheers,
Ralf

On Fri, Oct 2, 2009 at 6:52 PM, denis <denis-bz-gg@t-online.de> wrote:

> 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.
>
>
> 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
> .
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20091005/57484889/attachment.html
```