- 积分
- 520
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2015-10-4
- 最后登录
- 1970-1-1
|
发表于 2022-1-26 17:32:51
|
显示全部楼层
老师,我在存储数据的时候,遇到以下报错,好像是list和array的使用异常,但还是不知道改哪里。
第73行就是“ncfile.write(variables[0], latitude)”
File "M:\WRFDATA\sigmaTohpa.py", line 73, in <module>
ncfile.write(variables[0], array(latitude))
File "D:\software\MeteoInfo_3.2.2\MeteoInfo\pylib\mipylib\dataset\dimdatafile.py", line 493, in write
self.ncfile.write(ncvariable, value)
at ucar.nc2.NetcdfFileWriter.write(NetcdfFileWriter.java:1071)
at ucar.nc2.NetcdfFileWriter.write(NetcdfFileWriter.java:1053)
at sun.reflect.GeneratedMethodAccessor129.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
java.lang.UnsupportedOperationException: java.lang.UnsupportedOperationException: in define mode
fn = 'M:/WRFDATA/wrfout_d02_2020-04-14_05_38_00'
f = addfile(fn)
time = fn.split('_')[2]+fn.split('_')[3]+':'+fn.split('_')[4]+':'+fn.split('_')[5]
#Calculate pressure array
pp = f['P'][:]
psb = f['PB'][:]
ptop = f['P_TOP'][0]
eta = f['ZNU'][0]
latitude = f['XLAT'][:]
longitude = f['XLONG'][:]
nz,ny,nx = pp.shape
eta = eta.reshape(nz,1,1)
pres = (psb * eta + ptop + pp) * 0.01
#Read and de-stagger u and v
u = f['U'][:]
v = f['V'][:]
destag_u = meteo.wrf.destagger(u, -1)
destag_v = meteo.wrf.destagger(v, -2)
y = destag_u.dimvalue(-2)
x = destag_u.dimvalue(-1)
#Interpolate u and v to pressure level
levels = [800, 750, 500, 200]
uwind = meteo.log_interpolate_1d(levels, pres, destag_u, axis=0)
vwind = meteo.log_interpolate_1d(levels, pres, destag_v, axis=0)
#Save netcdf file
outfn = 'M:/WRFDATA/'+fn.split('/')[2]+'.NC'
ncfile = addfile(outfn, 'c')
ledim = ncfile.adddim('bottom_top', 4)
sndim = ncfile.adddim('south_north', ny)
wedim = ncfile.adddim('west_east', nx)
ncfile.addgroupattr('ITLE', ' OUTPUT FROM * PROGRAM:WRF-Chem V4.0.3 MODEL')
ncfile.addgroupattr('START_DATE', time)
ncfile.addgroupattr('SIMULATION_START_DATE', time)
ncfile.addgroupattr('WEST-EAST_GRID_DIMENSION', nx)
ncfile.addgroupattr('WEST-EAST_GRID_DIMENSION', ny)
ncfile.addgroupattr('WEST-EAST_GRID_DIMENSION', 4)
ncfile.addgroupattr('DX', '1000.0f')
ncfile.addgroupattr('DY', '1000.0f')
variables = []
var0 = ncfile.addvar('XLAT', 'float', [sndim, wedim]) #Latitude
var0.addattr('description', 'LATITUDE, SOUTH IS NEGATIVE')
var0.addattr('units', 'degree_north')
var0.addattr('coordinates', 'XLONG XLAT')
variables.append(var0)
var1 = ncfile.addvar('XLONG', 'float', [sndim, wedim]) #Longitude
var1.addattr('description', 'LONGITUDE, SOUTH IS NEGATIVE')
var1.addattr('units', 'degree_east')
var1.addattr('coordinates', 'XLONG XLAT')
variables.append(var1)
var2 = ncfile.addvar('LEVEL', 'int', [ledim]) #Level
var2.addattr('description', 'PRESSURE LEVEL')
var2.addattr('units', 'hPa')
variables.append(var2)
var3 = ncfile.addvar('U', 'float', [ledim, sndim, wedim]) #U
var3.addattr('description', 'x-wind component')
var3.addattr('units', 'm s-1')
var3.addattr('coordinates', 'XLONG_U XLAT_U XTIME')
variables.append(var3)
var4 = ncfile.addvar('V', 'float', [ledim, sndim, wedim]) #V
var4.addattr('description', 'y-wind component')
var4.addattr('units', 'm s-1')
var4.addattr('coordinates', 'XLONG_V XLAT_V XTIME')
variables.append(var4)
ncfile.write(variables[0], latitude)
ncfile.write(variables[1], longitude)
ncfile.write(variables[2], array(levels))
ncfile.write(variables[3], uwind)
ncfile.write(variables[4], vwind)
ncfile.flush()
ncfile.close()
|
|