繁体   English   中英

Xarray select dataarray 根据无维度坐标

[英]Xarray select dataarray according to an non-dimension coordinate

我想根据非维度坐标的标准 select 一个数据数组。 在下面的示例中,我的坐标“sat”取决于坐标“时间”,这正是我所需要的。 当我使用Dataarray.sel(time='2021-05-04')时,一切正常,但我需要能够使用此标准Dataarray.sel(sat='L30') 如果查询更方便,我可以打开以另一种方式堆叠有关“sat”的信息,但我不想将我的数据数组分成两个数据数组(sat='L30 和'S30')合并到一个数据集中.

谢谢!

<xarray.DataArray (band: 5, time: 48, lat: 93, lon: 82)>
array([...])
Coordinates:
  * band     (band) <U5 'Fmask' 'blue' 'nir_n' 'red' 'swir2'
  * lat      (lat) float64 5.415e+06 5.415e+06 5.415e+06 ... 5.413e+06 5.413e+06
  * lon      (lon) float64 6.658e+05 6.658e+05 6.659e+05 ... 6.682e+05 6.682e+05
  * time     (time) datetime64[ns] 2021-05-04T15:35:59 ... 2021-10-28T15:26:29
    sat      (time) <U3 'S30' 'L30' 'S30' 'S30' ... 'S30' 'S30' 'S30' 'S30'
Attributes:
    transform:      (30.0, 0.0, 665790.0, 0.0, -30.0, 5415330.0)
    crs:            +init=epsg:32619
    res:            (30.0, 30.0)
    is_tiled:       1
    nodatavals:     (-9999.0,)
    scales:         (1.0,)
    offsets:        (0.0,)
    AREA_OR_POINT:  Area

最后,在 xarray github 上的一个老问题中找到了足够优雅的答案:

ds.sel(时间 = ds.sat == 'L30')

笔记:

ds = 数据数组(或数据集)

时间:因为我的坐坐标与时间坐标相关联

ds.sat 存在是因为我创建了它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM