在 xarray 数据框中过滤 2 坐标索引
Filter 2 coordinate index in xarray dataframe
我正在尝试过滤 xarray 中的大型数据集以获得来自以下数据集的精确 latitude
、longitude
值:
<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
(see also examples here)。我认为类似以下的内容可以满足您的需求:
result = DS1.sel(latitude=43.5, longitude=22.0)
我正在尝试过滤 xarray 中的大型数据集以获得来自以下数据集的精确 latitude
、longitude
值:
<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
(see also examples here)。我认为类似以下的内容可以满足您的需求:
result = DS1.sel(latitude=43.5, longitude=22.0)