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

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

Added the ability to set the scale on the colour scheme to a log scale.

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        log.debug("kwargs = %s" % (kwargs,))
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                                 scale=scheme.scale)
52   
53    ### properties ###
54         
55    def __set_numLines(self, value):
56        self._contourDrawer.numContourLines = value
57   
58    def __get_numLines(self):
59        return self._contourDrawer.numContourLines
60
61    numLines = property(__get_numLines, __set_numLines)
62   
63    def __set_fontSize(self, value):
64        self._fontSize = value
65   
66    def __get_fontSize(self):
67        return self._fontSize
68
69    fontSize = property(__get_fontSize, __set_fontSize)
70   
71    def __set_labelInterval(self, value):
72        self._contourDrawer.contourLabelInterval = value
73   
74    def __get_labelInterval(self):
75        return self._contourDrawer.contourLabelInterval
76
77    labelInterval = property(__get_labelInterval, __set_labelInterval)
78   
79    def __set_lineWidth(self, value):
80        self._contourDrawer.contourLineWidth = value
81   
82    def __get_lineWidth(self):
83        return self._contourDrawer.contourLineWidth
84   
85    lineWidth = property(__get_lineWidth, __set_lineWidth)
86
87       
Note: See TracBrowser for help on using the repository browser.