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

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

Imroved the colour bar code so that a legend colour bar can be used without specifying any intervals.

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,
18                 hideOutside=False, 
19                 numIntervals = None, **kwargs):
20       
21        self.numIntervals = numIntervals
22        self.hideOutside = hideOutside
23       
24       
25        self._gridDrawer = GridDrawer()
26       
27        self.cdmsVar = cdmsVar
28        self.showGridLines = showGridLines
29        self.outline = outline
30       
31        LayerDrawerBase.__init__(self, **kwargs)
32       
33    def _drawToAxes(self, axes, xLimits, yLimits):
34        """
35        Creates a new grid object and draws it onto the axis.
36        """
37        #create a new grid, this grid will be in terms of lat/lon
38        grid = self._buildGrid(self.cdmsVar, xLimits, yLimits)
39       
40        # if the projection is latlon then there is no need to transform
41        # the data on the grid.
42        if self.projection == 'latlon':
43            basemap = None
44        else:
45            map = self._getMap(xLimits, yLimits)
46            basemap = map.basemap       
47       
48#        map = self._getMap(xLimits, yLimits)
49#        map.basemap.drawcoastlines(ax=axes, xLimits=xLimits, yLimits=yLimits)
50
51        scheme = self._csBuilder.buildScheme(self.colourBarStyle, grid=grid)
52        cmap = scheme.colourMap
53        #set the bad colour to transparent
54        cmap.set_bad('w', 0.0)
55       
56        self._applyMask(grid, scheme, self.hideOutside)
57       
58        #draw the grid on the axis
59        self._gridDrawer.draw(axes, grid,
60                              basemap=basemap, 
61                              limits=(xLimits, yLimits),
62                              norm=scheme.norm,
63                              cmap=cmap)
64       
65   
66    ### properties ###
67                       
68    def __set_showGridLines(self, value):
69        self._gridDrawer.showGridLines = value
70   
71    def __get_showGridLines(self):
72        return self._gridDrawer.showGridLines
73   
74    showGridLines = property(__get_showGridLines, __set_showGridLines) 
75   
76    def __set_outline(self, value):
77        self._gridDrawer.outline = value
78       
79    def __get_outline(self):
80        return self._gridDrawer.outline
81   
82    outline = property(__get_outline, __set_outline)
83
84    def __set_numIntervals(self, value):
85        self._csBuilder.numIntervals = value
86
87    def __get_numIntervals(self):
88        return self._csBuilder.numIntervals
89       
90    numIntervals = property(__get_numIntervals, __set_numIntervals, None, None) 
91   
92    def __set_hideOutside(self, value):
93        self._hideOutsideBounds = value
94
95    def __get_hideOutside(self):
96        return self._hideOutsideBounds
97       
98    hideOutside = property(__get_hideOutside, __set_hideOutside, None, None)
Note: See TracBrowser for help on using the repository browser.