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

标签 python netcdf python-xarray

我有一个带有 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/

相关文章:

python - Python 中表的多个表头

python - 套接字使用随机端口,我需要一个

python - 从包含在 shapefile 边界内的 netcdf 文件中提取数据

r - 编写netcdf时设置坐标系

python - netCDF4-python 生成的文件在 Panoply 中显示效果不佳

python - 查找 NetCDF 中多个经纬度中心的半径内的值

python - 使用 x 轴偏移在 python (5GB) 中绘制非常大的文件

python - Flask 是否已经清理了请求数据?

python - 使用库 xarray (python) 进行分组后,时间维度错误

python - 使用 matplotlib 在一张图上绘制四个箱线图