![]() Points in "xi", "yi", "zi" using linear interpolation. """Sample a 3D array "v" with pixel corner locations at "x","y","z" at the Print interp3(x, y, z, data, xi, yi, -25 * np.ones_like(xi))ĭef interp3(x, y, z, v, xi, yi, zi, **kwargs): # Interpolate a region of the x-y plane at z=-25 ![]() Howver, it should more or less replicate the behavior of interp3 as I remember it (ignoring the "zooming" functionality of interp3(data, zoom_factor), which handles.) import numpy as npįrom scipy.ndimage import map_coordinates I'll try to add more explanation later tonight (this is rather dense code).Īll in all, the interp3 function I have is more complex than it may need to be for your exact purposes. For the code snippet below, I'll assume that you always want floating point output. If you interpolate an integer array, you'll get integer output, which may or may not be what you want. There's also the additional wrinkle that map_coordinates always preserves the dtype of the input array in the output. If you want to specify the interpolated coordinates similar to matlab's interp3, then you'll need to convert your intput coordinates into "index" coordinates. The interface to it seems a bit clunky at first, but it does give you a lot of flexibility. Other than that, the two are similar and equally easy to use.īasically, ndimage.map_coordinates works in "index" coordinates (a.k.a. So you see some slight differences: Scipy uses x,y,z index order while MATLAB uses y,x,z (strangely) In Scipy you define a function in a separate step and when you call it, the coordinates are grouped like (x1,y1,z1),(x2,y2,z2). SCIPY CODE: from scipy.interpolate import RegularGridInterpolatorĪgain it's. The result is Vi= which is indeed the value at those two points (2,6,8) and (3,5,7). ![]() ![]() Here is a full example demonstrating both it will help you understand the exact differences. Vi = my_interpolating_function(array().T) My_interpolating_function = rgi((x,y,z), V) The MATLAB command Vi = interp3(x,y,z,V,xi,yi,zi) would translate to something like: from numpy import arrayįrom scipy.interpolate import RegularGridInterpolator as rgi In scipy 0.14 or later, there is a new function which closely resembles interp3. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |