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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/qesdi/geoplot/trunk/lib/geoplot/layer_drawer_contour.py@5876
Revision 5876, 2.5 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 contours of the data onto an image object.
3"""
4
5import logging
6
7from geoplot.contour_drawer import ContourDrawer
8from geoplot.layer_drawer import LayerDrawerBase
9
10log = logging.getLogger(__name__)
11
12class LayerDrawerContour(LayerDrawerBase):
13    "Draw only the layer section of the plot"
14   
15    def __init__(self, cdmsVar,  numLines=10, fontSize='medium', labelInterval=1, 
16                 lineWidth=0.5, **kwargs):
17       
18        self._contourDrawer = ContourDrawer()
19        self.numLines = numLines
20        self.cdmsVar = cdmsVar
21        self.fontSize = fontSize
22        self.labelInterval =labelInterval
23        self.lineWidth = lineWidth
24       
25        LayerDrawerBase.__init__(self, **kwargs)
26       
27    def _drawToAxes(self, axes, xLimits, yLimits):
28        """
29        Draw the contours onto the axes.
30        """
31       
32        grid = self._buildGrid(self.cdmsVar, xLimits, yLimits)
33       
34        scheme = self._csBuilder.buildScheme(grid)
35       
36        #if the projection is 'latlon' then no transformation is needed.
37        if self.projection == 'latlon':
38            basemap = None
39        else:
40            map = self._getMap(xLimits, yLimits)
41            basemap = map.basemap       
42       
43       
44        cmap = scheme.colourMap
45       
46        #set the bad colour to transparent
47        cmap.set_bad('w', 0.0)
48       
49        self._contourDrawer.draw(axes, grid, normalize=scheme.norm, cmap=cmap,
50                                 basemap=basemap, fontSize=self.fontSize)
51   
52    ### properties ###
53         
54    def __set_numLines(self, value):
55        self._contourDrawer.numContourLines = value
56   
57    def __get_numLines(self):
58        return self._contourDrawer.numContourLines
59
60    numLines = property(__get_numLines, __set_numLines)
61   
62    def __set_fontSize(self, value):
63        self._fontSize = value
64   
65    def __get_fontSize(self):
66        return self._fontSize
67
68    fontSize = property(__get_fontSize, __set_fontSize)
69   
70    def __set_labelInterval(self, value):
71        self._contourDrawer.contourLabelInterval = value
72   
73    def __get_labelInterval(self):
74        return self._contourDrawer.contourLabelInterval
75
76    labelInterval = property(__get_labelInterval, __set_labelInterval)
77   
78    def __set_lineWidth(self, value):
79        self._contourDrawer.contourLineWidth = value
80   
81    def __get_lineWidth(self):
82        return self._contourDrawer.contourLineWidth
83   
84    lineWidth = property(__get_lineWidth, __set_lineWidth)
85
86       
Note: See TracBrowser for help on using the repository browser.