0
netcdfファイルの変数を持つ。これは、通常のグリッド化されたデータの時間、高さ、lon、latの関数:U [時間、高さ、lon、lat]。私はこの変数を、通常のグリッドにないlon_new、lat_newの定義された位置に補間したい(グリッドポイントの間にある)。私は変数U [0,0、lon_new、lat_new]を1つの補間された位置の点で持つことができるようにしたい。通常のグリッドで変数を補間し、Pythonで通常のグリッド上にない場所に補間する。scipy interpolate.interpn value error
私はscipy補間関数を読んで、scipy.interpolate.interpnが私が使用したい関数だと思っています。私はこの関数の簡単な例を実行しようとしましたが、エラーが続いています。
x_points = [1,2,3,4] #lets call this list of lons on the grid
y_points = [1,2,3,4] #lets call this list of lats on the grid
#Get the lon,lat pairs
point_pairs=[]
for i in x_points:
for j in y_points:
points = [i,j]
point_pairs.append(points)
print point_pairs
print np.shape(point_pairs)
[[1, 1], [1, 2], [1, 3], [1, 4], [2, 1], [2, 2], [2, 3], [2, 4], [3, 1], [3, 2], [3, 3], [3, 4], [4, 1], [4, 2], [4, 3], [4, 4]]
(16L, 2L)
xi = (2.5,2.5) #point in between grid points that I am interested in getting the interpolated value
xi=np.array(xi)
print xi
print np.shape(xi)
[ 2.5 2.5]
(2L,)
values = np.ones(16) #array of values at every grid point Let's say I loop over every grid point and get the value at each one
print values
[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
interpolated_value = interpolate.interpn(point_pairs, values, xi, method='linear')
ValueError: There are 16 point arrays, but values has 1 dimensions
簡単な例で私がscipy関数の1つを試みたところで、上記の質問を編集しました。 – HM14
上記の「拡張」の回答を参照してください。 – Andrew
ありがとう!それが私が行方不明だったものです! – HM14