xarray:沿一个坐标反转数组

ru1*_*111 3 python-xarray

对于我的数据数组,我有坐标经度、纬度和时间。我只想沿纬度反转数组,以便[90, 85, ..., -85, -90]变为[-90, -80, ..., 85, 90].

Max*_*ian 11

同意@jhamman 的回应,即一个可重现的例子会有所帮助

我想你可以用

da = xr.tutorial.open_dataset('air_temperature')
da.reindex(lat=list(reversed(da.lat)))`
Run Code Online (Sandbox Code Playgroud)

  • 这有效 - 我发现`da.reindex(lat=da.lat[::-1])`要快一点。非常感谢! (4认同)
  • 我认为这不起作用,直到我意识到 `reindex()` 函数没有就位,你必须将返回值分配给某些东西(可能是原始变量)。 (2认同)

rvb*_*rvb 5

基于此讨论,另一种选择是使用isel来获得相反的视图:

da = xr.tutorial.open_dataset('air_temperature')
da.isel(lat=slice(None, None, -1)
Run Code Online (Sandbox Code Playgroud)

我发现这种方法更适合 dask 数组支持的大型数据集。reindex@Maximilian 的答案中的方法会导致数据被重新分成非常大的块。这种方法避免了这种情况。