- 积分
- 55965
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
前面讲了格点和站点数据,除此以外轨迹数据也是气象领域常用的数据格式,比如气团轨迹、台风路径等。MeteoInfo目前直接支持MICAPS第7类格式(台风数据)和HYSPLIT模式输出的气团轨迹数据格式。其实数据格式有无数,使用脚本可以自己读各种格式中的轨迹数据。这里演示一个绘制HYSPLIT模式输出气团轨迹的例子。
用MeteoDataInfo类的openHYSPLITTrajData方法打开轨迹数据文件,并获取HYSPLITTrajDataInfo类的对象:
mdi = MeteoDataInfo()
mdi.openHYSPLITTrajData(fn)
dataInfo = mdi.getDataInfo()
利用HYSPLITTrajDataInfo类的createTrajLayer生成气团轨迹线图层,createTrajPointLayer生成气团轨迹点图层,createTrajStartPointLayer生成轨迹起点点图层。
要绘制一维图,首先要构造相应的XY数据(XYDataset类),然后创建XYPlot类对象,再生成Chart类对象,最后在MapLayout中添加一个LayoutChart即可。
脚本代码如下:
- #-----------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2014-12-19
- # Purpose: Plot HYSPLIT trajectory data
- # Note: Sample
- #-----------------------------------------------------
- #---- Import classes
- print 'Import classes...'
- from org.meteoinfo.layout import MapLayout, PaperSize
- from org.meteoinfo.data.mapdata import MapDataManage
- from org.meteoinfo.data.meteodata import MeteoDataInfo
- from org.meteoinfo.global import Extent
- from org.meteoinfo.drawing import PointStyle
- from org.meteoinfo.chart import Chart
- from org.meteoinfo.chart.plot import XYPlot, ChartPlotMethod
- import os
- from java.awt import Color
- from javax.swing import JFrame
- #---- Set directories
- print 'Set directories...'
- baseDir = 'D:/MyProgram/Distribution/java/MeteoInfo/MeteoInfo'
- dataDir = os.path.join(baseDir, 'sample')
- mapDir = os.path.join(baseDir, 'map')
- figDir = 'D:/Temp/test'
- #---- Create MapLayout object
- mapLayout = MapLayout()
- mapFrame = mapLayout.getActiveMapFrame()
- ps = PaperSize('Custum', 650, 640)
- mapLayout.setPaperSize(ps)
- #---- Load country layer
- print 'Load country layer...'
- countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
- lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
- lb.setOutlineColor(Color.black)
- lb.setOutlineSize(2)
- mapFrame.addLayer(countryLayer)
- #---- Create MeteoDataInfo object
- mdi = MeteoDataInfo()
- #---- Open a trajectory data file
- print 'Open trajectory data file...'
- fn = os.path.join(dataDir, 'HYSPLIT/tdump')
- mdi.openHYSPLITTrajData(fn)
- dataInfo = mdi.getDataInfo()
- #---- Create trajectory layers
- print 'Create trajectory layers...'
- trajLayer = dataInfo.createTrajLineLayer()
- startLayer = dataInfo.createTrajStartPointLayer()
- lb = startLayer.getLegendScheme().getLegendBreaks().get(0)
- lb.setStyle(PointStyle.Star)
- #---- Add layer
- mapFrame.addLayer(trajLayer)
- mapFrame.addLayer(startLayer)
- #---- Add pressure profile chart
- print 'Add pressure profile chart...'
- dataset = dataInfo.getXYDataset(12) #Pressure is in 12th column
- plot = XYPlot(True, dataset)
- plot.setChartPlotMethod(ChartPlotMethod.LINE_POINT)
- plot.getXAxis().setLabel('Time')
- plot.getYAxis().setLabel('hPa')
- plot.getYAxis().setInverse(True)
- ls = trajLayer.getLegendScheme()
- for i in range(0, dataset.getSeriesCount()):
- plot.setPolylineBreak(i, ls.getLegendBreaks().get(i))
- chart = Chart(None, plot)
- chart.setDrawLegend(False)
- layoutChart = mapLayout.addChart(10, 410)
- layoutChart.setWidth(590)
- layoutChart.setHeight(200)
- layoutChart.setChart(chart)
- #---- Add title
- title = mapLayout.addText('MeteoInfo script demo - Trajectory', 300, 30, 'Arial', 16)
- #---- Zoom map
- print 'Zoom map...'
- mapLayout.getActiveLayoutMap().setWidth(550)
- mapLayout.getActiveLayoutMap().setHeight(350)
- mapFrame.getMapView().zoomToExtent(trajLayer.getExtent().extend(2, 2))
- #---- Output figure
- print 'Output figure...'
- mapLayout.exportToPicture(os.path.join(figDir, 'traj_test.png'))
- #---- Set mapframe
- mapFrame.setGridXDelt(5)
- mapFrame.setGridYDelt(5)
- frame = JFrame('MeteoInfo Script Sample', size = (650, 680))
- frame.add(mapLayout)
- frame.visible = True
- print 'Finish...'
运行结果:
|
|