- 积分
- 55940
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
运行MM5模式需要更大范围边界气象场的驱动,T639是目前中国气象局一个比较好的业务数据源,T639是GRIB2格式,需要转换为MM5的中间文件格式。MeteoInfo Java版支持MM5输出和中间文件格式,可以通过写脚本来方便的进行批量转换,并可以通过定时提交作业自动运行,满足业务预报的需求。
示例脚本如下:
- #--------------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2014-5-8
- # Purpose: Convert GRIB data to MM5 intermediate data
- # Note: Sample
- #-----------------------------------------------------------
- from org.meteoinfo.data.meteodata import MeteoDataInfo
- from org.meteoinfo.data.meteodata.mm5 import MM5IMDataInfo
- from org.meteoinfo.data.meteodata import Variable
- from org.meteoinfo.data.meteodata.mm5 import DataHead
- import os
- import datetime
- #---- Define convert function
- def convert(inDir, outDir, sdate, fhour):
- hdate = sdate + datetime.timedelta(hours=fhour)
- hdatestr = hdate.strftime('%Y-%m-%d_%H:00:00')
- print hdatestr
- #---- Set intput and output data file
- infn = os.path.join(inDir, 'gmf.639.' + sdate.strftime('%Y%m%d%H') + \
- '%03d.grb2'%fhour)
- print 'T639 file: ' + infn
- outfn = os.path.join(outDir, 'T639_' + sdate.strftime('%Y-%m-%d') + '_%02d'%fhour)
- print 'MM5 intermediate file: ' + outfn
- #---- Read a GRIB data file
- mydata = MeteoDataInfo()
- mydata.openNetCDFData(infn)
- print 'GRIB file has been opened...'
- #---- Set output MM5 intermediate data info
- mm5DI = MM5IMDataInfo()
- #---- Set variable and level list
- gvars = ['Geopotential_height_isobaric','Temperature_isobaric',\
- 'u-component_of_wind_isobaric','v-component_of_wind_isobaric',\
- 'Relative_humidity_isobaric','Pressure_reduced_to_MSL_msl',\
- 'Temperature_surface']
- mvars = ['HGT','T','U','V','RH','PMSL','SST']
- units = ['m','K','m s{-1}','m s{-1}','%','Pa','K']
- descs = ['Height','Temperature','U','V','Relative Humidity',\
- 'Sea-level Pressure','Sea-surface Temperature']
- #---- Write MM5 intermediate data file
- dataInfo = mydata.getDataInfo()
- mm5DI.createDataFile(outfn)
- vNum = len(gvars)
- for i in range(0, vNum):
- #Read input grid data
- varName = gvars
- print 'Variable: ' + mvars
- var = dataInfo.getVariable(varName)
- levNum = var.getLevelNum()
- print 'Level number: ' + str(levNum)
- for l in range(0, levNum):
- mydata.setLevelIndex(l)
- gData = mydata.getGridData(varName)
- dh = DataHead()
- dh.iversion = 3
- dh.hdate = hdatestr
- dh.xfcst = 0.0
- dh.field = mvars
- dh.units = units
- dh.desc = descs
- if levNum <= 1:
- dh.level = 200100.0
- else:
- dh.level = var.getLevels().get(l)
- print 'Level: ' + str(dh.level)
- dh.idim = gData.getXNum()
- dh.jdim = gData.getYNum()
- dh.llflag = 0
- dh.startlat = gData.getYMax()
- dh.startlon = gData.getXMin()
- dh.deltalat = -gData.getYDelt()
- dh.deltalon = gData.getXDelt()
- #Write data
- mm5DI.writeDataHead(dh)
- mm5DI.writeGridData(gData)
- mm5DI.closeDataFile()
- #---- Run program
- #---- Set datetime
- stime = datetime.datetime.now()
- sdate = datetime.datetime.now()
- sdate = sdate.replace(hour=0)
- sdate = sdate - datetime.timedelta(days=2)
- print sdate
- #---- Set directories
- inDir = "D:/Working/MIScript/baoding/rdT639"
- outDir = "D:/Working/MIScript/baoding/rdT639"
- #---- Convert data
- #convert(inDir, outDir, sdate, 18)
- for fhour in range(0, 109, 6):
- convert(inDir, outDir, sdate, fhour)
- print 'Run time: %s'%(datetime.datetime.now() - stime)
- print 'Finished!'
转换前的GRIB2数据图形:
转换后的MM5中间文件数据图形:
|
|