0

I need to interpolate two variables written in the 3D grid on another 3D grid. I tried the inverse distance method, but I get only two values that do not represent the distribution on the original grid, assigned to each point of the new grid. Here is an example of my code:

text=text[pstart:pend]
x=[]
y=[]
z=[]
for line in text:
    coords=line.split()
    x.append(float(coords[2])) #coordinates of the new grid
    y.append(float(coords[1]))
    z.append(float(coords[0]))

Xg=np.asarray([x,y,z])



# Gather mean flow data
xd=[]
yd=[]
zd=[]
cd=[]
rhod=[]
with open(meanflowdata,'rb') as csvfile:
    spamreader=csv.reader(csvfile, delimiter=',')
    for row in spamreader:
        if len(row)>2:
            xd.append(float(row[0])) #coordinates and values of the source file
            yd.append(float(row[1]))
            zd.append(float(row[2]))
            cd.append(float(row[3]))
            rhod.append(float(row[4]))

Xd=np.asarray([xd,yd,zd])
Zd=np.asarray([cd,rhod])



leafsize = 20

print "# setting up KDtree"
invdisttree = Invdisttree( Xd.T, Zd.T, leafsize=leafsize, stat=1 )

print "# Performing interpolation"
interpol = invdisttree( Xg.T )
c=interpol.T[0]
rho=interpol.T[1]

As far as I could check, the problem lies when I call the invdisttree function, which does not work properly. Does someone have an idea or an alternative method to suggest for the interpolation?

Smithiam
  • 162
  • 1
  • 16

1 Answers1

0

Where do interpol.T[0], interpol.T[1] come from, where did your Invdisttree come from ? This on SO has

invdisttree = Invdisttree( X, z )  -- data points, values
interpol = invdisttree( q, nnear=3, eps=0, p=1, weights=None, stat=0 )

In your case X could be 100 x 3, z 100 x 2, query points q 10 x 3 ⟶ interpol 10 x 2. (invdisttree is a function, which you call to do the interpolation:
interpol = invdisttree( q ...) . Is that confusing ?)

denis
  • 21,378
  • 10
  • 65
  • 88