xarray 中穿过 0 的切片经度坐标

Slicing longitude coordinate in xarray which crosses the 0

我有经度坐标从 0.5 到 359.5 的 xarray 数据集,如下所示:

Dimensions:    (bnds: 2, lat: 40, lev: 35, lon: 31, member_id: 1)
Coordinates:
    lev_bnds   (lev, bnds) float64 ...
    lon_bnds   (lon, bnds) float64 ...
    lat_bnds   (lat, bnds) float64 ...
  * lon        (lon) float64 0.5 1.5 2.5 3.5 4.5 ... 359.5
  * lev        (lev) float64 2.5 10.0 20.0 32.5 ... 5e+03 5.5e+03 6e+03 6.5e+03
  * lat        (lat) float64 -89.5 -88.5 -87.5 -86.5 ... -53.5 -52.5 -51.5 -50.5
  * member_id  (member_id) object 'r1i1p1f1'
Dimensions without coordinates: bnds
Data variables:
    so         (member_id, lev, lat, lon) float32 nan nan nan ... 

我感兴趣的区域在60W到30E之间,大概对应经度300.5到30.5。有没有办法在这些坐标之间分割数据集? 我尝试使用 isel(slice(-60,30) 但在 slice 函数中不可能有负数到正数。 我知道我可以将数据分成两个小的(300.5-359.5 和 0.5-30.5),但我想知道是否有更好的方法。

谢谢!

正如您正确指出的那样,目前 isel 不能 select 从维度的起点和终点在单次传递中。

如果结合roll http://xarray.pydata.org/en/stable/generated/xarray.DataArray.roll.html,你可以将你想要的点移动到一个连续的区域,然后select你需要的那些。

注意:我不能从你的例子中确定,但看起来你可能想要 sel 而不是 isel,因为你可能 selecting by index value而不是位置