source: qesdi/geoplot/trunk/lib/geoplot/layer_drawer_grid.py @ 5876

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/qesdi/geoplot/trunk/lib/geoplot/layer_drawer_grid.py@5876
Revision 5876, 2.3 KB checked in by pnorton, 10 years ago (diff)

Added a faster layer drawer for the grid, a new style of colour bar and colour schemes which now hold the normalisation and colour map instances.

Line 
1"""
2A layer drawer that draws the grid boxes of the data onto an image object.
3"""
4
5import logging
6import time
7
8import geoplot.utils as geoplot_utils
9from geoplot.grid_drawer import GridDrawer
10from geoplot.layer_drawer import LayerDrawerBase
11
12log = logging.getLogger(__name__)
13
14class LayerDrawerGrid(LayerDrawerBase):
15    "Draw only the layer section of the plot"
16   
17    def __init__(self, cdmsVar, showGridLines=False, outline=False, **kwargs):
18       
19        self._gridDrawer = GridDrawer()
20       
21        self.cdmsVar = cdmsVar
22        self.showGridLines = showGridLines
23        self.outline = outline
24       
25        LayerDrawerBase.__init__(self, **kwargs)
26       
27    def _drawToAxes(self, axes, xLimits, yLimits):
28        """
29        Creates a new grid object and draws it onto the axis.
30        """
31        #create a new grid, this grid will be in terms of lat/lon
32        grid = self._buildGrid(self.cdmsVar, xLimits, yLimits)
33       
34        # if the projection is latlon then there is no need to transform
35        # the data on the grid.
36        if self.projection == 'latlon':
37            basemap = None
38        else:
39            map = self._getMap(xLimits, yLimits)
40            basemap = map.basemap       
41       
42#        map = self._getMap(xLimits, yLimits)
43#        map.basemap.drawcoastlines(ax=axes, xLimits=xLimits, yLimits=yLimits)
44
45        scheme = self._csBuilder.buildScheme(grid)
46        cmap = scheme.colourMap
47        #set the bad colour to transparent
48        cmap.set_bad('w', 0.0)
49       
50        #draw the grid on the axis
51        self._gridDrawer.draw(axes, grid,
52                              basemap=basemap, 
53                              limits=(xLimits, yLimits),
54                              norm=scheme.norm,
55                              cmap=cmap)
56       
57   
58    ### properties ###
59                       
60    def __set_showGridLines(self, value):
61        self._gridDrawer.showGridLines = value
62   
63    def __get_showGridLines(self):
64        return self._gridDrawer.showGridLines
65   
66    showGridLines = property(__get_showGridLines, __set_showGridLines) 
67   
68    def __set_outline(self, value):
69        self._gridDrawer.outline = value
70       
71    def __get_outline(self):
72        return self._gridDrawer.outline
73   
74    outline = property(__get_outline, __set_outline)
75 
Note: See TracBrowser for help on using the repository browser.