transientskp / pyse

Python Source Extractor
BSD 2-Clause "Simplified" License
11 stars 5 forks source link

Faster interpolation than scipy.ndimage.map_coordinates for the linear case. #14

Closed HannoSpreeuw closed 3 years ago

HannoSpreeuw commented 3 years ago

scipy.ndimage.map_coordinates is used to interpolate the grid values of the background mode and rms to the entire image. Default this is done using bilinear interpolation. For that case much faster solutions are available.

One of the answers to this SO question includes these four lines of code:

    f = interp.interp1d(y, im, kind='linear')
    temp = f(new_y)
    f = interp.interp1d(x, temp.T, kind='linear')
    new_im = f(new_x).T

This is more than three times faster than scipy.ndimage.map_coordinates for linear interpolation. scipy.ndimage.zoom should also be an option for speedup, but even after extensive tweaking of the zoom parameters I could not produce the exact same output as map_coordinates. My bad.

(One might want to retain the option to apply other interpolation orders, I do not see its use, not accommodated for here)