Beispiel #1
0
def makelegend(source, **kwargs):
    '''
    Make a legend.
    
    :param souce: Legend file name or list of the legen breaks.
    
    :returns: Created legend.
    '''
    if isinstance(source, basestring):
        if os.path.exists(source):
            ls = LegendScheme()
            ls.importFromXMLFile(source, False)
            return ls
        else:
            source = getcolormap(source)
    else:
        if isinstance(source, list):
            ls = LegendScheme(source)
        else:
            values = kwargs.pop('values', None)
            if values is None:
                ls = None
            else:
                if isinstance(values, MIArray):
                    values = values.aslist()
                cbs = source.findBreaks(values)
                ls = LegendScheme(cbs)
    return ls
Beispiel #2
0
def makelegend(source, **kwargs):
    '''
    Make a legend.
    
    :param souce: Legend file name or list of the legen breaks.
    
    :returns: Created legend.
    '''
    if isinstance(source, basestring):
        if os.path.exists(source):
            ls = LegendScheme()
            ls.importFromXMLFile(source, False)
            return ls
        else:
            source = getcolormap(source)
    else:
        if isinstance(source, list):
            if isinstance(source[0], ColorBreak):
                ls = LegendScheme(source)
            else:
                colors = getcolors(source)
                values = kwargs.pop('values', None)
                if values is None:
                    cbs = []
                    for c in colors:
                        cb = ColorBreak()
                        cb.setColor(c)
                        cbs.append(cb)
                    ls = LegendScheme(cbs)
                else:
                    ls = LegendManage.createLegendScheme(values, colors)
        else:
            values = kwargs.pop('values', None)
            if values is None:
                ls = None
            else:
                if isinstance(values, NDArray):
                    values = values.aslist()
                cbs = source.findBreaks(values)
                ls = LegendScheme(cbs)
    return ls
Beispiel #3
0
def makelegend(source):
    '''
    Make a legend.
    
    :param souce: Legend file name or list of the legen breaks.
    
    :returns: Created legend.
    '''
    if isinstance(source, basestring):
        if os.path.exists(source):
            ls = LegendScheme()
            ls.importFromXMLFile(source, False)
            return ls
        else:
            source = getcolormap(source)
    else:
        ls = LegendScheme(source)
    return ls
Beispiel #4
0
def makesymbolspec(geometry, *args, **kwargs):
    '''
    Make a legend.
    
    :param geometry: (*string*) Geometry type. [point | line | polygon].
    :param levels: (*array_like*) Value levels. Default is ``None``, not used.
    :param colors: (*list*) Colors. Defaul is ``None``, not used.
    :param legend break parameter maps: (*map*) Legend breaks.
    :param field: (*string*) The field to be used in the legend.
    
    :returns: Created legend.
    '''
    shapetype = ShapeTypes.Image
    if geometry == 'point':
        shapetype = ShapeTypes.Point
    elif geometry == 'line':
        shapetype = ShapeTypes.Polyline
    elif geometry == 'polygon':
        shapetype = ShapeTypes.Polygon  
    else:
        shapetype = ShapeTypes.Image
        
    levels = kwargs.pop('levels', None)
    cols = kwargs.pop('colors', None)
    field = kwargs.pop('field', '')
    if not levels is None and not cols is None:
        if isinstance(levels, MIArray):
            levels = levels.aslist()
        colors = []
        for cobj in cols:
            colors.append(getcolor(cobj))
        ls = LegendManage.createLegendScheme(shapetype, levels, colors)
        setlegendscheme(ls, **kwargs)         
        ls.setFieldName(field)
        values = kwargs.pop('values', None)
        if values is None:
            return ls
        else:
            nls = LegendScheme(ls.getShapeType())
            for v in values:
                nls.addLegendBreak(ls.findLegendBreak(v))
            return nls
           
    n = len(args)
    isunique = True
    if n == 0:
        ls = LegendManage.createSingleSymbolLegendScheme(shapetype)
        setlegendscheme(ls, **kwargs)
    elif n == 1 and isinstance(args[0], int):
        ls = LegendManage.createUniqValueLegendScheme(args[0], shapetype)
        setlegendscheme(ls, **kwargs)
    else:
        ls = LegendScheme(shapetype)
        for arg in args:
            if isinstance(arg, (list, tuple)):
                for argi in arg:
                    lb, isu = getlegendbreak(geometry, **argi)
                    if isunique and not isu:
                        isunique = False
                    ls.addLegendBreak(lb)
            else:
                lb, isu = getlegendbreak(geometry, **arg)
                if isunique and not isu:
                    isunique = False
                ls.addLegendBreak(lb)
       
    ls.setFieldName(field)
    if ls.getBreakNum() > 1:
        if isunique:
            ls.setLegendType(LegendType.UniqueValue)
        else:
            ls.setLegendType(LegendType.GraduatedColor)
            
    return ls
	if i == 0:
		sdata = mdi.getStationData('Precipitation6h')
	else:
		sdata = sdata.add(mdi.getStationData('Precipitation6h'))

	atime = atime + timedelta(hours=6)
	
#---- 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)
ls.setLegendType(LegendType.GraduatedColor)
values = [0,0.1,1,2,5,10,20,25,50,100,1000]
colors = [Color(255,255,255),Color(170,240,255),Color(120,230,240),Color(200,220,50),Color(240,220,20),
	Color(255,120,10),Color(255,90,10),Color(240,40,0),Color(180,10,0),Color(120,10,0)]
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])
	if i == 0:
		lb.setCaption('< ' + str(values[i + 1]))
	elif i == len(colors) - 1:
		lb.setCaption('> ' + str(values[i]))
	else:
Beispiel #6
0
lb.setDrawFill(False)
lb.setOutlineColor(Color.blue)
mapFrame.addLayer(countryLayer)

#---- Create MeteoDataInfo object
mdi = MeteoDataInfo()

#---- Open a MICAPS data file
fn = os.path.join(dataDir, 'MICAPS/10101414.000')
mdi.openMICAPSData(fn)

#---- Get station info data
sidata = mdi.getStationInfoData()

#---- Create station info layer from the station info data
ls = LegendScheme(ShapeTypes.Point)
ls.setLegendType(LegendType.SingleSymbol)
lbs = ls.getLegendBreaks()
lb = PointBreak()
lb.setSize(16)
lb.setColor(Color.blue)
lb.setOutlineColor(Color.red)
lb.setStyle(PointStyle.Star)
lbs.add(lb)

layer = DrawMeteoData.createSTInfoLayer(sidata, ls, 'StationInfo')
layer.setAvoidCollision(True)

#---- Add layer
mapFrame.addLayer(layer)
mapFrame.moveLayer(layer, 0)
	if i == 0:
		sdata = mdi.getStationData('Precipitation6h')
	else:
		sdata = sdata.add(mdi.getStationData('Precipitation6h'))

	atime = atime + timedelta(hours=6)
	
#---- 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)
#---- 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 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)
        ylist.append(ymin + ydelt * i)

    X = jarray.array(xlist, 'd')
    Y = jarray.array(ylist, 'd')
    xDim = Dimension(DimensionType.X)
    xDim.setValues(X)
    dataInfo.setXDimension(xDim)
    yDim = Dimension(DimensionType.Y)
    yDim.setValues(Y)
    dataInfo.setYDimension(yDim)
    var = dataInfo.getVariable('Optical_Depth_Land_And_Ocean_Mean_Mean')
    print var.getName()
    dimList = [yDim, xDim]
    var.setDimensions(dimList)
    gData = mdi.getGridData(var.getName())
    #aLS = LegendManage.createLegendSchemeFromGridData(gData, LegendType.GraduatedColor, ShapeTypes.Polygon)
    aLS = LegendScheme(ShapeTypes.Polygon)
    aLS.importFromXMLFile(os.path.join(dataDir, 'AOD.lgs'))
    aLayer = DrawMeteoData.createRasterLayer(gData, "Test_HDF", aLS)
    mf = miapp.getMapDocument().getActiveMapFrame()
    mf.addLayer(aLayer)
    mf.moveLayer(aLayer, 0)
    mdi = MeteoDataInfo()
    inf = os.path.join(outDir, 'China_Prec_2010101420.csv')
    outf = os.path.join(outDir, 'test.csv')
    mdi.openLonLatData(inf)
    stData = mdi.getStationData('Precipitation')
    interData = gData.toStation(stData)
    interData.saveAsCSVFile(outf, 'AOD')

print 'Finished!'
Beispiel #10
0
 def plot(self, *args, **kwargs):
     """
     Plot lines and/or markers to the map.
     
     :param x: (*array_like*) Input x data.
     :param y: (*array_like*) Input y data.
     :param style: (*string*) Line style for plot.
     :param linewidth: (*float*) Line width.
     :param color: (*Color*) Line color.
     
     :returns: (*VectoryLayer*) Line VectoryLayer.
     """
     fill_value = kwargs.pop('fill_value', -9999.0)
     proj = kwargs.pop('proj', None)    
     order = kwargs.pop('order', None)
     n = len(args) 
     xdatalist = []
     ydatalist = []    
     styles = []
     if n == 1:
         ydata = plotutil.getplotdata(args[0])
         if isinstance(args[0], DimArray):
             xdata = args[0].dimvalue(0)
         else:
             xdata = []
             for i in range(0, len(args[0])):
                 xdata.append(i)
         xdatalist.append(minum.asarray(xdata).array)
         ydatalist.append(minum.asarray(ydata).array)
     elif n == 2:
         if isinstance(args[1], basestring):
             ydata = plotutil.getplotdata(args[0])
             if isinstance(args[0], DimArray):
                 xdata = args[0].dimvalue(0)
             else:
                 xdata = []
                 for i in range(0, len(args[0])):
                     xdata.append(i)
             styles.append(args[1])
         else:
             xdata = plotutil.getplotdata(args[0])
             ydata = plotutil.getplotdata(args[1])
         xdatalist.append(minum.asarray(xdata).array)
         ydatalist.append(minum.asarray(ydata).array)
     else:
         c = 'x'
         for arg in args: 
             if c == 'x':    
                 xdatalist.append(minum.asarray(arg).array)
                 c = 'y'
             elif c == 'y':
                 ydatalist.append(minum.asarray(arg).array)
                 c = 's'
             elif c == 's':
                 if isinstance(arg, basestring):
                     styles.append(arg)
                     c = 'x'
                 else:
                     styles.append('-')
                     xdatalist.append(minum.asarray(arg).array)
                     c = 'y'
     
     snum = len(xdatalist)
         
     if len(styles) == 0:
         styles = None
     else:
         while len(styles) < snum:
             styles.append('-')
     
     #Get plot data styles - Legend
     lines = []
     ls = kwargs.pop('legend', None) 
     if ls is None:
         if styles != None:
             for i in range(0, len(styles)):
                 line = plotutil.getplotstyle(styles[i], str(i), **kwargs)
                 lines.append(line)
         else:
             for i in range(0, snum):
                 label = kwargs.pop('label', 'S_' + str(i + 1))
                 line = plotutil.getlegendbreak('line', **kwargs)[0]
                 line.setCaption(label)
                 lines.append(line)
         ls = LegendScheme(lines)
     
     layer = DrawMeteoData.createPolylineLayer(xdatalist, ydatalist, ls, \
             'Plot_lines', 'ID', -180, 180)
     if (proj != 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)
#---- 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 layer
print 'Create 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)