Ejemplo n.º 1
0
 def stationmodel(self, smdata, **kwargs):
     """
     Plot station model data on the map.
     
     :param smdata: (*StationModelData*) Station model data.
     :param surface: (*boolean*) Is surface data or not. Default is True.
     :param size: (*float*) Size of the station model symbols. Default is 12.
     :param proj: (*ProjectionInfo*) Map projection of the data. Default is None.
     :param order: (*int*) Z-order of created layer for display.
     
     :returns: (*VectoryLayer*) Station model VectoryLayer.
     """
     proj = kwargs.pop('proj', None)
     size = kwargs.pop('size', 12)
     surface = kwargs.pop('surface', True)
     ls = LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Point, Color.blue, size)
     layer = DrawMeteoData.createStationModelLayer(smdata, ls, 'stationmodel', surface)
     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)
Ejemplo n.º 2
0
 def streamplot(self, *args, **kwargs):
     """
     Plot streamline 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 color: (*Color*) Streamline color. Default is blue.
     :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 density: (*int*) Streamline density. Default is 4.
     :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 streamline VectoryLayer.
     """
     cmap = plotutil.getcolormap(**kwargs)
     fill_value = kwargs.pop('fill_value', -9999.0)
     proj = kwargs.pop('proj', None)
     cobj = kwargs.pop('color', 'b')
     color = plotutil.getcolor(cobj)
     isuv = kwargs.pop('isuv', True)
     density = kwargs.pop('density', 4)
     n = len(args)
     if n < 4:
         u = args[0]
         v = args[1]
         y = u.dimvalue(0)
         x = u.dimvalue(1)
         args = args[2:]
     else:
         x = args[0]
         y = args[1]
         u = args[2]
         v = args[3]
         args = args[4:]  
     ls = LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Polyline, color, 1)
     plotutil.setlegendscheme(ls, **kwargs)
     #layer = __plot_uvgriddata_m(plot, udata, vdata, None, ls, 'streamplot', isuv, proj=proj, density=density)
     layer = DrawMeteoData.createStreamlineLayer(u.array, v.array, x.array, y.array, density, 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)
Ejemplo n.º 3
0
 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)
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)
Ejemplo n.º 5
0
lb.setDrawFill(False)
lb.setOutlineColor(Color.black)
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 data
sdata = mdi.getStationData('WeatherNow')

#---- Create station weather layer from the station data
layer = DrawMeteoData.createWeatherSymbolLayer(sdata, 'All Weather', 'WeatherSymbole')
#weathers = [5,10,11,12,40,41,42,43,44,45,46,47,48,49]
#layer = DrawMeteoData.createWeatherSymbolLayer(sdata, weathers, 'WeatherSymbole')

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

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

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

#---- Set layout map
print 'Set layout map...'
mapLayout.getActiveLayoutMap().setWidth(580)
Ejemplo n.º 6
0
    ynum = 400
    xdelt = 0.25
    ydelt = 0.25
    xlist = []
    ylist = []
    for i in range(0, xnum):
        xlist.append(xmin + xdelt * i)
    for i in range(0, ynum):
        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('precipitation')
    print var.getName()
    dimList = [xDim, yDim]
    var.setDimensions(dimList)
    gData = mdi.getGridData(var.getName())
    aLS = LegendManage.createLegendSchemeFromGridData(
        gData, LegendType.GraduatedColor, ShapeTypes.Polygon)
    aLayer = DrawMeteoData.createRasterLayer(gData, "Test_HDF", aLS)
    mf = miapp.getMapDocument().getActiveMapFrame()
    mf.addLayer(aLayer)
    mf.moveLayer(aLayer, 0)

print 'Finished!'
Ejemplo n.º 7
0
    def imshow(self, *args, **kwargs):
        """
        Display an image 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 fill_value: (*float*) Fill_value. Default is ``-9999.0``.
        :param fill_color: (*color*) Fill_color. Default is None (white color).
        :param proj: (*ProjectionInfo*) Map projection of the data. Default is None.
        :param zorder: (*int*) Z-order of created layer for display.
        :param interpolation: (*string*) Interpolation option [None | bilinear | bicubic].
        
        :returns: (*RasterLayer*) RasterLayer created from array data.
        """
        cmap = plotutil.getcolormap(**kwargs)
        fill_value = kwargs.pop('fill_value', -9999.0)        
        ls = kwargs.pop('symbolspec', None)
        n = len(args) 
        isrgb = False
        if n <= 2:
            if isinstance(args[0], (list, tuple)):
                isrgb = True
                rgbdata = args[0]
                if isinstance(rgbdata[0], DimArray):
                    x = rgbdata[0].dimvalue(1)
                    y = rgbdata[0].dimvalue(0)                
                else:
                    x = minum.arange(0, rgbdata[0].shape[1])
                    y = minum.arange(0, rgbdata[0].shape[0])
            elif args[0].ndim > 2:
                isrgb = True
                rgbdata = args[0]
                x = rgbdata.dimvalue(1)
                y = rgbdata.dimvalue(0)
            else:
                gdata = minum.asgridarray(args[0])
                args = args[1:]
        elif n <=4:
            x = args[0]
            y = args[1]
            a = args[2]
            if isinstance(a, (list, tuple)):
                isrgb = True
                rgbdata = a
            elif a.ndim > 2:
                isrgb = True
                rgbdata = a
            else:
                gdata = minum.asgridarray(a, x, y, fill_value)
                args = args[3:]    
        
        isadd = kwargs.pop('isadd', True)
        interpolation = kwargs.pop('interpolation', None)
        if isrgb:
            if isinstance(rgbdata, (list, tuple)):
                rgbd = []
                for d in rgbdata:
                    rgbd.append(d.asarray())
                rgbdata = rgbd
            else:
                rgbdata = rgbdata.asarray()        
            extent = [x[0],x[-1],y[0],y[-1]]
            igraphic = GraphicFactory.createImage(rgbdata, extent)
            x = plotutil.getplotdata(x)
            y = plotutil.getplotdata(y)
            layer = DrawMeteoData.createImageLayer(x, y, igraphic, 'layer_image')
        else:
            if len(args) > 0:
                if ls is None:
                    level_arg = args[0]
                    if isinstance(level_arg, int):
                        cn = level_arg
                        ls = LegendManage.createImageLegend(gdata, cn, cmap)
                    else:
                        if isinstance(level_arg, MIArray):
                            level_arg = level_arg.aslist()
                        ls = LegendManage.createImageLegend(gdata, level_arg, cmap)
            else:    
                if ls is None:
                    ls = LegendManage.createImageLegend(gdata, cmap)
            plotutil.setlegendscheme(ls, **kwargs)
            fill_color = kwargs.pop('fill_color', None)
            if not fill_color is None:
                cb = ls.getLegendBreaks().get(ls.getBreakNum() - 1)
                if cb.isNoData():
                    cb.setColor(plotutil.getcolor(fill_color))

            layer = DrawMeteoData.createRasterLayer(gdata, 'layer', ls) 
                            
        proj = kwargs.pop('proj', None)
        if not proj is None:
            layer.setProjInfo(proj)
        if not interpolation is None:
            layer.setInterpolation(interpolation)
        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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
#---- Create MeteoDataInfo object
mdi = MeteoDataInfo()

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

#---- Get U/V grid data
mdi.setTimeIndex(2)
mdi.setLevelIndex(3)
udata = mdi.getGridData('U')
vdata = mdi.getGridData('V')

#---- Create wind vector layer from the U/V grid data
layer = DrawMeteoData.createGridVectorLayer(udata, vdata,  'UV_Vector', True)
#layer = DrawMeteoData.createGridBarbLayer(udata, vdata,  'UV_Barb', True)
#layer = DrawMeteoData.createStreamlineLayer(udata, vdata, 'Z_Streamline', True)

#---- 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)

#---- Add wind arrow
windArrow = mapLayout.addWindArrow(660, 420)
lb.setOutlineColor(Color.black)
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 wind direction/speed station data
windDir = mdi.getStationData('WindDirection')
windSpeed = mdi.getStationData('WindSpeed')

#---- Create barb and vector wind layers
bLayer = DrawMeteoData.createSTBarbLayer(windDir, windSpeed, 'WindBarb_Point', False)
vLayer = DrawMeteoData.createSTVectorLayer(windDir, windSpeed, 'WindVector_Point', False)

#---- Add layers
mapFrame.addLayer(bLayer)
mapFrame.addLayer(vLayer)

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

#---- Set layout map
print 'Set layout map...'
mapLayout.getActiveLayoutMap().setWidth(580)
mapLayout.getActiveLayoutMap().zoomToExtentLonLatEx(Extent(70, 140, 15, 55))

#---- 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)
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 model data
smdata = mdi.getStationModelData()

#---- Create station info layer from the station model data
layer = DrawMeteoData.createStationModelLayer(smdata, 'StationModel')

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

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

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

#---- Set layout map
print 'Set layout map...'
mapLayout.getActiveLayoutMap().setWidth(580)
mapLayout.getActiveLayoutMap().zoomToExtentLonLatEx(Extent(70, 140, 15, 55))
# ---- 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")")
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)
Ejemplo n.º 16
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 data
sdata = mdi.getStationData('Visibility')

#---- Create station point layer from the grid data
layer = DrawMeteoData.createSTPointLayer(sdata, 'Visibility_STPoint', 'Visibility')

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

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

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

#---- Set layout map
print 'Set layout map...'
mapLayout.getActiveLayoutMap().setWidth(580)
mapLayout.getActiveLayoutMap().zoomToExtentLonLatEx(Extent(70, 140, 15, 55))
Ejemplo n.º 17
0
#---- 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
Ejemplo n.º 18
0
#---- 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
Ejemplo n.º 19
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)
Ejemplo n.º 20
0
#---- 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)

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

#---- Set layout map
print 'Set layout map...'
mapLayout.getActiveLayoutMap().setWidth(580)
mapLayout.getActiveLayoutMap().zoomToExtentLonLatEx(Extent(70, 140, 15, 55))

#---- Set mapframe
Ejemplo n.º 21
0
 def scatter(self, *args, **kwargs):
     """
     Make a scatter plot on a map.
     
     :param x: (*array_like*) Input x data.
     :param y: (*array_like*) Input y data.
     :param z: (*array_like*) Input z data.
     :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, different 
         levels will be plotted in different colors in the order specified.
     :param size: (*int of list*) Marker size.
     :param marker: (*string*) Marker of the points.
     :param fill: (*boolean*) Fill markers or not. Default is True.
     :param edge: (*boolean*) Draw edge of markers or not. Default is True.
     :param facecolor: (*Color*) Fill color of markers. Default is black.
     :param edgecolor: (*Color*) Edge color of markers. Default is black.
     :param proj: (*ProjectionInfo*) Map projection of the data. Default is None.
     :param zorder: (*int*) Z-order of created layer for display.
     
     :returns: (*VectoryLayer*) Point VectoryLayer.
     """
     n = len(args) 
     if n == 1:
         a = args[0]
         y = a.dimvalue(0)
         x = a.dimvalue(1)
         args = args[1:]
     else:
         x = args[0]
         y = args[1]
         if not isinstance(x, MIArray):
             x = minum.array(x)
         if not isinstance(y, MIArray):
             y = minum.array(y)
         if n == 2:
             a = x
             args = args[2:]
         else:
             a = args[2]
             if not isinstance(a, MIArray):
                 a = minum.array(a)
             args = args[3:]
     
     ls = kwargs.pop('symbolspec', None)
     if ls is None:
         isunique = False
         colors = kwargs.get('colors', None) 
         if not colors is None:
             if isinstance(colors, (list, tuple)) and len(colors) == len(x):
                 isunique = True
         size = kwargs.get('size', None)
         if not size is None:
             if isinstance(size, (list, tuple, MIArray)) and len(size) == len(x):
                 isunique = True
         if isunique:
             ls = LegendManage.createUniqValueLegendScheme(len(x), ShapeTypes.Point)
         else:
             ls = plotutil.getlegendscheme(args, a.min(), a.max(), **kwargs)
         ls = plotutil.setlegendscheme_point(ls, **kwargs)
     
     if a.size == ls.getBreakNum() and ls.getLegendType() == LegendType.UniqueValue:
         layer = DrawMeteoData.createSTPointLayer_Unique(a.array, x.array, y.array, ls, 'layer', 'data')
     else:
         layer = DrawMeteoData.createSTPointLayer(a.array, x.array, y.array, ls, 'layer', 'data')
     
     proj = kwargs.pop('proj', None)
     if not proj is None:
         layer.setProjInfo(proj)
     avoidcoll = kwargs.pop('avoidcoll', None)
     if not avoidcoll is None:
         layer.setAvoidCollision(avoidcoll)
     
     # 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)
	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)
Ejemplo n.º 23
0
	xnum = 1440
	ynum = 400
	xdelt = 0.25
	ydelt = 0.25
	xlist = []
	ylist = []
	for i in range(0,xnum):
		xlist.append(xmin + xdelt * i)
	for i in range(0,ynum):
		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('precipitation')
	print var.getName()
	dimList = [xDim, yDim]
	var.setDimensions(dimList)
	gData = mdi.getGridData(var.getName())	
	aLS = LegendManage.createLegendSchemeFromGridData(gData, LegendType.GraduatedColor, ShapeTypes.Polygon)
	aLayer = DrawMeteoData.createRasterLayer(gData, "Test_HDF", aLS)
	mf = miapp.getMapDocument().getActiveMapFrame()
	mf.addLayer(aLayer)
	mf.moveLayer(aLayer, 0)	

print 'Finished!'