我正在使用Scientific.IO.NetCDF将NetCDF数据读入Python。我试图读取一个大小为(366,30,476,460)的4d 32位变量,但是我的ndarray中最终得到的只有零值。奇怪的是,如果我只读取3d数据(1,30,476,460),返回的值就是正确的。
这是我想要做的事情:
“[:]”的意思是我正在将整个4D变量“u”读取到一个称为“udata”的ndarray中。但这样做不起作用,udata中全是零。然而,如果我这样做:
这是我想要做的事情:
from Scientific.IO.NetCDF import NetCDFFile as Dataset
from collections import namedtuple
# Define output data structure as a named tuple
Roms_data=namedtuple('Roms_data','Ti Tf Nt U V W Zeta')
# Open the NetCDF file for reading.
ncfile = Dataset(data_file,'r')
if Tstart==-1:
ti=0
tf=NTsav-1
else:
ti=Tstart-1
tf=Tend-1
try:
udata = ncfile.variables['u'][:]
print str(udata.shape)
except:
print ' Failed to read u data from '+data_file
“[:]”的意思是我正在将整个4D变量“u”读取到一个称为“udata”的ndarray中。但这样做不起作用,udata中全是零。然而,如果我这样做:
try:
udata = ncfile.variables['u'][0,:,:,:]
print str(udata.shape)
except:
print ' Failed to read u data from '+data_file
那么现在的“udata”是一个3D的ndarray,具有从NetCDF文件中读取的值。
需要帮忙吗?提前感谢。