Vis*_*ngh 2 python python-2.7 python-3.x python-requests python-xarray
我使用的是winpython 3.6。我有给定区域的 xarray 数据,如下所示:
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 ...
Run Code Online (Sandbox Code Playgroud)
网格间距为200km*200km(2.0度*2.0度尺度),每日时间序列变量。现在我想为每个时间步以(50km * 50km或0.5度* 0.5度网格比例)重新网格化这些数据。我尝试使用重塑选项但没有成功。我无法得到任何解决方案。如何使用最近邻法或 IDW 等标准方法来做到这一点?任何帮助,将不胜感激。
网格上数据的最近邻查找可以通过以下方式完成reindex
:
sea_clt.reindex(lat=lat_new, lon=lot_new, method='nearest')
Run Code Online (Sandbox Code Playgroud)
其他插值,例如线性插值,尚未在 xarray 中实现。
对于线性插值,我们现在能做的最好的可能是
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
Run Code Online (Sandbox Code Playgroud)