Equivalent of map_coordinates in Julia

Is someone aware of a Julia equivalent of the Python function scipy.ndimage.map_coordinates? I’ve looked at Interpolations.jl but couldn’t find this exact feature.

In order to port a code from Python to Julia I need this feature, I’d like to avoid duplicating work if it has been already implemented. Or maybe someone is willing to contribute it :slight_smile:

You get it by composition of other functionality (because the task you’re trying to solve is “just” interpolation). Create your input array as an array of SVector (from StaticArrays) and then use Interpolations.


Thanks for the reply, however I’m not sure I got what you mean. Could you please show how to translate the example at scipy.ndimage.map_coordinates — SciPy v0.19.1 Reference Guide? Here it is for reference:

>>> import numpy as np
>>> from scipy import ndimage
>>> a = np.arange(12.).reshape((4, 3))
>>> a
array([[  0.,   1.,   2.],
       [  3.,   4.,   5.],
       [  6.,   7.,   8.],
       [  9.,  10.,  11.]])
>>> ndimage.map_coordinates(a, [[0.5, 2], [0.5, 1]], order=1)
array([ 2.,  7.])

I think my problem is understanding what exactly the Python code does :slight_smile:

Ok, I managed at least to reproduce the example with this code:

using Interpolations

function map_coordinates(input, coordinates::AbstractArray{<:AbstractArray{T}, N}) where {T, N}
    output = Array{T,N}(size(coordinates))
    for (i, coord) in enumerate(coordinates)
        output[i] = interpolate(input, BSpline(Linear()), OnCell())[coord[1] + 1, coord[2] + 1]
    return output

Example (note that the second argument is slightly different from the Python version):

julia> map_coordinates(reshape(0:11, 3, 4)', [[0.5, 0.5], [2, 1]])
2-element Array{Float64,1}:

Of course this doesn’t completely match all features of map_coordinates but can be a starting point.