gpt4 book ai didi

python - 使用 xarray 从 netcdf 中提取最近的经纬度和时间值

转载 作者:太空狗 更新时间:2023-10-30 02:27:05 27 4
gpt4 key购买 nike

我有一个带有 foll 的 netCDF 文件。结构:

<xarray.Dataset>
Dimensions: (latitude: 94, longitude: 192, time: 366)
Coordinates:
* longitude (longitude) float32 -180.0 -178.125 -176.25 -174.375 -172.5 ...
* latitude (latitude) float32 88.5419 86.6532 84.7532 82.8508 80.9474 ...
* time (time) datetime64[ns] 2016-01-01 2016-01-02 2016-01-03 ...
Data variables:
m2t (time, latitude, longitude) float64 246.5 246.4 246.4 246.4
pre (time, latitude, longitude) float64 9.988e-08 9.988e-08 ...
Attributes:
Conventions: CF-1.0

如何提取特定纬度和经度(例如 86.45、-156.25)和时间(例如 2016-01-10)的网格单元格的值?确切的纬度/经度值可能不在坐标中,在这种情况下我们需要最接近的纬度/经度值

我可以像这样提取特定经度的值:

_hndl_nc.sel(longitude=(_hndl_nc.longitude == -20))

但是,由于 -20 不存在于经度坐标中,因此这不起作用。

最佳答案

虽然你还没有完全正确的语法,但你已经很接近了:

_hndl_nc.sel(time='2016-01-10', longitude=-170.0, latitude=-20.0, method='nearest')

另见: Read multiple coordinates with xarray

关于python - 使用 xarray 从 netcdf 中提取最近的经纬度和时间值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42125653/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com