码迷,mamicode.com
首页 > 其他好文 > 详细

MeteoInfoLab脚本示例:获取气团轨迹每个节点的气象数据

时间:2015-10-02 12:34:01      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:

读取HYSPLIT输出的轨迹数据文件和相应时间的气象数据文件,生成轨迹图层,循环每条轨迹的节点,读出该节点的经度、纬度、气压、时间,通过对气象数据插值获得该节点的气象数据。

脚本程序:

#-----------------------------------------------------
# Author: Yaqiang Wang
# Date: 2015-9-30
# Purpose: Get meteorological data along trajectory
# Note: Sample
#-----------------------------------------------------

# Set working directory
trajDir = D:/Temp/HYSPLIT
meteoDir = D:/Temp/arl

# Open trjactory data file
print Open trajectory data file ...
trajfn = os.path.join(trajDir, traj_20090731)
print Trajectory file:  + trajfn
trajf = addfile_hytraj(trajfn)
# Create trajectory layer
trajLayer = trajf.trajlayer()

# Open meteorological data file
print Open meteorological data file...
meteofn = os.path.join(meteoDir, gdas1.jul09.w5)
print Meteorological file:  + meteofn
meteof = addfile(meteofn)

# Get meteorological data along trajectory
print Get meteorological data along trajectory...
outfn = os.path.join(trajDir, pblh_traj.txt)
outf = open(outfn, w)
outf.write(Lon,Lat,Time,Heigh,PBLH,UWND\n)
pblvar = PBLH
uvar = UWND
idx = 0
for tline in trajLayer.shapes():
    t = trajLayer.cellvalue(StartDate, idx)
    h = trajLayer.cellvalue(StartHour, idx)    
    t.replace(hour=h)
    for ps in tline.getPoints():
        lon = ps.X
        lat = ps.Y 
        z = ps.M
        pres = ps.Z
        pbl = meteof.tostation(pblvar, lon, lat, None, t)
        uwnd = meteof.tostation(uvar, lon, lat, pres, t)
        print lon: %.2f; lat: %.2f; time: %s; height: %.2f; PBLH: %.2f; UWND: %.2f % (lon, lat, t.strftime(%Y%m%d_%H:%M), z, pbl, uwnd)
        line = %.4f,%.4f,%s,%.2f,%.2f,%.2f % (lon,lat,t.strftime(%Y%m%d_%H:%M),z,pbl,uwnd)
        outf.write(line + \n)
        t = t + datetime.timedelta(hours=-1)
    idx += 1

outf.close()
print Finish...

技术分享

MeteoInfoLab脚本示例:获取气团轨迹每个节点的气象数据

标签:

原文地址:http://www.cnblogs.com/yaqiang/p/4852094.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!