1

我有一个问题,我无法使用 scipy 正确解决。我想重新采样和排列,以便降低分辨率(从高到低)但是,这就是问题所在,新的阵列形状不是旧阵列形状的一个因素。例如:

 lat = scipy.mgrid[-14.0:14+0.25:0.25]
 lon = scipy.mgrid[100.0:300+0.25:0.25]
 z = rand((lat.shape[0],lon.shape[0]))
 new_res = 0.70135

现在我有一个空间分辨率为 0.25 的数组 z,我想将其减少到 new_res。任何想法如何使用 scipy 或手动完成?更复杂的情况是数组 z 中经常存在不良数据,即 z[0.20] 可能为 nan。

感谢您的帮助和想法

4

1 回答 1

2

一个快速的方法是使用scipy.ndimage.interpolation.map_coordinates.

lat = scipy.mgrid[-14.0:14+0.25:0.25]
lon = scipy.mgrid[100.0:300+0.25:0.25]
z = tile(lon,(len(lat),1))
new_res = 0.70135


new_lat = scipy.mgrid[-14.0:14+0.25:new_res]
new_lon = scipy.mgrid[100.0:300+0.25:new_res]
X,Y = meshgrid(((new_lat-np.min(lat))/(np.max(lat)-np.min(lat)))*lat.shape[0],((new_lon-np.min(lon))/(np.max(lon)-np.min(lon)))*lon.shape[0])
pts = np.asarray(zip(X.ravel(),Y.ravel())).T
new_z = scipy.ndimage.interpolation.map_coordinates(z,pts).reshape(len(new_lon),len(new_lat)).T

调用中的所有混乱meshgrid都是转换实际单位 -> 数组单位。我不确定这将如何处理NaN,我怀疑您必须先清理数据或NaN在重新采样时接受增长区域。

教程也可能有用。

于 2012-10-05T14:46:29.143 回答