爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 2789|回复: 3

王老师,关于HYSPLIT trajectory model 脚本

[复制链接]

新浪微博达人勋

发表于 2017-12-3 22:19:42 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
#-----------------------------------------------------# Author: Yaqiang Wang
# Date: 2015-9-30
# Purpose: Run HYSPLIT trajectory model - days
# Note: Sample
#-----------------------------------------------------
# Set working directory
metDir = 'C:/Users/ASUS/Desktop/cs'
outDir = 'C:/Users/ASUS/Desktop/jg'
workingDir = 'C:/hysplit4/working'
os.chdir(workingDir)
print 'Current directory: ' + os.getcwd()
# Set parameters
lon = '115.2'
lat = '40.1'
shour = '06'
heights = ['100.0','500.0','1000.0']
hnum = len(heights)
hours = '-24'
vertical = '0'
top = '10000.0'
# 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(t):
    y = t.year
    ystr = t.strftime('%y')
    m = t.month
    mmm = getmonthstr(m)
    fns = []
    # The meteo files of this month
    for i in range(1,6):
        fn = 'gdas1.' + mmm + ystr + '.w' + str(i)
        if os.path.exists(os.path.join(metDir, fn)):
            fns.append(fn)
    # The last two meteo files of last month
    m = m - 1
    if m == 0:
        m = 12
        ystr = str(y - 1)[2:]
    mmm = getmonthstr(m)
    fn = 'gdas1.' + mmm + ystr + '.w4'
    fns.append(fn)
    fn = 'gdas1.' + mmm + ystr + '.w5'
    if os.path.exists(os.path.join(metDir, fn)):
        fns.append(fn)
    else:
        fns.append('gdas1.' + mmm + ystr + '.w3')
    return fns
# Set start/end time
import datetime
stime = datetime.datetime(2013,7,10)
etime = datetime.datetime(2013,7,20)
# Loop
ctFile = './CONTROL'
while stime <= etime:
    print stime.strftime('%Y-%m-%d ') + shour + ':00'
    ctf = open(ctFile, 'w')
    ctf.write(stime.strftime('%y %m %d ') + shour + "\n")
    ctf.write(str(hnum) + '\n')
    for j in range(0,hnum):
        ctf.write(lat + ' ' + lon + ' ' + heights[j] + '\n')
    ctf.write(hours + '\n')
    ctf.write(vertical + '\n')
    ctf.write(top + '\n')
    fns = getmeteofiles(stime)
    fnnum = len(fns)
    ctf.write(str(fnnum) + '\n')
    for j in range(0,fnnum):
        ctf.write(metDir + '/' + '\n')
        ctf.write(fns[j] + '\n')
    ctf.write(outDir + '/' + '\n')
    outfn = stime.strftime('traj_%Y%m%d')
    ctf.write(outfn)
    ctf.close()
    os.system('c:/hysplit4/exec/hyts_std.exe')
    stime = stime + datetime.timedelta(days=1)
print 'Finish...'


这是我参照老师您的脚本编写的计算气团轨迹,没有报错,可是不知道为啥没有生成文件


QQ图片20171205204708.png (这是我的测试所用的arl数据,测试时间是2013,7,10-7,20)

谢谢老师您的解答!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-12-6 09:31:06 | 显示全部楼层
你看看CONTROL文件里的内容
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2017-12-6 09:48:49 | 显示全部楼层
MeteoInfo 发表于 2017-12-6 09:31
你看看CONTROL文件里的内容

谢谢老师,我找到原因了,这个脚本需要上个月前两个周的数据
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2017-12-6 09:48:54 | 显示全部楼层
MeteoInfo 发表于 2017-12-6 09:31
你看看CONTROL文件里的内容

谢谢老师,我找到原因了,这个脚本需要上个月前两个周的数据
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表