# Regridding 3d array

nub question.
I have a 3d array of input data1 of dimensions [nx,ny,nz]
The data represent a 3D continuous function sampled on an irregular grid.
data[i,j,k] is the data at grid point [i,j,k].
xgrid1[i,j,k] are the x-coordinates of point [i,j,k].
ygrid1[i,j,k] are the y-coordinates of point [i,j,k].
zgrid1[i,j,k] are the z-coordinates of point [i,j,k].
xgrid1, ygrid1, and zgrid1 could be instead be represented by an array of triple grid1.

xgrid2, ygrid2, and zgrid2 (or grid2) are the coordinates of a different grid.
How do generate a 3D array data2 that approximates the function represented by data1 at the grid points defined by grid2?

This should be a trivial application of any interpolation package, but I find the documentation of the packages too concise to be of much help.

Hi asb,
The Interpolations.jl package does linear interpolation on irregular grids, e.g. this:

``````using Interpolations

xg1,yg1,zg1 = sort(rand(50)),sort(rand(60)),sort(rand(70))
data1 = [sum(xyz) for xyz=Iterators.product(xg1,yg1,zg1)]

itp = interpolate((xg1,yg1,zg1), data1, Gridded(Linear()))
etpf = extrapolate(itp, Flat())

xg2,yg2,zg2 = range(0,1,length=10),range(0,1,length=11),range(0,1,length=12)
coords = Iterators.product(xg2,yg2,zg2)
data2 = (c->etpf(c...)).(coords)
``````