- 积分
- 130
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2016-3-25
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 rolemodel 于 2018-9-22 16:17 编辑
我用王老师的程序进行grib资料到ARL资料的转换,报错为
run script...
C:/hysplit4/working\hebing.grib
GRIB data file has been opened...
Time index: 0
2013-06-29 00:00
PRSS Surface_pressure_surface
T02M 2_metre_temperature_surface
U10M 10_metre_U_wind_component_surface
indices must be 3 dimensions!
Traceback (most recent call last):
File "D:\meteoinfojb\6yue2930.py", line 57, in <module>
ksum = arlf.writedatarec(atime, 0, avname, fhour, 99, gdata)
File "D:\metoinfo\MeteoInfo\pylib\mipylib\dataset\dimdatafile.py", line 456, in writedatarec
ksum = self.arldata.writeGridData(t, lidx, vname, fhour, grid, data.asarray())
AttributeError: 'NoneType' object has no attribute 'asarray'
这是我的脚本
from org.meteoinfo.data.meteodata import MeteoDataInfo
from org.meteoinfo.data.meteodata.arl import ARLDataInfo
from org.meteoinfo.data.meteodata.arl import DataLabel
import os
#---- Set data folder
datadir = 'C:/hysplit4/working'
#---- Set output data file
outfn = os.path.join(datadir, '201306.arl')
#if os.path.exists(outfn):
# os.remove(outfn)
#---- Read a GRIB data file
infn = os.path.join(datadir, 'hebing.grib')
print infn
inf = addfile(infn)
print 'GRIB data file has been opened...'
#---- Set output ARL data file
arlf = addfile(outfn, 'c', dtype='arl')
#---- Set variable and level list
gvar2d = ['Surface_pressure_surface','2_metre_temperature_surface','10_metre_U_wind_component_surface',\
'10_metre_V_wind_component_surface']
gvar3d = ['Geopotential_isobaric','Temperature_isobaric','Vertical_velocity_isobaric',\
'U-component_of_wind_isobaric','V-component_of_wind_isobaric','Relative_humidity_isobaric']
avar2d = ['PRSS','T02M','U10M','V10M']
avar3d = ['HGTS','TEMP','WWND','UWND','VWND','SPHU']
gv = inf['Geopotential_isobaric']
nx = gv.dimlen(gv.ndim - 1)
ny = gv.dimlen(gv.ndim - 2)
levels = gv.dimvalue(gv.ndim - 3)[::-1]
nz = len(levels)
arlf.set2dvar(avar2d)
arlf.setlevels(levels)
for l in levels:
arlf.set3dvar(avar3d)
#---- Write ARL data file
arlf.setx(gv.dimvalue(gv.ndim - 1))
arlf.sety(gv.dimvalue(gv.ndim - 2))
tNum = inf.timenum()
fhour = 0
for t in range(0, tNum):
print 'Time index: ' + str(t)
atime = inf.gettime(t)
print atime.strftime('%Y-%m-%d %H:00')
dhead = arlf.getdatahead(inf.proj, 'RSMC', 2, fhour)
#Pre-write index record without checksum - will be over-write latter
arlf.writeindexrec(atime, dhead)
#Checksum list
ksumlist = []
# Write 2d variables
ksums = []
for avname,gvname in zip(avar2d, gvar2d):
print avname + ' ' + gvname
if avname == 'U10M' or avname == 'V10M':
gdata = inf[gvname][t,0,:,:]
else:
gdata = inf[gvname][t,:,:]
if avname == 'PRSS':
gdata = gdata * 0.01
ksum = arlf.writedatarec(atime, 0, avname, fhour, 99, gdata)
ksums.append(ksum)
ksumlist.append(ksums)
# Write 3d variables
for lidx in range(0, nz):
ksums = []
llidx = nz - lidx - 1
print lidx
print llidx
for avname,gvname in zip(avar3d, gvar3d):
print avname + ' ' + gvname
gdata = inf[gvname][t,llidx,:,:]
if avname == 'WWND':
gdata = gdata * 0.01
elif avname == 'SPHU':
gdata = gdata * 1000.
ksum = arlf.writedatarec(atime, lidx + 1, avname, fhour, 99, gdata)
ksums.append(ksum)
ksumlist.append(ksums)
#Re-write index record with checksum
arlf.writeindexrec(atime, dhead, ksumlist)
fhour += 1
arlf.close()
print 'Finished!'
|
|