zoukankan      html  css  js  c++  java
  • MeteoInfoLab脚本示例:获取气团轨迹每个节点的气象数据

    读取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
    ')
    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 + '
    ')
            t = t + datetime.timedelta(hours=-1)
        idx += 1
    
    outf.close()
    print 'Finish...'

  • 相关阅读:
    P1281 书的复制 dp
    P3402 最长公共子序列(nlogn)
    P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers
    P1202 黑色星期五
    P1205 方块转换
    [递推] hihocoder 1239 Fibonacci
    [二分] hihoCoder 1269 优化延迟
    [分治] POJ 3233 Matrix Power Series
    使用HTMLParser解析html
    CSAPP2e: Proxy lab 解答
  • 原文地址:https://www.cnblogs.com/yaqiang/p/4852094.html
Copyright © 2011-2022 走看看