使用python在地理位置不规则的经度/纬度网格上执行双线性插值的最快方法



我有两个形式为np.array[i,j,k]的不规则网格。它们表示经度和纬度数组:lons[135,90,4]lats[135,90,4]。在每个i,j坐标处,我具有被细分为9x8像素网格的数据。lon/lat阵列中的k值对应于每个9x8子网格的4个角处的lon/lat值。第一个数组元素是左上角的像素。第二个元素是右上角的像素。第三和第四元素分别指左下像素和右下像素。以下是位于135,90网格上i,j的网格点的图示:

 nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbspj
 nbsp nbspk=0 nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbspk=1
nbsp nbsp nbsp nbsp thinsp;0 nbsp thinsp thinsp;1. nbsp thinsp thinsp;2. nbsp thinsp thinsp;3. nbsp thinsp thinsp;4. nbsp thinsp thinsp;5. nbsp thinsp thinsp;6. nbsp thinsp thinsp;7
 nbsp nbsp 0|----|----|----|----|---|----|
 nbsp nbsp nbsp;1|----|----|----|----|---|----|
 nbsp nbsp nbsp;2|----|----|----|----|---|----|
 nbsp nbsp nbsp;3|----|----|----|----|---|----|
i nbsp nbsp 4|----|----|----|----|---|----|
 nbsp nbsp nbsp;5|----|----|----|----|---|----|
 nbsp nbsp nbsp;6|----|----|----|----|---|----|
 nbsp nbsp nbsp;7|----|----|----|----|---|----|
 nbsp nbsp nbsp;8|----|----|----|----|---|----|
 nbsp nbsp k=2 nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbspk=3

我有形式为data[135,90,9,8]的阵列中每个子网格像素的数据,我想使用类似plt.pcolormesh(lons,lats,data)的东西在地图上绘制数据

到目前为止,我已经编写了一个循环,将数据重塑为2D数组:new_data[1215,720]

# Note: 135*9 = 1215, 90*8 = 720
new_data = np.zeros((1215,720))
n,m,i,j=0,0,0,0
for i in range(135):
for j in range(90):
new_data[n:n+9,m:m+8] = data[i,j,:,:]
m = m + 8
m = 0
n = n + 9

现在,我需要使用4个角lon/lat值(即k值)对每个i,j网格点的9x8子网格应用双线性插值。本质上,我需要形式为new_lons[1215,720]new_lats[1215,720]的lon/lat数组,以便使用pcolormesh进行绘图。

应用这种插值的最有效(最快)方法是什么?在这种情况下,我该如何应用它

有很多插值问题,但我还没有见过一个涉及到对位于不规则间隔的长/宽网格上的每个点进行子网格插值的问题。提前谢谢。

我已经找到了解决问题的方法,所以希望有一天这能帮助到别人。。。

为了重新网格化lat/lons,我使用了imresize:的双线性插值

from scipy.misc import imresize
new_data = np.zeros((1215,720))
new_lons = np.zeros((1215,720))
new_lats = np.zeros((1215,720))
n,m=0,0
for i in range(135):
for j in range(90):
new_data[n:n+9,m:m+8] = data[i,j,:,:]
new_lons[n:n+9,m:m+8] = imresize(lons[i,j,:].reshape(2,2), (9,8), mode='F', interp='bilinear')
new_lats[n:n+9,m:m+8] = imresize(lats[i,j,:].reshape(2,2), (9,8), mode='F', interp='bilinear')
m = m + 8
m = 0
n = n + 9

最新更新