0
我使用代码沿线的制作netCDF文件:如何为python的netCDF4模块中的变量分配一个短名称?
from netCDF4 import Dataset
outfile = Dataset('output.nc', 'w', format = 'NETCDF4')
level = outfile.createDimension('level', 1)
time = outfile.createDimension('t', None)
lats = outfile.createDimension('latitude', 141)
lons = outfile.createDimension('longitude', 121)
precips = outfile.createVariable('Precipitation', 'f4',('t','level','latitude','longitude'))
times = outfile.createVariable('t','f8',('t',))
levels = outfile.createVariable('level','i4',('level',))
latitudes = outfile.createVariable('latitude','f4',('latitude',))
longitudes = outfile.createVariable('longitude','f4',('longitude',))
latitudes.units = "degrees east"
longitudes.units = "degrees north"
levels.units = "surface"
precips.units = "mm/day"
times.calendar = "gregorian"
这一切工作正常(一旦您填写的变量与数据和呼叫outfile.close()
),但你如何分配一个短名称到变量?我希望沿着线的东西:
precips.shortFieldName = "prec"
但是,已经尝试了很多上的变化,以及扫描的文档,并通过源代码膛线,我没有接近的解决方案。
任何想法?
你贴我优秀作品的代码指针:事后'打印precips.shortFieldName'产量'u'prec “'。问题是什么? – 2014-12-04 14:01:22
你有没有尝试过使用'setattr'? 'setattr(precips,'shortFieldName','prec')' – N1B4 2014-12-04 18:52:02