【问题标题】:Reading 1-D Variables in WRF NetCDF files with GDAL python使用 GDAL python 读取 WRF NetCDF 文件中的一维变量
【发布时间】:2016-07-12 02:33:59
【问题描述】:

我的问题很简单。
以 wrfout 文件“out.nc”为例。
该文件包含 Geo2D、Geo3D 和 1D 变量。

在 Python 2.7 中使用 GDAL 包,我可以像这样轻松提取 Geo2D 变量:

## T2 is 2-d variable means temperature 2 m above the ground
temp = gdal.Open('NETCDF:"'+"out.nc"+'":T2')          

但是当我想使用这段代码提取一维数组时,它失败了。

## Time is 1-d array represent the timeseries throught the simulation period
time = gdal.Open('NETCDF:"'+"out.nc"+'":Time')       

什么都没发生!希望有人提供一些建议以轻松读取任意维度的 WRF 输出变量!

【问题讨论】:

  • 你试过用 python-netcdf4 代替 gdal 吗?

标签: python gdal netcdf matplotlib-basemap


【解决方案1】:

您也可以在 scipy.io 中使用 NetCDF 阅读器:

import scipy.io.netcdf as nc

# Open a netcdf file object and assign the data values to a variable
time = nc.netcdf_file('out.nc', 'r').variables['Time'][:]

它的好处是 scipy 是一个非常流行和广泛安装的软件包,同时在某些方面类似于打开文件。

【讨论】:

  • 感谢您的回复。我会努力的!
猜你喜欢
  • 2021-02-10
  • 2020-09-22
  • 2022-01-09
  • 2016-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多