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

Ralf Gommers ralf.gommers at googlemail.com
Tue Oct 6 15:49:40 EDT 2009


First a general comment: the example code should be self-contained so the
reader can execute all lines and get the correct result.

Also, try to write docs as reStructuredText immediately, because that is the
form in which it has to end up eventually.

On Fri, Oct 2, 2009 at 6:52 PM, denis <denis-bz-gg at 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] --
>

Why 91 and not 90? A should be defined in code, and a more descriptive name
would be nice.


> A[0] along the equator, A[:,0] along the prime meridian through
> Greenwich.
>

I'd write A[0] as A[0, :], more explicit.


> Then
>
> ................................................................................
>    z = scipy.ndimage.map_coordinates( A, Cities.T, order=order )
>
> ................................................................................
>
`order` is not defined.

>
> 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 .)
>

Would leave out the RuntimeError. The sentence before is clear enough.

>
> 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.
>
> Spline interpolation is used, I would mention this explicitly. Not sure if
it is Catmull-Rom.


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

If you ask the reader a question, why not answer it? This would annoy me.

>
> Of course the values in A may be arrays -- colors, sounds, anything
> that can be blended or interpolated -- not just scalars.
>
> This needs example code, otherwise the reader will be confused. Using a 3-D
instead of 2-D array will not work.


> 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 ?
>
> Sure, NR is fine.


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

Cheers,
Ralf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20091006/7d5843ec/attachment.html>


More information about the SciPy-User mailing list