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