簡體   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