python - 应该如何使用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,)
任何我错的建议,都将不胜感激。
解决方案
这个函数包装,你可以在这里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))
推荐阅读
- php - 使用 brew 在 MacOS 上安装 php72
- javascript - 不监听 iOS 上的滚动事件
- django - 如何为 django 激活电子邮件添加重新发送间隔?
- node.js - Node.js 和车把中的 DocuSign API 集成
- regex - 如何使用交替和替换来执行 Perl 正则表达式
- javascript - 带有特殊字符的正则表达式问题
- html - 在使用 BEM(块、元素、修饰符)命名约定时,是否必须将类名应用于 HTML 中的每个元素?
- php - 响应必须包含 AMP-Access-Control-Allow-Source-Origin 标头?
- php - Laravel 错误:函数 Illuminate\Database\Eloquent\Model::setAttribute() 的参数太少
- spring-boot - Springboot如何锁定libs的版本,比如Rails的Gemfile.lock?