metpy的函数interpolate_to_points应该怎么用?

How should the function interpolate_to_points of metpy be used?

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

points (array_like, shape (n, D)) – Coordinates of the data points. values (array_like, shape (n,)) – Values of the data points. xi (array_like, shape (M, D)) – Points to interpolate the data onto.

关于 'points' 我已经尝试将它们提供为一维数组,二维网格(通过 np.meshgrid 获得),并以经度优先或纬度优先的方式提供。 '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,) 非常感谢任何我错误的建议。

这个函数封装了scipy.interpolate.griddata,你可以看看他们的文档here

他们的示例显示了以下内容,它适用于 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))