- 积分
- 2281
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-9-11
- 最后登录
- 1970-1-1
|
发表于 2017-2-17 16:21:50
|
显示全部楼层
本帖最后由 良辰 于 2017-2-17 16:23 编辑
王老师,学生又有一个问题。想在tdump写入的时候,将气压一列替换为湿位涡。使用replace好像没有这个函数。想咨询一下王老师,怎么能实现。就是不改变原轨迹数据格式,只是替换一下气压列。错误行为39行。
- # Get meteorological data along trajectory
- print 'Get meteorological data along trajectory...'
- # Open trjactory data file
- print 'Open trajectory data file ...'
- trajfn = os.path.join(trajDir, 'tdump42.5122.5500_2009070312')
- print 'Trajectory file: ' + trajfn
- trajf = addfile_hytraj(trajfn)
- # Create trajectory layer
- trajLayer = trajf.trajlayer()
- # Get meteorological data along trajectory
- print 'Get meteorological data along trajectory...'
- outfn = os.path.join(trajDir, 'tdump42.5122.5500_2009070312.txt')
- inf = open(trajfn, 'r')
- outf = open(outfn, 'w')
- lnum = 0
- for line in inf:
- lnum += 1;
- if (lnum >= 1) & (lnum <= 16):
- print line
- outf.write(line)
- idx = 0
- for tline in trajLayer.shapes():
- t = trajLayer.cellvalue('Date', idx)
- h = trajLayer.cellvalue('Hour', idx)
- t.replace(hour=h)
- for ps in tline.getPoints():
- lon = ps.X
- lat = ps.Y
- z = ps.M
- pres = ps.Z
- #if pressure below 975,mpv nan
- if pres > 975:
- press=975
- else:
- press=ps.Z
- v = vort.interpn([t,pres,lat,lon])
- ww = mpv.interpn([t,press,lat,lon])
- temp = t0.interpn([t,pres,lat,lon])
- line = tline.replace(pres,ww)
- outf.write(line + '\n')
- t = t + datetime.timedelta(hours=-1)
- idx += 1
- outf.close()
- inf.close()
- print 'Finish...'
复制代码
|
|