예제 #1
0
    def barbs(self, *args, **kwargs):
        """
        Plot a 2-D field of barbs in a map.
        
        :param x: (*array_like*) Optional. X coordinate array.
        :param y: (*array_like*) Optional. Y coordinate array.
        :param u: (*array_like*) U component of the arrow vectors (wind field) or wind direction.
        :param v: (*array_like*) V component of the arrow vectors (wind field) or wind speed.
        :param z: (*array_like*) Optional, 2-D z value array.
        :param levs: (*array_like*) Optional. A list of floating point numbers indicating the level 
            barbs to draw, in increasing order.
        :param cmap: (*string*) Color map string.
        :param fill_value: (*float*) Fill_value. Default is ``-9999.0``.
        :param isuv: (*boolean*) Is U/V or direction/speed data array pairs. Default is True.
        :param size: (*float*) Base size of the arrows.
        :param proj: (*ProjectionInfo*) Map projection of the data. Default is None.
        :param zorder: (*int*) Z-order of created layer for display.
        :param select: (*boolean*) Set the return layer as selected layer or not.
        
        :returns: (*VectoryLayer*) Created barbs VectoryLayer.
        """
        cmap = plotutil.getcolormap(**kwargs)
        fill_value = kwargs.pop('fill_value', -9999.0)
        proj = kwargs.pop('proj', None)
        order = kwargs.pop('order', None)
        isuv = kwargs.pop('isuv', True)
        n = len(args) 
        iscolor = False
        cdata = None
        onlyuv = True
        if n >= 4 and isinstance(args[3], (DimArray, MIArray)):
            onlyuv = False
        if onlyuv:
            u = minum.asarray(args[0])
            v = minum.asarray(args[1])
            xx = args[0].dimvalue(1)
            yy = args[0].dimvalue(0)
            x, y = minum.meshgrid(xx, yy)
            args = args[2:]
            if len(args) > 0:
                cdata = minum.asarray(args[0])
                iscolor = True
                args = args[1:]
        else:
            x = minum.asarray(args[0])
            y = minum.asarray(args[1])
            u = minum.asarray(args[2])
            v = minum.asarray(args[3])
            args = args[4:]
            if len(args) > 0:
                cdata = minum.asarray(args[0])
                iscolor = True
                args = args[1:]
        if iscolor:
            if len(args) > 0:
                cn = args[0]
                ls = LegendManage.createLegendScheme(cdata.min(), cdata.max(), cn, cmap)
            else:
                levs = kwargs.pop('levs', None)
                if levs is None:
                    ls = LegendManage.createLegendScheme(cdata.min(), cdata.max(), cmap)
                else:
                    if isinstance(levs, MIArray):
                        levs = levs.tolist()
                    ls = LegendManage.createLegendScheme(cdata.min(), cdata.max(), levs, cmap)
        else:    
            if cmap.getColorCount() == 1:
                c = cmap.getColor(0)
            else:
                c = Color.black
            ls = LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Point, c, 10)
        ls = plotutil.setlegendscheme_point(ls, **kwargs)
        if not cdata is None:
            cdata = cdata.array
        layer = DrawMeteoData.createBarbLayer(x.array, y.array, u.array, v.array, cdata, ls, 'layer', isuv)
        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)