2

I have a 3D array and want to interpolate it into a finer resolution grid. The 3D array is defined on a regular grid with even spacing. The interpolation is also on a regular grid with even spacing. The step size is 2^(-n), n=0,1,2,3 .... Interpolation should be either linear or higher order Bspline. For example, a 3D array a has sizes of (3,3,5) and the step size of the interpolation grid is (0.5, 0.5, 0.5)(n=1). Then the interpolation grid is defined as

x=np.linspace(0,2,num=5) # 3/0.5-1 = 5
y=np.linspace(0,2,num=5) # 3/0.5-1 = 5
z=np.linspace(0,4,num=9) # 5/0.5-1 = 9
xx, yy, zz = np.meshgrid(x, y, z, sparse=True)

Then the output array should have sizes of (5,5,9). Which interpolation function in scipy or numpy can do the job in a most efficient way?

zell
  • 9,830
  • 10
  • 62
  • 115
f. c.
  • 1,095
  • 11
  • 26
  • 2
    have you looked at the [many interpolation options](https://docs.scipy.org/doc/scipy/reference/interpolate.html) from scipy? – David Jun 11 '20 at 21:11
  • Yes, but I could not find regular even grids to regular even grid for 3D array. I have seen there are RegularGridInterpolator and map_coordinates, but they are designed to solve more general problems. – f. c. Jun 11 '20 at 21:32
  • 1
    [scipy.interpolate.interpn](https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interpn.html#scipy.interpolate.interpn) interpolates on regular grids of arbitrary dimension – David Jun 11 '20 at 21:35
  • @David I have looked the interpn function, but could not find a good example about it. Could you give an example of how to use it? – f. c. Jun 12 '20 at 08:23
  • 1
    https://stackoverflow.com/questions/39332053/using-scipy-interpolate-interpn-to-interpolate-a-n-dimensional-array/39357219 – David Jun 12 '20 at 15:52

1 Answers1

1

I have found zoom is the most efficient function to do it. Check it out: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.zoom.html

f. c.
  • 1,095
  • 11
  • 26