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

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

Added a module to fix the import Image / from PIL import Image problem.

Line 
1"""
2An object to draw just the layer (map + grid) from the plot,
3can draw to a file, a string or create an Image object.
4"""
5
6
7import logging
8import StringIO
9import thread
10
11from geoplot.image_import import Image
12from geoplot.contour_drawer import ContourDrawer
13import geoplot.utils as geoplot_utils
14
15from geoplot.layer_drawer import LayerDrawerBase
16
17log = logging.getLogger(__name__)
18
19class LayerDrawerContour(LayerDrawerBase):
20    "Draw only the layer section of the plot"
21   
22    def __init__(self, cdmsVar, gridType='latlon', projection='latlon', cmap = None,  cmapRange=(None,None),
23                 transparent=False, numLines=10, fontSize='medium', labelInterval=1, 
24                 intervalColourbar=False, 
25                 intervalNames=None):
26       
27        self._contourDrawer = ContourDrawer()
28        self.numLines = numLines
29        self.cdmsVar = cdmsVar
30        self.fontSize = fontSize
31        self.labelInterval =labelInterval
32       
33        LayerDrawerBase.__init__(self, gridType=gridType, transparent=transparent, cmap=cmap, cmapRange=cmapRange)
34       
35    def _drawToAxes(self, axes, xLimits, yLimits):
36        """
37        Draw the contours onto the axes.
38        """
39       
40        grid = self._buildGrid(self.cdmsVar, xLimits, yLimits)
41       
42        #if the projection is 'latlon' then no transformation is needed.
43        if self.projection == 'latlon':
44            basemap = None
45        else:
46            map = self._getMap(xLimits, yLimits)
47            basemap = map.basemap       
48       
49        norm = self._cb.getNormalize(grid=grid)
50        cmap = self._cb.getColourMap(grid=grid)
51       
52        #set the bad colour to transparent
53        cmap.set_bad('w', 0.0)
54       
55        self._contourDrawer.draw(axes, grid, normalize=norm, cmap=cmap,
56                                 basemap=basemap, fontSize=self.fontSize)
57   
58    ### properties ###
59         
60    def __set_numLines(self, value):
61        self._contourDrawer.numContourLines = value
62   
63    def __get_numLines(self):
64        return self._contourDrawer.numContourLines
65
66    numLines = property(__get_numLines, __set_numLines)
67   
68    def __set_fontSize(self, value):
69        self._fontSize = value
70   
71    def __get_fontSize(self):
72        return self._fontSize
73
74    fontSize = property(__get_fontSize, __set_fontSize)
75   
76   
77    def __set_labelInterval(self, value):
78        self._contourDrawer.contourLabelInterval = value
79   
80    def __get_labelInterval(self):
81        return self._contourDrawer.contourLabelInterval
82
83    labelInterval = property(__get_labelInterval, __set_labelInterval)
84
85       
Note: See TracBrowser for help on using the repository browser.