首页 > 解决方案 > 应该如何使用metpy的interpolate_to_points函数?

问题描述

我想将地理参考数据重新网格到特定网格,在纬度和经度维度上具有不同的分辨率。在我使用之前basemap.interp,但是这个底图已经死了。我正在试验这个metpy包,metpy.interpolate_to_points似乎是合适的人选。只是,从文档中我无法确定我应该输入的参数的格式。上面写着:

points (array_like, shape (n, D)) – 数据点的坐标。values (array_like, shape (n,)) – 数据点的值。xi (array_like, shape (M, D)) – 插入数据的点。

关于“点”,我尝试将它们作为一维数组、二维网格网格(通过 np.meshgrid 获得)以及以 lon first 或 lat first 方式提供。'xi' 也一样。例如:

from metpy.interpolate import interpolate_to_points
out_lons, out_lats = np.meshgrid(out_lons_1Darray, out_lats_1Darray)
downscaled_array = interpolate_to_points( [in_lons, in_lats], input_array, [out_lons, out_lats] )

无论我从哪一次尝试中得到ValueError: operands could not be broadcast together with shapes (192,) (288,) 任何我错的建议,都将不胜感激。

标签: pythonmetpy

解决方案


这个函数包装,你可以在这里scipy.interpolate.griddata看到他们的文档。

他们的示例显示了以下内容,该功能适用​​于该metpy.interpolate.interpolate_to_points功能:

def func(x, y):
    return x*(1-x)*np.cos(4*np.pi*x) * np.sin(4*np.pi*y**2)**2

grid_x, grid_y = np.mgrid[0:1:100j, 0:1:200j]
points = np.random.rand(1000, 2)
values = func(points[:,0], points[:,1])
grid_out = interpolate_to_points(points, values, (grid_x, grid_y))

推荐阅读