def contourf(self, *args, **kwargs): """ Plot filled 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.Polygon) plotutil.setlegendscheme(ls, **kwargs) isadd = kwargs.pop('isadd', True) smooth = kwargs.pop('smooth', True) layer = DrawMeteoData.createShadedLayer(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) if zorder is None: zorder = 0 self.add_layer(layer, zorder, select) self.axes.setDrawExtent(layer.getExtent().clone()) self.axes.setExtent(layer.getExtent().clone()) return MILayer(layer)
lb = PolygonBreak() lb.setColor(colors[i]) lb.setStartValue(values[i]) lb.setEndValue(values[i + 1]) if i == 0: lb.setCaption('< ' + str(values[i + 1])) elif i == len(colors) - 1: lb.setCaption('> ' + str(values[i])) else: lb.setCaption(str(values[i]) + ' - ' + str(values[i + 1])) lb.setDrawOutline(False) lbs.add(lb) #---- Create shaded layer print 'Create shaded layer...' layer = DrawMeteoData.createShadedLayer(gdata, ls, 'Rain_shaded', 'Rain', True) layer.setMaskout(True) #---- Add layer mapFrame.addLayer(layer) mapFrame.moveLayer(layer, 0) #---- Add title title = mapLayout.addText('Precipitation map of China', 280, 40, 'Arial', 18) stime = stime + timedelta(hours=-6) subTitle = mapLayout.addText('(' + stime.strftime('%Y-%m-%d %H:00') + ' to ' + etime.strftime('%Y-%m-%d %H:00') + ')', 280, 60, 'Arial', 16) #---- Set layout map print 'Set layout map...' layoutMap.setDrawGridLine(False)
#---- Open GrADS data print 'Open GrADS data...' mdi = MeteoDataInfo() mdi.openGrADSData(os.path.join(dataDir, 'model.ctl')) #---- Set time index mdi.setTimeIndex(2) #---- Get pressure grid data gdata = mdi.getGridData('PS') gdata.extendToGlobal() #---- Create pressure shaded layer print 'Create pressure shaded layer...' pressLayer = DrawMeteoData.createShadedLayer(gdata, 'Pressure', 'PS', True) #---- Add layer mapFrame.addLayer(pressLayer) #--- Move pressure layer to bottom mapFrame.moveLayer(pressLayer, 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
#---- Interpolate station data to grid data print 'Interpolate station data to grid data...' interpSet = InterpolationSetting(60,140,-20,60,160,160,"IDW_Radius",2,1) #radList = [10.0, 8.0, 6.0, 4.0] #interpSet = InterpolationSetting(60,140,-20,60,160,160,"Cressman",radList) gdata = sdata.interpolateData(interpSet) #---- Set legend scheme ls = LegendScheme(ShapeTypes.Polygon) lsfn = 'D:/Temp/rain1.lgs' ls.importFromXMLFile(lsfn) #---- Create shaded layer print 'Create shaded layer...' layer = DrawMeteoData.createShadedLayer(gdata, ls, 'Rain_shaded', 'Rain', True) layer.setMaskout(True) #---- Add layer mapFrame.addLayer(layer) mapFrame.moveLayer(layer, 0) #---- Set sub title stime = stime + timedelta(hours=-6) subTitle = mapLayout.getTexts().get(1) subTitle.setLabelText(u'(' + stime.strftime('%Y-%m-%d %H:00') + u' 至 ' + etime.strftime('%Y-%m-%d %H:00') + u')') #---- Set legend legend = mapLayout.getLegends().get(0) legend.setLegendLayer(layer)
ls = LegendScheme(ShapeTypes.Polygon) ls.setLegendType(LegendType.GraduatedColor) values = [450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950,1000, 1050] colors = [Color(160,0,200),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 = PolygonBreak() lb.setColor(colors[i]) lb.setStartValue(values[i]) lb.setEndValue(values[i + 1]) lb.setCaption(str(values[i]) + ' ' + str(values[i + 1])) lb.setDrawOutline(False) lbs.add(lb) layer = DrawMeteoData.createShadedLayer(gdata, ls, 'Pressure_Shaded', '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)
qs = es.mul(0.62197).div(DataMath.sub(prs, es.mul(0.378))) #qs = 0.62197*es/(prs-0.378*es) q = qs.mul(rhum).div(100) #q = qs*rhum/100 qhdivg = DataMath.hdivg(q.mul(uwnd).div(g), q.mul(vwnd).div(g)) #qhdivg = DataMath.Hdivg(q*uwnd/g,q*vwnd/g) qv = rhum.mul(es).div(100) #qv = rhum*es/100 uv = DataMath.magnitude(uwnd, vwnd) #uv = DataMath.Magnitude(uwnd, vwnd) uvq = uv.mul(qv).div(9.8*1000) #uvq = uv*qv/(9.8*1000) #---- Create data layer print 'Create data layer...' dataLayer = DrawMeteoData.createShadedLayer(qhdivg, "WaterVaporFlux", "Flux", False) #---- Add layer print 'Add layers...' mapFrame.addLayer(dataLayer) mapFrame.moveLayer(dataLayer, 0) #---- Zoom data mapLayout.getActiveLayoutMap().zoomToExtentLonLatEx(Extent(0,360,-90.1,90.1)) #---- Set MapLayout format = SimpleDateFormat('yyyy-MM-dd') aTime = dataAir.getDataInfo().getTimes().get(tIdx) mapLayout.addText('Water Vapor Flux Divergence - ' + format.format(aTime), 320, 30, 'Arial', 16) aLegend = mapLayout.addLegend(650, 100) aLegend.setLegendStyle(LegendStyles.Bar_Vertical) aLegend.setLegendLayer(dataLayer) layoutMap.setGridXDelt(60)
# ---- Interpolate station data to grid data print "Interpolate station data to grid data..." interpSet = InterpolationSetting(60, 140, -20, 60, 160, 160, "IDW_Radius", 2, 1) # radList = [10.0, 8.0, 6.0, 4.0] # interpSet = InterpolationSetting(60,140,-20,60,160,160,"Cressman",radList) gdata = sdata.interpolateData(interpSet) # ---- Set legend scheme ls = LegendScheme(ShapeTypes.Polygon) lsfn = "D:/Temp/rain1.lgs" ls.importFromXMLFile(lsfn) # ---- Create shaded layer print "Create shaded layer..." layer = DrawMeteoData.createShadedLayer(gdata, ls, "Rain_shaded", "Rain", True) layer.setMaskout(True) # ---- miapp object mapFrame = miapp.getMapDocument().getActiveMapFrame() mapLayout = miapp.getMapDocument().getMapLayout() # ---- Add layer mapFrame.addLayer(layer) mapFrame.moveLayer(layer, 0) # ---- Set sub title stime = stime + timedelta(hours=-6) subTitle = mapLayout.getTexts().get(1) subTitle.setLabelText(u"(" + stime.strftime("%Y-%m-%d %H:00") + u" 至 " + etime.strftime("%Y-%m-%d %H:00") + u")")