Skip to main content
 首页 » 编程设计

python之无法读取 netcdf 文件属性,因为属性名称包含括号

2024年10月24日10mayingbao

我正在使用 python-2.7 和 NetCDF4 模块来读取 netcdf 文件。我需要从名称中包含括号的 netcdf 文件中读取全局属性 (Lat(Degrees.Cents_of_degrees)),但我无法读取它。我的工作:

from netCDF4 import Dataset as NetCDFFile 
filename = 'DDE30.2002.RG300004.nc' 
nc = NetCDFFile(filename) 
lat = nc.Lat(Degrees.Cents_of_degrees) 

但是我明白了:

AttributeError: NetCDF: Attribute not found 

我试过在括号前使用反斜杠,但没有用。 Here是 netcdf 文件。

请您参考如下方法:

我想你想要 getncattr [docs] .可能最好不要依赖@M.T 建议的私有(private)方法。

lat = nc.getncattr('Lat(Degrees.Cents_of_degrees)')