小编Gij*_*ter的帖子

更改变量的netcdf文件的值

我有一个三维的大netcdf文件.我想替换LU_INDEXnetcdf文件中的变量所有值10与2.

我写这个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()
Run Code Online (Sandbox Code Playgroud)

我收到错误:

The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Run Code Online (Sandbox Code Playgroud)

我对python不是很有经验,所以如果有更简单的方法,我们非常欢迎您发表评论.

python netcdf

2
推荐指数
1
解决办法
3570
查看次数

标签 统计

netcdf ×1

python ×1