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

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

Improved the colour bar code so it now accepts the data array instead of just a minimum + maximum. It also now defaults to creating a Normalize instance with vmin=None and vmax=None instead of 0 and 1.

Also modified the layer_drawer objects to use the ColourBar? class instead of implementing it themselves.

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 Image
9import StringIO
10import thread
11
12import numpy as N
13
14from matplotlib.patches import Rectangle
15from matplotlib.figure import Figure
16from matplotlib.backends.backend_agg import FigureCanvasAgg
17from matplotlib.lines import Line2D
18
19from geoplot.grid_builder_lat_lon import GridBuilderLatLon
20from geoplot.grid_builder_national import GridBuilderNational
21from geoplot.grid_builder_rotated import GridBuilderRotated
22
23from geoplot.map_lat_lon import MapLatLon
24
25from geoplot.grid_drawer import GridDrawer
26import geoplot.utils as geoplot_utils
27
28from geoplot.layer_drawer import LayerDrawerBase
29from geoplot.colour_bar import ColourBar
30
31from matplotlib.colors import Normalize
32
33log = logging.getLogger(__name__)
34
35VALID_GRID_TYPES = ['latlon', 'national', 'rotated']
36
37class LayerDrawerGrid(LayerDrawerBase):
38    "Draw only the layer section of the plot"
39   
40    def __init__(self, cdmsVar, gridType='latlon', showGridLines=False, cmap=None, cmapRange=(None,None), outline=False,
41                 transparent=False):
42       
43
44        self._gridDrawer = GridDrawer()
45       
46        log.debug("cmapRange = %s" % (cmapRange,))
47       
48        if cmapRange[0] > cmapRange[1]:
49            log.warning("cmapRange[0] > cmapRange[1], swapping values")
50            cmapRange = (cmapRange[1], cmapRange[0])       
51       
52        self.cdmsVar = cdmsVar
53        self.showGridLines = showGridLines
54        self.outline = outline
55       
56        LayerDrawerBase.__init__(self, gridType=gridType, transparent=transparent, cmap=cmap, cmapRange=cmapRange)
57       
58    def _drawToAxes(self, axes, xLimits, yLimits):
59        """
60        Creates a new grid object and draws it onto the axis.
61        """
62        #create a new grid, this grid will be in terms of lat/lon
63        grid = self._buildGrid(self.cdmsVar, xLimits, yLimits)
64       
65        # if the projection is latlon then there is no need to transform
66        # the data on the grid.
67        if self.projection == 'latlon':
68            basemap = None
69        else:
70            map = self._getMap(xLimits, yLimits)
71            basemap = map.basemap       
72       
73        norm = self._cb.getNormalize()
74               
75        #draw the grid on the axis
76        self._gridDrawer.draw(axes, grid,
77                              basemap=basemap, 
78                              limits=(xLimits, yLimits),
79                              norm=norm,
80                              cmap=self._cb.getColourMap())
81                             
82   
83    ### properties ###
84                       
85    def __set_showGridLines(self, value):
86        self._gridDrawer.showGridLines = value
87   
88    def __get_showGridLines(self):
89        return self._gridDrawer.showGridLines
90   
91    showGridLines = property(__get_showGridLines, __set_showGridLines) 
92   
93    def __set_outline(self, value):
94        self._gridDrawer.outline = value
95       
96    def __get_outline(self):
97        return self._gridDrawer.outline
98   
99    outline = property(__get_outline, __set_outline)
100 
Note: See TracBrowser for help on using the repository browser.