- 积分
- 1331
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2018-7-3
- 最后登录
- 1970-1-1
|
Python
系统平台: |
|
问题截图: |
|
问题概况: |
用王老师的Meteoinfo代码将ERA5转arl后一直出错,请问有人遇到过这个问题吗?怎么解决? |
我看过提问的智慧: |
看过 |
自己思考时长(天): |
1 |
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
这是王老师的代码,我只把文件名改成我自己的
# Convert ERA5 GRIB data to ARL data
#---- Set data folder
datadir = r'E:/ERA5/down'
#---- Set output data file
outfn = os.path.join(datadir, 'test_era5_grib_diff1.arl')
#---- Read a GRIB data file
infn3d = addfile('{}/201901_press.grib'.format(datadir))
infn2d = addfile('{}/201901sur.grib '.format(datadir))
print 'GRIB data file has been opened...'
#---- Set output ARL data file
arlf = addfile(outfn, 'c', dtype='arl')
#---- Set variable and level list
#---- Variable names in ERA5 data file
gvar2d = ['Surface_pressure_surface','2_metre_temperature_surface','10_metre_U_wind_component_surface',\
'10_metre_V_wind_component_surface','Boundary_layer_height_surface','Convective_available_potential_energy_surface',\
'Instantaneous_eastward_turbulent_surface_stress_surface','Instantaneous_northward_turbulent_surface_stress_surface']
gvar3d = ['Geopotential_isobaric','Temperature_isobaric','Vertical_velocity_isobaric',\
'U_component_of_wind_isobaric','V_component_of_wind_isobaric','Relative_humidity_isobaric']
#---- Corresponding variable names in ARL data file
avar2d = ['PRSS','T02M','U10M','V10M','PBLH','CAPE','UMOF','VMOF']
avar3d = ['HGTS','TEMP','WWND','UWND','VWND','RELH']
#--- Add DIFF fields - difference between the original data and the packed data
avar3d_diff = list(avar3d)
avar3d_diff.append('DIFW')
#---- Set parameters of ARL data file
gv = infn3d['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.setlevels(levels)
arlf.set2dvar(avar2d)
for l in levels:
arlf.set3dvar(avar3d_diff)
arlf.setx(gv.dimvalue(gv.ndim - 1))
arlf.sety(gv.dimvalue(gv.ndim - 2))
#---- Write ARL data file
tNum = infn3d.timenum()
fhour = 0
for t in range(0, tNum):
print 'Time index: ' + str(t)
atime = infn3d.gettime(t)
print atime.strftime('%Y-%m-%d %H:00')
dhead = arlf.getdatahead(infn3d.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):
gdata = infn2d[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,llidx)
for avname,gvname in zip(avar3d, gvar3d):
gdata = infn3d[gvname][t,llidx,:,:]
if avname == 'WWND':
gdata = gdata * 0.01
difw = arlf.diff_origin_pack(gdata)
elif avname == 'SPHU':
gdata = gdata * 1000.
elif avname == 'HGTS':
gdata = gdata / 9.80665
ksum = arlf.writedatarec(atime, lidx + 1, avname, fhour, 99, gdata)
ksums.append(ksum)
ksum = arlf.writedatarec(atime, lidx + 1, 'DIFW', fhour, 99, difw)
ksums.append(ksum)
ksumlist.append(ksums)
#Re-write index record with checksum
arlf.writeindexrec(atime, dhead, ksumlist)
fhour += 1
arlf.close()
print 'Finished!'
下面是出错的地方,试着改了53行(标红的地方),加了ksums也不行。不知道还能怎么改。
GRIB data file has been opened...
Time index: 0
2019-01-01 00:00
Traceback (most recent call last):
File "<iostream>", line 53, in <module>
File "D:\software\MeteoInfo\pylib\mipylib\dataset\dimdatafile.py", line 434, in writeindexrec
self.arldata.writeIndexRecord(t, datahead, ksums)
at org.meteoinfo.data.meteodata.arl.ARLDataInfo.writeIndexRecord(ARLDataInfo.java:1785)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
java.lang.NegativeArraySizeException: java.lang.NegativeArraySizeException
|
|