我想根据标准从非维度坐标中选择一个Dataarray。在下面的例子中,我有我的坐标"坐着",这取决于坐标"时间",这正是我所需要的。当我使用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=DataArray(或Dataset(
时间:因为我的sat坐标与时间坐标相连
ds.sat存在是因为我创建了它