2014-12-03 26 views
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" 

但是,已經嘗試了很多上的變化,以及掃描的文檔,並通過源代碼膛線,我沒有接近的解決方案。

任何想法?

+1

你貼我優秀作品的代碼指針:事後'打印precips.shortFieldName'產量'u'prec 「'。問題是什麼? – 2014-12-04 14:01:22

+1

你有沒有嘗試過使用'setattr'? 'setattr(precips,'shortFieldName','prec')' – N1B4 2014-12-04 18:52:02

回答

0

prec=precips ^^再就是這不是兩個對象 => 2名這兩者都是使用

相關問題