0

我想根据非维度坐标的标准选择一个 Dataarray。在下面的示例中,我的坐标“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
4

1 回答 1

0

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

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

笔记:

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

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

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

于 2022-01-24T13:57:06.087 回答