예제 #1
0
 def contour(self, *args, **kwargs):  
     """
     Plot contours on the map.
     
     :param x: (*array_like*) Optional. X coordinate array.
     :param y: (*array_like*) Optional. Y coordinate array.
     :param z: (*array_like*) 2-D z value array.
     :param levs: (*array_like*) Optional. A list of floating point numbers indicating the level curves 
         to draw, in increasing order.
     :param cmap: (*string*) Color map string.
     :param colors: (*list*) If None (default), the colormap specified by cmap will be used. If a 
         string, like ``r`` or ``red``, all levels will be plotted in this color. If a tuple of matplotlib 
         color args (string, float, rgb, etc), different levels will be plotted in different colors in 
         the order specified.
     :param proj: (*ProjectionInfo*) Map projection of the data. Default is None.
     :param isadd: (*boolean*) Add layer or not. Default is ``True``.
     :param zorder: (*int*) Z-order of created layer for display.
     :param smooth: (*boolean*) Smooth countour lines or not.
     :param select: (*boolean*) Set the return layer as selected layer or not.
     
     :returns: (*VectoryLayer*) Contour VectoryLayer created from array data.
     """
     n = len(args) 
     if n <= 2:
         a = args[0]
         y = a.dimvalue(0)
         x = a.dimvalue(1)
         args = args[1:]
     else:
         x = args[0]
         y = args[1]
         a = args[2]
         args = args[3:]
     ls = plotutil.getlegendscheme(args, a.min(), a.max(), **kwargs)
     ls = ls.convertTo(ShapeTypes.Polyline)
     plotutil.setlegendscheme(ls, **kwargs)
     isadd = kwargs.pop('isadd', True)
     smooth = kwargs.pop('smooth', True)
     layer = DrawMeteoData.createContourLayer(a.array, x.array, y.array, ls, 'layer', 'data', smooth)
     proj = kwargs.pop('proj', None)
     if not proj is None:
         layer.setProjInfo(proj)
     
     # Add layer
     isadd = kwargs.pop('isadd', True)
     if isadd:
         zorder = kwargs.pop('zorder', None)
         select = kwargs.pop('select', True)
         self.add_layer(layer, zorder, select)
         self.axes.setDrawExtent(layer.getExtent().clone())
         self.axes.setExtent(layer.getExtent().clone())
             
     return MILayer(layer)
print 'Create layer...'
ls = LegendScheme(ShapeTypes.Polyline)
ls.setLegendType(LegendType.UniqueValue)
values = [500, 550, 600, 650, 700, 750, 800, 850, 900, 950,1000]
colors = [Color(110,0,220),Color(30,60,255),Color(0,160,255),Color(0,200,200),Color(0,220,0),
	Color(160,230,50),Color(230,220,50),Color(230,175,45),Color(240,130,40),Color(250,60,60),Color(240,0,130)]
lbs = ls.getLegendBreaks()
for i in range(0, len(colors)):
	lb = PolylineBreak()
	lb.setColor(colors[i])
	lb.setStartValue(values[i])
	lb.setEndValue(values[i])
	lb.setCaption(str(values[i]))
	lbs.add(lb)

layer = DrawMeteoData.createContourLayer(gdata, ls, 'Pressure_contour', 'PS', True)

#---- Add layer
mapFrame.addLayer(layer)
mapFrame.moveLayer(layer, 0)

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

#---- Zoom layout map
print 'Zoom layout map...'
mapLayout.getActiveLayoutMap().zoomToExtentLonLatEx(Extent(0, 360, -90, 90))

#---- Set mapframe
mapFrame.setGridXDelt(30)
mapFrame.setGridYDelt(30)
#---- Create MeteoDataInfo object
mdi = MeteoDataInfo()

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

#---- Get grid data
mdi.setTimeIndex(2)
mdi.setLevelIndex(3)
gdata = mdi.getGridData('Z')
gdata.extendToGlobal()

#---- Create shaded layer from the grid data
layer = DrawMeteoData.createContourLayer(gdata, 'Z_contour', 'Z', True)
#layer = DrawMeteoData.createShadedLayer(gdata, 'Z_shaded', 'Z', True)
#layer = DrawMeteoData.createRasterLayer(gdata, 'Z_raster')
#layer = DrawMeteoData.createGridFillLayer(gdata, 'Z_gridfill', 'Z')
#layer = DrawMeteoData.createGridPointLayer(gdata, 'Z_gridpoint', 'Z')

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

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

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

#---- Zoom layout map