爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
楼主: MeteoInfo

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

[复制链接]

新浪微博达人勋

发表于 2016-8-8 16:15:28 | 显示全部楼层
MeteoInfo 发表于 2016-8-5 16:45
参考此贴:MeteoInfoLab脚本示例:计算涡度并插值
http://bbs.06climate.com/forum.php?mod=viewthread& ...
  1. # Set working directory
  2. trajDir = 'D:/Temp/HYSPLIT'
  3. meteoDir = r'D:\Temp\arl'
  4. # Open trjactory data file
  5. print 'Open trajectory data file ...'
  6. trajfn = os.path.join(trajDir, 'traj_20150331')
  7. print 'Trajectory file: ' + trajfn
  8. trajf = addfile_hytraj(trajfn)
  9. # Create trajectory layer
  10. trajLayer = trajf.trajlayer()
  11. # Open meteorological data file
  12. print 'Open meteorological data file...'
  13. meteofn = os.path.join(meteoDir, 'gdas1.mar15.w5')
  14. print 'Meteorological file: ' + meteofn
  15. meteof = addfile(meteofn)
  16. # Get meteorological data along trajectory
  17. print 'Get meteorological data along trajectory...'
  18. outfn = os.path.join(trajDir, 'traj.txt')
  19. outf = open(outfn, 'w')
  20. outf.write('Lon,Lat,Time,Heigh,pres,TEMP,RELH,VORT,DIVG,es\n')
  21. #uwnd = meteof['UWND'][:,:,:,:]
  22. #vwnd = meteof['VWND'][:,:,:,:]
  23. tvar = 'TEMP'
  24. rhvar = 'RELH'
  25. uwnd = meteof['UWND'][:,:,[10, 80],[50,140]]
  26. vwnd = meteof['VWND'][:,:,[10, 80],[50,140]]
  27. vort = hcurl(uwnd, vwnd)
  28. divg = hdivg(uwnd, vwnd)

  29. #######假相当位温的计算#####
  30. es = 6.1078*exp(17.2693882*(tvar-273.16)/(tvar-35.86))
  31. qq = rvar*(0.62197*es/(prs-0.378*es))/100.
  32. e = prs*qq/(0.62197+qq)+1e-10
  33. tlcl = 55.0+2840.0/(3.5*log(t0)-log(e)-4.805)
  34. theta = t0*pow((1000/prs),(0.2854*(1.0-0.28*qq)))
  35. eqt = theta*exp(((3376./tlcl)-2.54)*qq*(1.0+0.81*qq))
  36. thse = eqt-273.15
  37. print thse
  38. ###########湿位涡###########grads程序,没有做相应修改###
  39. f = 2*7.292*sin(lat*3.14159/180.0)*0.00001
  40. g = 9.8
  41. dp = 100*(lev(z-1)-lev(z+1))
  42. deqt = eqt(z-1)-eqt(z+1)
  43. du = uwnd(z-1)-uwnd(z+1)
  44. dv = vwnd(z-1)-vwnd(z+1)
  45. dx = 2.0*6370949.0*cos(lat*3.14159/180.0)*3.14159/180.0
  46. dy = 2.0*6370949.0*3.14159/180.0
  47. dtx = cdiff(eqt,x)
  48. dty = cdiff(eqt,y)
  49. pv1 = -g*(vort+f)*deqt/dp  
  50. pv2 = g*((dv/dp)*(dtx/dx)-(du/dp)*(dty/dy))
  51. pv = pv1+pv2

  52. '''
  53. idx = 0
  54. for tline in trajLayer.shapes():   
  55.     t = trajLayer.cellvalue('Date', idx)
  56.     h = trajLayer.cellvalue('Hour', idx)
  57.     t.replace(hour=h)
  58.     for ps in tline.getPoints():  
  59.         lon = ps.X
  60.         lat = ps.Y
  61.         z = ps.M
  62.         pres = ps.Z
  63.         v = vort.interpn([t,pres,lat,lon])
  64.         d = divg.interpn([t,pres,lat,lon])
  65.         temp = meteof.tostation(tvar, lon, lat, pres, t)
  66.         rh = meteof.tostation(rhvar, lon, lat, pres, t)
  67.         es = meteof.tostation(esvar, lon, lat, pres, t)
  68.         print 'lon: %.3f; lat: %.3f; time: %s; height: %.1f; pres: %.1f; TEMP: %.1f;  RELH: %.1f;  VORT: %f; DIVG: %f; es:%f' % (lon,lat,t.strftime('%Y%m%d_%H:%M'),z,pres,temp,rh,v,d,es)
  69.         line = '%.3f,%.3f,%s,%.1f,%.1f,%.1f,%.1f,%f,%f,%f' % (lon,lat,t.strftime('%Y%m%d_%H:%M'),z,pres,temp,rh,v,d,es)
  70.         outf.write(line + '\n')
  71.         t = t + datetime.timedelta(hours=-1)
  72.     idx += 1
  73. outf.close()
  74. print 'Finish...'
复制代码

王老师,我想尝试进行湿位涡的计算和追踪,刚开始调试就出错,饱和水汽压都进行不下去!错误如下:如果王老师有时间帮忙指点!
Traceback (most recent call last):
  File "<iostream>", line 31, in <module>
TypeError: unsupported operand type(s) for -: 'str' and 'float'
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2016-8-8 16:16:30 | 显示全部楼层
良辰 发表于 2016-8-8 16:15
王老师,我想尝试进行湿位涡的计算和追踪,刚开始调试就出错,饱和水汽压都进行不下去!错误如下:如果 ...

tvar是字符串,需要提取温度数据数组参与计算。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-8-9 08:21:46 来自手机 | 显示全部楼层
好的,谢谢老师!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-8-16 09:14:31 | 显示全部楼层
MeteoInfo 发表于 2016-8-8 16:16
tvar是字符串,需要提取温度数据数组参与计算。
  1. # Set working directory
  2. trajDir = 'D:/Temp/HYSPLIT'
  3. meteoDir = r'D:\Temp\arl'
  4. # Open trjactory data file
  5. print 'Open trajectory data file ...'
  6. trajfn = os.path.join(trajDir, 'traj_20150331')
  7. print 'Trajectory file: ' + trajfn
  8. trajf = addfile_hytraj(trajfn)
  9. # Create trajectory layer
  10. trajLayer = trajf.trajlayer()
  11. # Open meteorological data file
  12. print 'Open meteorological data file...'
  13. meteofn = os.path.join(meteoDir, 'gdas1.mar15.w5')
  14. print 'Meteorological file: ' + meteofn
  15. meteof = addfile(meteofn)
  16. # Get meteorological data along trajectory
  17. print 'Get meteorological data along trajectory...'
  18. outfn = os.path.join(trajDir, 'traj.txt')
  19. outf = open(outfn, 'w')
  20. outf.write('Lon,Lat,Time,Heigh,pres,TEMP,RELH,VORT,DIVG,es\n')
  21. #uwnd = meteof['UWND'][:,:,:,:]
  22. #vwnd = meteof['VWND'][:,:,:,:]
  23. tvar = meteof['TEMP'][:,:,:,:]
  24. rhvar = meteof['RELH'][:,:,:,:]
  25. uwnd = meteof['UWND'][:,:,[10, 80],[50,160]]
  26. vwnd = meteof['VWND'][:,:,[10, 80],[50,160]]
  27. gv = meteof['HGTS']
  28. nx = gv.dimlen(gv.ndim - 1)
  29. ny = gv.dimlen(gv.ndim - 2)
  30. levels = gv.dimvalue(gv.ndim - 3)[::1]
  31. prs = levels
  32. #vort = hcurl(uwnd, vwnd)
  33. #divg = hdivg(uwnd, vwnd)

  34. #######假相当位温的计算#####
  35. es = 6.1078*exp(17.2693882*(tvar-273.16)/(tvar-35.86))
  36. print es
  37. '''
  38. qq = rvar*(0.62197*es/(prs-0.378*es))/100.
  39. e = prs*qq/(0.62197+qq)+1e-10
  40. tlcl = 55.0+2840.0/(3.5*log(tvar)-log(e)-4.805)
  41. theta = tvar*pow((1000/prs),(0.2854*(1.0-0.28*qq)))
  42. eqt = theta*exp(((3376./tlcl)-2.54)*qq*(1.0+0.81*qq))
  43. thse = eqt-273.15
  44. print thse
  45. ###########湿位涡###########grads程序,没有做相应修改###
  46. f = 2*7.292*sin(lat*3.14159/180.0)*0.00001
  47. g = 9.8
  48. dp = 100*(lev(z-1)-lev(z+1))
  49. deqt = eqt(z-1)-eqt(z+1)
  50. du = uwnd(z-1)-uwnd(z+1)
  51. dv = vwnd(z-1)-vwnd(z+1)
  52. dx = 2.0*6370949.0*cos(lat*3.14159/180.0)*3.14159/180.0
  53. dy = 2.0*6370949.0*3.14159/180.0
  54. dtx = cdiff(eqt,x)
  55. dty = cdiff(eqt,y)
  56. pv1 = -g*(vort+f)*deqt/dp  
  57. pv2 = g*((dv/dp)*(dtx/dx)-(du/dp)*(dty/dy))
  58. pv = pv1+pv2
  59. '''
  60. idx = 0
  61. for tline in trajLayer.shapes():   
  62.     t = trajLayer.cellvalue('Date', idx)
  63.     h = trajLayer.cellvalue('Hour', idx)
  64.     t.replace(hour=h)
  65.     for ps in tline.getPoints():  
  66.         lon = ps.X
  67.         lat = ps.Y
  68.         z = ps.M
  69.         pres = ps.Z
  70.         v = vort.interpn([t,pres,lat,lon])
  71.         d = divg.interpn([t,pres,lat,lon])
  72. #        temp = meteof.tostation(tvar, lon, lat, pres, t)
  73. #        rh = meteof.tostation(rhvar, lon, lat, pres, t)
  74. #        es = meteof.tostation(esvar, lon, lat, pres, t)
  75.         print 'lon: %.3f; lat: %.3f; time: %s; height: %.1f; pres: %.1f; TEMP: %.1f;  RELH: %.1f;  VORT: %f; DIVG: %f' % (lon,lat,t.strftime('%Y%m%d_%H:%M'),z,pres,temp,rh,v,d)
  76.         line = '%.3f,%.3f,%s,%.1f,%.1f,%.1f,%.1f,%f,%f,%f' % (lon,lat,t.strftime('%Y%m%d_%H:%M'),z,pres,temp,rh,v,d)
  77.         outf.write(line + '\n')
  78.         t = t + datetime.timedelta(hours=-1)
  79.     idx += 1
  80. outf.close()
  81. print 'Finish...'
复制代码

王老师,我想计算位涡。提取温度数据数组参与计算了,但是还是出错,错误如下:
File "<iostream>", line 36, in <module>
  File "D:\Temp\MeteoInfo\pylib\mipylib\dimarray.py", line 210, in __rmul__
    return DimArray.__mul__(self, other)
  File "D:\Temp\MeteoInfo\pylib\mipylib\dimarray.py", line 206, in __mul__
    r = DimArray(self.array.__mul__(other), self.dims, self.fill_value, self.proj)
  File "D:\Temp\MeteoInfo\pylib\mipylib\miarray.py", line 166, in __mul__
    r = MIArray(ArrayMath.mul(self.array, other))
王老师,有时间帮我看一下呗?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2016-8-16 23:12:28 | 显示全部楼层
良辰 发表于 2016-8-16 09:14
王老师,我想计算位涡。提取温度数据数组参与计算了,但是还是出错,错误如下:
File "", line 36, in ...

参考此贴:MeteoInfoLab脚本示例:计算湿位涡
http://bbs.06climate.com/forum.p ... 931&fromuid=106
(出处: 气象家园)

需要下载最新版本的MeteoInfo。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-8-17 16:16:42 | 显示全部楼层
MeteoInfo 发表于 2016-8-16 23:12
参考此贴:MeteoInfoLab脚本示例:计算湿位涡
http://bbs.06climate.com/forum.php?mod=viewthread&tid= ...

非常感谢王老师!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2016-8-17 16:33:24 | 显示全部楼层
良辰 发表于 2016-8-17 16:16
非常感谢王老师!

你那里有条件的话最好验证一下湿位温的计算结果是否正确。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-8-17 16:46:38 | 显示全部楼层
MeteoInfo 发表于 2016-8-17 16:33
你那里有条件的话最好验证一下湿位温的计算结果是否正确。

好的,我有再分析资料画一下,进行对比!我还要计算一下位涡。这几天弄好了,一起发上来!
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-8-18 10:34:49 | 显示全部楼层

哎哟,我羞涩了:$
不过,这里真是一个气象人待下去的家
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-1-8 19:45:17 | 显示全部楼层
@meteoinfo 王老师 做pscf分析的时候我应该怎么求或者怎么在meteoinfo里边看所设网格内所以轨迹点数?
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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