2

我对 python 很陌生,想在常规网格中进行插值。首先,我用 interp2d 进行了尝试。这适用于大多数情况,但在某些情况下(唯一的区别是值)有一个警告,结果不符合预期。这是代码:

img=sys.argv[1]
latitude=np.loadtxt(img+'/'+'geolayer.Lat.txt')
longitude=np.loadtxt(img+'/'+'geolayer.Lon.txt')

n=int(sys.argv[2])

rows=int(sys.argv[3])
cols=int(sys.argv[4])

m=len(latitude)/n

#Latitude
column=latitude[:,0].reshape((m,n))
row=latitude[:,1].reshape((m,n))
val=latitude[:,2].reshape((m,n))

# create interpolation object
interp=interp2d(column,row,val)

# interpolate values
lattmp=interp(np.arange(cols),np.arange(rows))
lat=np.degrees(np.arctan(1.0067395*np.tan(np.radians(lattmp))))

这是我偶尔收到的警告:

Warning:     No more knots can be added because the number of B-spline coefficients
already exceeds the number of data points m. Probably causes: either
s or m too small. (fp>s)
    kx,ky=1,1 nx,ny=14,14 m=143 fp=0.000000 s=0.000000

这是输入的样子:

In [174]: shape(column)
Out[174]: (13, 11)
In [175]: shape(row)
Out[175]: (13, 11)
In [176]: shape(val)
Out[176]: (13, 11)

警告和无警告之间的唯一区别是 val 中的值。在阅读了几个线程之后,我也尝试了 scipy.interpolate.RectBivariateSpline:

ttt=scipy.interpolate.RectBivariateSpline(rr,cc,val,bbox=[0,4199, 0,4099],kx=1,ky=1)
lattmp=ttt(np.arange(cols),np.arange(rows))
In [181]: shape(cc)
Out[181]: (11,)
In [182]: shape(rr)
Out[182]: (13,)
In [183]: shape(val)
Out[183]: (13, 11)

但我只得到这个:

In [170]: lattmp
Out[170]: 
array([[ NaN,  NaN,  NaN, ...,  NaN,  NaN,  NaN],
   [ NaN,  Inf,  Inf, ...,  Inf,  Inf,  Inf],
   [ NaN,  Inf,  Inf, ...,  Inf,  Inf,  Inf],
   ..., 
   [ NaN,  Inf,  Inf, ...,  Inf,  Inf,  Inf],
   [ NaN,  Inf,  Inf, ...,  Inf,  Inf,  Inf],
   [ NaN,  Inf,  Inf, ...,  Inf,  Inf,  Inf]])

谁能告诉我,我能做什么?

最好的问候,谢谢你,马蒂亚斯

4

0 回答 0