- 积分
- 2280
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-9-11
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
- #--------------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2016-2-4
- # Purpose: Convert GRIB data to ARL data
- # Note: Sample
- #-----------------------------------------------------------
- #---- Set data folder
- datadir = 'D:/Temp'
- #---- Set output data file
- outfn = os.path.join(datadir, 'arl/fnl_20150218_06_00.grib2.arl')
- #if os.path.exists(outfn):
- # os.remove(outfn)
- #---- Read a GRIB data file
- infn = os.path.join(datadir, 'grib/fnl_20150218_06_00.grib2')
- 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 = ['Pressure_surface','Temperature_surface','u-component_of_wind_height_above_ground',\
- 'v-component_of_wind_height_above_ground']
- gvar3d = ['Geopotential_height_isobaric','Temperature_isobaric',\
- 'u-component_of_wind_isobaric','v-component_of_wind_isobaric',\
- 'Vertical_velocity_pressure_isobaric','Relative_humidity_isobaric']
- avar2d = ['PRSS','T02M','U10M','V10M']
- avar3d = ['HGTS','TEMP','UWND','VWND','WWND','RELH']
- gv = inf['Vertical_velocity_pressure_isobaric']
- nx = gv.dimlen(gv.ndim - 1)
- ny = gv.dimlen(gv.ndim - 2)
- levels = gv.dimvalue(gv.ndim - 3)[::-1]
- #levels = [100000,97500,95000,92500,90000,85000,80000,75000,70000,\
- # 65000,60000,55000,50000,45000,40000,35000,30000,25000,20000,15000,10000]
- nz = len(levels)
- arlf.setlevels(levels)
- arlf.set2dvar(avar2d)
- 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 nz
- print lidx
- print llidx
- for avname,gvname in zip(avar3d, gvar3d):
- print avname + ' ' + gvname
- gdata = inf[gvname][t,llidx,:,:]
- print gdata
- if avname == 'WWND':
- gdata = gdata * 0.01
- 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!'
复制代码 王老师,程序脚本运行正常,三维的数据输出错误!gdata貌似有问题。有时间能帮忙看一下吗?另外,ARL数据写入有什么单位、顺序等要求吗?
|
|