如何使用 IDW 将 xarray 从高分辨率重新网格化到低分辨率 [英] How to re-gridding xarray from higher to lower resolution using IDW

查看:108
本文介绍了如何使用 IDW 将 xarray 从高分辨率重新网格化到低分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 winpython 3.6.我有一个给定区域的 xarray 数据,如下所示:

I am using winpython 3.6. I have an xarray data for a given region as given below:

sea_clt=clt.sel(lat=slice(-13, 31), lon=slice(89,152))
clt_sea_array=sea_clt[:,:,:]

Out[20]: 
<xarray.DataArray 'clt' (time: 20075, lat: 23, lon: 25)>
[11543125 values with dtype=float32]
Coordinates:
  * lat      (lat) float64 -13.0 -11.0 -9.0 -7.0 -5.0 -3.0 -1.0 1.0 3.0 5.0 ...
  * lon      (lon) float64 91.25 93.75 96.25 98.75 101.2 103.8 106.2 108.8 ...
  * time     (time) datetime64[ns] 1950-01-01T12:00:00 1950-01-02T12:00:00 ...

网格间距为 200km*200km(2.0 度*2.0 度标度),每日时间序列变量.现在我想对每个时间步长以(50km*50km 或 0.5degree*0.5degree 网格比例)重新网格化这些数据.我尝试了重塑选项,但没有成功.我无法得到任何解决方案.如何使用最近邻或 IDW 等任何标准方法来做到这一点?任何帮助,将不胜感激.

The grid spacing is 200km*200km (2.0degree*2.0 degree scale) with daily time series variable. Now I want to re-gridding this data at (50km*50km or 0.5degree*0.5degree grid scale) for each time steps. I tried with reshaping options but not succeeded. I am not able to get any solution of it. How can do this with any standard method like Nearest-Neighbor or IDW? Any help would be appreciated.

推荐答案

可以使用 reindex,

sea_clt.reindex(lat=lat_new, lon=lot_new, method='nearest')

其他插值,例如线性插值,尚未在 xarray 中实现.

Other interpolations, such as linear interpolation, are not yet implemented in xarray.

对于线性插值,我们现在能做的最好的可能是

For the linear interpolation, the best we can do now might be

from scipy.interpolation import interp1d

def interp(y_src, x_src, x_dest, **kwargs):
    return interp1d(x_src, y_src, **kwargs)(x_dest)

new_da = sea_clt
new_da = xr.apply_ufunc(interp, new_da, input_core_dims=[['lat']], 
                        output_core_dims=[['lat_new']], 
                        kwargs={'x_src': new_da['lat'], 'x_dest': lat_new})
new_da.coords['lat_new'] = lat_new

new_da = xr.apply_ufunc(interp, new_da, input_core_dims=[['lon']], 
                        output_core_dims=[['lon_new']], 
                        kwargs={'x_src': new_da['lon'], 'x_dest': lon_new})
new_da.coords['lon_new'] = lon_new

这篇关于如何使用 IDW 将 xarray 从高分辨率重新网格化到低分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆