【发布时间】:2016-11-10 17:23:54
【问题描述】:
假设我有一个数组nl,其中包含 4124 个测量值。每个都与(lat,lon)对关联,指定测量发生的位置。这些位置没有网格化,即它们没有与规则间隔的值对齐。
In [51]: whos
Variable Type Data/Info
---------------------------------
lat ndarray 4124: 4124 elems, type `float32`, 16496 bytes
lon ndarray 4124: 4124 elems, type `float32`, 16496 bytes
nl ndarray 4124: 4124 elems, type `int16`, 8248 bytes
我为nl 创建一个DataArray,指定lat 和lon 作为坐标:
nl = xr.DataArray(nl, coords={'lon':(['time'], lon), 'lat':(['time'], lat)}, dims=['time'])
我知道我可以将这些值分组到经度或纬度的 bin 中以对它们进行操作,例如
nl_avg_lon = nl.groupby_bins('lon', np.r_[-180:190:10]).mean()
nl_avg_lat = nl.groupby_bins('lat', np.r_[-90:90:10]).mean()
我想做的是在经度 x 纬度的 2D 箱中对值进行分组,因此我可以将结果显示为地图。我不认为 groupby_bins 可以做到这一点,还有其他解决方案吗?
更新示例:
这就是我使用 numpy 做我想做的事情的方式:
latbins = np.r_[-90:100:10]
lonbins = np.r_[-180:190:10]
nsamples, xx, yy = np.histogram2d(lon, lat, bins=(lonbins, latbins))
nl_sum, xx, yy = np.histogram2d(lon, lat, bins=(lonbins, latbins), weights=nl)
nl_avg = nl_sum / nsamples
我想避免使用 numpy 来保持 xarray 与 dash 的集成。
【问题讨论】:
标签: python-xarray