- 积分
- 927
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2017-6-25
- 最后登录
- 1970-1-1
|
发表于 2023-5-20 15:40:49
|
显示全部楼层
本帖最后由 坎坷 于 2023-5-20 15:43 编辑
我使用的插值函数,使用的是scipy.interpolate.griddata这个函数,经实测,边缘处有锯齿,其他处基本一致
from scipy.interpolate import griddata
class read_wrf_vars:
def regrib_data(self, data, lon, lat):
"""
插值获取网格化数据
"""
# 截取边界
min_lon, max_lon, min_lat, max_lat = lon[:, 0].max(), lon[:, -1].min(), lat[0, :].max(), lat[-1, :].min()
dx = (max_lon - min_lon) / lat.shape[1]
dy = (max_lat - min_lat) / lat.shape[0]
resolution = 50
# dx = np.fabs(lon[0,1] - lon[0,0])
# dy = np.fabs(lat[0,1] - lat[0,0])
order = 1
while True:
if dx*order >= 50:
dx = dx*order // resolution * 50
break
else:
order = order * 10
dx = dx / order
order = 1
while True:
if dy*order >= 50:
dy = dy*order // resolution * 50
break
else:
order = order * 10
dy = dy / order
min_lon = min_lon // dx * dx
max_lon = max_lon // dx * dx
min_lat = min_lat // dy * dy
max_lat = max_lat // dy * dy
grid_x, grid_y = np.arange(min_lon + dx, max_lon, dx), np.arange(min_lat + dy, max_lat, dy)
grid_x2d, grid_y2d = np.meshgrid(grid_x, grid_y)
grid_z0 = griddata(np.array([np.array(lat).flatten(), np.array(lon).flatten()]).T, np.array(data).flatten(), (grid_y2d.flatten(), grid_x2d.flatten()), method='linear')
grid_z0 = grid_z0.reshape(grid_x2d.shape)
return grid_z0, grid_x, grid_y
|
|