【问题标题】:xarray selecting based on coordinates基于坐标的xarray选择
【发布时间】:2020-02-04 18:20:01
【问题描述】:

我有一堆数据要插入到xarray 数据集中。数据集下方只有一个 DataArray,但将来可能会更多。一些数据集维度已注释,我已将这些维度作为沿一个或多个轴的坐标插入到数据集中。现在我想获得一个坐标为annot1 = '1' 的数据集。

我用ds.sel() 方法尝试了一堆不同的字典,但这似乎不是解决方案。如何以仅获取 annot1 = '1' 的数据的方式索引以下数据集?

import xarray as xr
import numpy as 

coords = {
    'x':['a','b','c','d'], 
    'y':['A','B','C','D'], 
    'z':['d_000','d_001','d_010','d_011','d_100','d_101'],
    'annot1': ('z',['0','1','0','1','0','1']),
    'annot2': ('z',['0','0','1','1','0','0']),
    'annot3': ('z',['0','0','0','0','1','1']),
    'intens':(['x','y'], np.arange(4**2).reshape((4,4))),
}


ds = xr.Dataset(
    data_vars={
        'data': (['x','y','z'], np.random.randn(4,4,6))
    },
    coords=coords,
)
ds.sel(annot1 = '1') # How do i select only the data where annot1 is '1'?

【问题讨论】:

    标签: python python-3.x python-xarray


    【解决方案1】:

    找到我要找的东西:ds.sel(z=ds['annot1']=='1')

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 1970-01-01
      • 2020-03-04
      • 2021-12-12
      • 1970-01-01
      • 2022-01-27
      • 2017-09-25
      相关资源
      最近更新 更多