scipy/scipy — pull request #206 by jjhelmus (2012-05-08 21:43:44+00:00)
Title: Map coordinate fix

This pull request address Trac Tickets [#796](http://projects.scipy.org/scipy/ticket/796), [#1378]( http://projects.scipy.org/scipy/ticket/1378) and [#1520]( http://projects.scipy.org/scipy/ticket/1520) which all stem from the map_coordinate function in ni_interpolation.c

As currently written, this pull causes two tests in test_ndimage to fail (boundary modes and boundary modes 2) which is the reason for the long explaination. In these two tests the 'wrap' mode need further clarification. Take a simplified version of the boundary mode test:
```
def shift(x): return (x[0] + 0.5,)
input = numpy.array([2,4,6,8.])
output = ndimage.geometric_transform(input, shift, mode='wrap', output_shape=(5,), order=1)
```
This generates an index mapping to take from the input for the output of [0.5, 1.5, 2.5, 3.5, 4.5]. With "wrap" mode determining what elements these correspond to is difficult.

The first element is well defined, halfway between the first and second elements in input, 2 and 4, so 3.
The second and third elements are also well defined, 5 and 7.

The fourth element has an index of 3.5, but the input only has indices to 3. Currently in scipy this is "wrapped" an index of 0.5, with a value of 3, but this seems incorrect to me. The fourth element in the input has an index of 3, if the data is wrapped (appended before and after the original data as needed) then the first element would have an index of 4. In this sense an index of 3.5 is halfway between the fourth (last) element and the first element and might be represented as -0.5. The problem come when we try to find a value for this element, we need to extrapolate a half point past either the last element or the first element.

The fifth element in the output has an input index of 4.5, which is currently "wrapped" to an index of 1.5 and takes the value of 5. In my mind, if an index of 4 wraps to the first element of the input, then the 4.5 should be between the first and second element of the input, so 3.

So the question becomes should output be:
1). As scipy has it currently so that 3.5 -> 0.5 and 4.5 -> 1.5. output = [3, 5, 7, 3, 5]
2). As in this pull so that 3.5 -> -0.5, 4.5 -> 0.5. output = [3, 5, 7, ?, 3] and then also what should ? be.

I'm in support of 2, but would be happy if someone can convince me that 1 is correct.

As an addition exame, please see what happens to the third element vs. all other elements of output when shift is defined as:
```
def shift(x): return (x[0] + 0.9,)
def shift(x): return (x[0] + 1.0,)
def shift(x): return (x[0] + 1.1,)
```