登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
利用HYSPLIT GUI或者TrajStat可以一次计算一个月的气团轨迹,但对于要大批量计算长时间序列的轨迹来说还是不够方便。这里给出一个能够一次计算一年轨迹的脚本,会极大地减少工作量。需要最新的MeteoInfo Java版软件和TrajStat Java版plugin。
- #-----------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2014-7-11
- # Purpose: Run TrajStat - calculate trajectories
- # Note: Sample
- #-----------------------------------------------------
- import sys
- sys.path.append('D:/MyProgram/java/MeteoInfoDev/MeteoInfo/plugins/TrajStat/TrajStat.jar')
- import os
- import time
- from datetime import datetime
- from datetime import timedelta
- from calendar import monthrange
- from trajstat.trajectory import TrajUtil
- from trajstat.trajectory import TrajConfig
- # Set working directory
- metDir = 'P:/MetData/MetData'
- outDir = 'O:/trajectory/bishkek/trajdata'
- # Get month abstract string
- def getmonthstr(m):
- mmm = 'jan'
- if m == 1:
- mmm = 'jan'
- elif m == 2:
- mmm = 'feb'
- elif m == 3:
- mmm = 'mar'
- elif m == 4:
- mmm = 'apr'
- elif m == 5:
- mmm = 'may'
- elif m == 6:
- mmm = 'jun'
- elif m == 7:
- mmm = 'jul'
- elif m == 8:
- mmm = 'aug'
- elif m == 9:
- mmm = 'sep'
- elif m == 10:
- mmm = 'oct'
- elif m == 11:
- mmm = 'nov'
- elif m == 12:
- mmm = 'dec'
- return mmm
- # Get GDAS1 meteorological data files by time
- def getmeteofiles(y, m):
- ystr = str(y)[2:]
- mmm = getmonthstr(m)
- fns = []
- # The meteo files of this month
- cdir = os.path.join(metDir, str(y))
- for i in range(1,6):
- fn = os.path.join(cdir, 'gdas1.' + mmm + ystr + '.w' + str(i))
- if os.path.exists(fn):
- fns.append(fn)
- # The last two meteo files of last month
- m = m - 1
- if m == 0:
- m = 12
- y = y - 1
- ystr = str(y)[2:]
- cdir = os.path.join(metDir, str(y))
- mmm = getmonthstr(m)
- fn = os.path.join(cdir, 'gdas1.' + mmm + ystr + '.w4')
- fns.append(fn)
- fn = os.path.join(cdir, 'gdas1.' + mmm + ystr + '.w5')
- if not os.path.exists(fn):
- fn = os.path.join(cdir, 'gdas1.' + mmm + ystr + '.w3')
- fns.append(fn)
- return fns
- # Set parameters
- print 'Set paramters...'
- year = 2011
- tc = TrajConfig()
- tc.setStartDay(1)
- tc.setStartHours('00 06 12 18')
- tc.setLocation('42.68 74.69 1000.00')
- tc.setRunHours(-96)
- tc.setTopOfModel(10000.0)
- tc.setVertical(0)
- tc.setOutPath(outDir)
- # Loop - one year calculation
- print 'Trajectory calculation...'
- for month in range(1, 13):
- print 'Month: ' + str(month)
- eday = monthrange(year, month)[1]
- tc.setEndDay(eday)
- tc.initStartTime(year, month)
- fns = getmeteofiles(year, month)
- tc.setMeteoFiles(fns)
- #TrajUtil.trajCal(tc)
- print 'Convert trajectory endpoint files to tgs files...'
- TrajUtil.trajToTGS(tc)
- print 'Join tgs files...'
- tgsfn = TrajUtil.joinTGSFiles(tc)
- print 'Convert tgs file to shape file...'
- shpfn = tgsfn.replace('.tgs','.shp')
- TrajUtil.convertToShapeFile(tgsfn, shpfn)
- print 'Remove trajectory files...'
- TrajUtil.removeTrajFiles(tc)
- print 'Finish !'
|