爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 2572|回复: 0

MeteoInfo脚本教程(八):U/V格点数据

[复制链接]

新浪微博达人勋

发表于 2014-12-1 21:41:01 | 显示全部楼层 |阅读模式

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

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

x
风场的表达需要两个变量:U/V或者风速/风向。模式通常会输出风场的U/V分量,可以绘制风场矢量图、风向杆图和流场图,分别用DrawMeteoData的下面方法:

    DrawMeteoData.createGridVectorLayer(GridData udata, GridData vdata,  String layerName, Boolean isUV)
    DrawMeteoData.createGridBarbLayer(GridData udata, GridData vdata,  String layerName, Boolean isUV)
    DrawMeteoData.createStreamlineLayer(GridData udata, GridData vdata,  String layerName, Boolean isUV)


示例脚本如下:
  1. #-----------------------------------------------------
  2. # Author: Yaqiang Wang
  3. # Date: 2014-12-1
  4. # Purpose: Read and plot U/V grid data
  5. # Note: Sample
  6. #-----------------------------------------------------
  7. #---- Import classes
  8. print 'Import classes...'
  9. from org.meteoinfo.layout import MapLayout
  10. from org.meteoinfo.data.mapdata import MapDataManage
  11. from org.meteoinfo.data.meteodata import MeteoDataInfo, DrawMeteoData
  12. from org.meteoinfo.layout import LegendStyles
  13. from org.meteoinfo.global import Extent
  14. import os
  15. from java.awt import Color
  16. from javax.swing import JFrame

  17. #---- Set directories
  18. print 'Set directories...'
  19. baseDir = 'D:/MyProgram/Distribution/java/MeteoInfo/MeteoInfo'
  20. dataDir = os.path.join(baseDir, 'sample')
  21. mapDir = os.path.join(baseDir, 'map')

  22. #---- Create MapLayout object
  23. mapLayout = MapLayout()
  24. mapFrame = mapLayout.getActiveMapFrame()

  25. #---- Load country layer
  26. print 'Load country layer...'
  27. countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
  28. lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
  29. lb.setDrawFill(False)
  30. lb.setOutlineColor(Color.black)
  31. mapFrame.addLayer(countryLayer)

  32. #---- Create MeteoDataInfo object
  33. mdi = MeteoDataInfo()

  34. #---- Open a GrADS data file
  35. fn = os.path.join(dataDir, 'GrADS/model.ctl')
  36. mdi.openGrADSData(fn)

  37. #---- Get U/V grid data
  38. mdi.setTimeIndex(2)
  39. mdi.setLevelIndex(3)
  40. udata = mdi.getGridData('U')
  41. vdata = mdi.getGridData('V')

  42. #---- Create shaded layer from the grid data
  43. layer = DrawMeteoData.createGridVectorLayer(udata, vdata,  'UV_Vector', True)
  44. #layer = DrawMeteoData.createGridBarbLayer(udata, vdata,  'UV_Barb', True)
  45. #layer = DrawMeteoData.createStreamlineLayer(udata, vdata, 'Z_Streamline', True)

  46. #---- Add layer
  47. mapFrame.addLayer(layer)

  48. #--- Move pressure layer to bottom
  49. mapFrame.moveLayer(layer, 0)

  50. #---- Add title
  51. title = mapLayout.addText('MeteoInfo script demo', 350, 30, 'Arial', 16)

  52. #---- Zoom layout map
  53. print 'Zoom layout map...'
  54. mapLayout.getActiveLayoutMap().zoomToExtentLonLatEx(Extent(70, 140, 15, 55))

  55. #---- Set mapframe
  56. mapFrame.setGridXDelt(10)
  57. mapFrame.setGridYDelt(10)

  58. frame = JFrame('MeteoInfo Script Sample', size = (800, 600))
  59. frame.add(mapLayout)
  60. frame.visible = True
  61. print 'Finished!'




Image00069.png



MapLayout的addWindArrow(int left, int top)方法可以添加风矢量箭头图例:
  1. #-----------------------------------------------------
  2. # Author: Yaqiang Wang
  3. # Date: 2014-12-1
  4. # Purpose: Read and plot U/V grid data
  5. # Note: Sample
  6. #-----------------------------------------------------
  7. #---- Import classes
  8. print 'Import classes...'
  9. from org.meteoinfo.layout import MapLayout
  10. from org.meteoinfo.data.mapdata import MapDataManage
  11. from org.meteoinfo.data.meteodata import MeteoDataInfo, DrawMeteoData
  12. from org.meteoinfo.layout import LegendStyles
  13. from org.meteoinfo.global import Extent
  14. import os
  15. from java.awt import Color
  16. from javax.swing import JFrame

  17. #---- Set directories
  18. print 'Set directories...'
  19. baseDir = 'D:/MyProgram/Distribution/java/MeteoInfo/MeteoInfo'
  20. dataDir = os.path.join(baseDir, 'sample')
  21. mapDir = os.path.join(baseDir, 'map')

  22. #---- Create MapLayout object
  23. mapLayout = MapLayout()
  24. mapFrame = mapLayout.getActiveMapFrame()

  25. #---- Load country layer
  26. print 'Load country layer...'
  27. countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
  28. lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
  29. lb.setDrawFill(False)
  30. lb.setOutlineColor(Color.black)
  31. mapFrame.addLayer(countryLayer)

  32. #---- Create MeteoDataInfo object
  33. mdi = MeteoDataInfo()

  34. #---- Open a GrADS data file
  35. fn = os.path.join(dataDir, 'GrADS/model.ctl')
  36. mdi.openGrADSData(fn)

  37. #---- Get U/V grid data
  38. mdi.setTimeIndex(2)
  39. mdi.setLevelIndex(3)
  40. udata = mdi.getGridData('U')
  41. vdata = mdi.getGridData('V')

  42. #---- Create wind vector layer from the U/V grid data
  43. layer = DrawMeteoData.createGridVectorLayer(udata, vdata,  'UV_Vector', True)

  44. #---- Add layer
  45. mapFrame.addLayer(layer)

  46. #--- Move pressure layer to bottom
  47. mapFrame.moveLayer(layer, 0)

  48. #---- Add title
  49. title = mapLayout.addText('MeteoInfo script demo', 350, 30, 'Arial', 16)

  50. #---- Add wind arrow
  51. windArrow = mapLayout.addWindArrow(660, 420)

  52. #---- Zoom layout map
  53. print 'Zoom layout map...'
  54. mapLayout.getActiveLayoutMap().zoomToExtentLonLatEx(Extent(70, 140, 15, 55))

  55. #---- Set mapframe
  56. mapFrame.setGridXDelt(10)
  57. mapFrame.setGridYDelt(10)

  58. frame = JFrame('MeteoInfo Script Sample', size = (800, 600))
  59. frame.add(mapLayout)
  60. frame.visible = True
  61. print 'Finished!'




Image00070.png

本帖被以下淘专辑推荐:

密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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