【发布时间】:2017-07-07 04:30:44
【问题描述】:
我有一个大型的 netcdf 文件,它是三维的。我想用 2 替换 netcdf 文件中变量 LU_INDEX 的所有值 10。
我为此编写了这个 python 脚本,但它似乎不起作用。
filelocation = 'D:/dataset.nc'
ncdataset = nc.Dataset(filelocation,'r')
lat = ncdataset.variables['XLAT_M'][0,:,:]
lon = ncdataset.variables['XLONG_M'][0,:,:]
lu_index = ncdataset.variables['LU_INDEX'][0,:,:]
lu_index_new = lu_index
ncdataset.close()
nlat,nlon=lat.shape
for ilat in range(nlat):
for ilon in range(lon):
if lu_index == 10:
lu_index_new[ilat,ilon] = 2
newfilename = 'D:/dataset.new.nc'
copyfile(ncdataset,newfilename)
newfile = nc.Dataset(newfilename,'r+')
newfile.variables['LU_INDEX'][0,:,:] = lu_index_new
newfile.close()
我得到错误:
The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
我对python不是很有经验,所以如果有更简单的方法可以做到这一点,非常欢迎您发表评论。
【问题讨论】: