繁体   English   中英

在 xarray 数据框中过滤 2 坐标索引

[英]Filter 2 coordinate index in xarray dataframe

我正在尝试过滤 xarray 中的大型数据集以获取以下数据集中的精确latitudelongitude值:

<xarray.Dataset>
Dimensions:    (latitude: 23, level: 6, longitude: 21, time: 178486)
Coordinates:
  * time       (time) datetime64[ns] 1979-01-01 ... 2019-11-26T21:00:00
  * latitude   (latitude) float32 46.5 46.25 46.0 45.75 ... 41.5 41.25 41.0
  * longitude  (longitude) float32 18.0 18.25 18.5 18.75 ... 22.5 22.75 23.0
  * level      (level) int32 750 800 850 900 950 1000
Data variables:
    cbh        (time, latitude, longitude) float32 ...
    clwc       (time, level, latitude, longitude) float32 ...
    t          (time, level, latitude, longitude) float32 ...
    vetar      (time, level, latitude, longitude) float32 ...
    sp         (time, latitude, longitude) float32 ...
Attributes:
    Conventions:  CF-1.6
    history:      2019-05-11 06:14:51 GMT by grib_to_netcdf-2.10.0: /opt/ecmw...

我正在尝试使用 where 语句来执行此操作,但似乎我需要比较数组才能执行此操作。 使用DS1.where(DS1.longitude==22.0 and DS1.latitude==43.5,drop=True)我得到了著名的错误:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

我可以分两步执行此过滤,首先是

ds22=DS1.where(DS1.longitude==22.0,drop=True) 

然后用

ds22435=ds22.where(ds22.latitude==43.5,drop=True)

但是有没有办法一步做到这一点?

看看Dataset.sel (另请参见此处的示例)。 我认为类似以下内容将满足您的需求:

result = DS1.sel(latitude=43.5, longitude=22.0)

暂无
暂无

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

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