爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 2658|回复: 0

grib2转arl,结果错误,求王老师指点!

[复制链接]

新浪微博达人勋

发表于 2016-8-3 15:35:53 | 显示全部楼层 |阅读模式

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

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

x
  1. #--------------------------------------------------------
  2. # Author: Yaqiang Wang
  3. # Date: 2016-2-4
  4. # Purpose: Convert GRIB data to ARL data
  5. # Note: Sample
  6. #-----------------------------------------------------------
  7. #---- Set data folder
  8. datadir = 'D:/Temp'
  9. #---- Set output data file
  10. outfn = os.path.join(datadir, 'arl/fnl_20150218_06_00.grib2.arl')
  11. #if os.path.exists(outfn):
  12. # os.remove(outfn)
  13. #---- Read a GRIB data file
  14. infn = os.path.join(datadir, 'grib/fnl_20150218_06_00.grib2')
  15. print infn
  16. inf = addfile(infn)
  17. print 'GRIB data file has been opened...'
  18. #---- Set output ARL data file
  19. arlf = addfile(outfn, 'c', dtype='arl')
  20. #---- Set variable and level list
  21. gvar2d = ['Pressure_surface','Temperature_surface','u-component_of_wind_height_above_ground',\
  22. 'v-component_of_wind_height_above_ground']
  23. gvar3d = ['Geopotential_height_isobaric','Temperature_isobaric',\
  24. 'u-component_of_wind_isobaric','v-component_of_wind_isobaric',\
  25. 'Vertical_velocity_pressure_isobaric','Relative_humidity_isobaric']
  26. avar2d = ['PRSS','T02M','U10M','V10M']
  27. avar3d = ['HGTS','TEMP','UWND','VWND','WWND','RELH']
  28. gv = inf['Vertical_velocity_pressure_isobaric']
  29. nx = gv.dimlen(gv.ndim - 1)
  30. ny = gv.dimlen(gv.ndim - 2)
  31. levels = gv.dimvalue(gv.ndim - 3)[::-1]
  32. #levels = [100000,97500,95000,92500,90000,85000,80000,75000,70000,\
  33. # 65000,60000,55000,50000,45000,40000,35000,30000,25000,20000,15000,10000]
  34. nz = len(levels)
  35. arlf.setlevels(levels)
  36. arlf.set2dvar(avar2d)
  37. for l in levels:
  38. arlf.set3dvar(avar3d)

  39. #---- Write ARL data file
  40. arlf.setx(gv.dimvalue(gv.ndim - 1))
  41. arlf.sety(gv.dimvalue(gv.ndim - 2))
  42. tNum = inf.timenum()
  43. fhour = 0
  44. for t in range(0, tNum):
  45. print 'Time index: ' + str(t)
  46. atime = inf.gettime(t)
  47. print atime.strftime('%Y-%m-%d %H:00')
  48. dhead = arlf.getdatahead(inf.proj, 'RSMC', 2, fhour)
  49. #Pre-write index record without checksum - will be over-write latter
  50. arlf.writeindexrec(atime, dhead)
  51. #Checksum list
  52. ksumlist = []
  53. # Write 2d variables
  54. ksums = []
  55. for avname,gvname in zip(avar2d, gvar2d):
  56. print avname + ' ' + gvname
  57. if avname == 'U10M' or avname == 'V10M':
  58. gdata = inf[gvname][t,0,:,:]
  59. else:
  60. gdata = inf[gvname][t,:,:]
  61. if avname == 'PRSS':
  62. gdata = gdata * 0.01
  63. ksum = arlf.writedatarec(atime, 0, avname, fhour, 99, gdata)
  64. ksums.append(ksum)
  65. ksumlist.append(ksums)
  66. # Write 3d variables
  67. for lidx in range(0, nz):
  68. ksums = []
  69. llidx = nz - lidx - 1
  70. # print nz
  71. print lidx
  72. print llidx
  73. for avname,gvname in zip(avar3d, gvar3d):
  74. print avname + ' ' + gvname
  75. gdata = inf[gvname][t,llidx,:,:]
  76. print gdata
  77. if avname == 'WWND':
  78. gdata = gdata * 0.01
  79. ksum = arlf.writedatarec(atime, lidx + 1, avname, fhour, 99, gdata)
  80. ksums.append(ksum)
  81. ksumlist.append(ksums)
  82. #Re-write index record with checksum
  83. arlf.writeindexrec(atime, dhead, ksumlist)
  84. fhour += 1
  85. arlf.close()
  86. print 'Finished!'
复制代码
王老师,程序脚本运行正常,三维的数据输出错误!gdata貌似有问题。有时间能帮忙看一下吗?另外,ARL数据写入有什么单位、顺序等要求吗?
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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