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

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

Improved geoplot's behaviour when dealing with variables with axis in the order of lon/lat instead of lat/lon.

Line 
1"""
2A layer drawer that draws the grid boxes of the data onto an image object.
3"""
4
5import logging
6
7import geoplot.utils as geoplot_utils
8from geoplot.grid_drawer import GridDrawer
9from geoplot.layer_drawer import LayerDrawerBase
10
11log = logging.getLogger(__name__)
12
13class LayerDrawerGrid(LayerDrawerBase):
14    "Draw only the layer section of the plot"
15   
16    def __init__(self, cdmsVar, gridType='latlon', showGridLines=False, cmap=None, cmapRange=(None,None), outline=False,
17                 transparent=False, 
18                 intervalColourbar=False, 
19                 bgcolour='white',
20                 intervalNames=None):
21       
22        self._gridDrawer = GridDrawer()
23       
24        self.cdmsVar = cdmsVar
25        self.showGridLines = showGridLines
26        self.outline = outline
27       
28        LayerDrawerBase.__init__(self, gridType=gridType, transparent=transparent, cmap=cmap, cmapRange=cmapRange, bgcolour=bgcolour)
29       
30    def _drawToAxes(self, axes, xLimits, yLimits):
31        """
32        Creates a new grid object and draws it onto the axis.
33        """
34        #create a new grid, this grid will be in terms of lat/lon
35        grid = self._buildGrid(self.cdmsVar, xLimits, yLimits)
36       
37        # if the projection is latlon then there is no need to transform
38        # the data on the grid.
39        if self.projection == 'latlon':
40            basemap = None
41        else:
42            map = self._getMap(xLimits, yLimits)
43            basemap = map.basemap       
44       
45#        map = self._getMap(xLimits, yLimits)
46#        map.basemap.drawcoastlines(ax=axes, xLimits=xLimits, yLimits=yLimits)     
47       
48        norm = self._cb.getNormalize(grid=grid)
49        cmap = self._cb.getColourMap(grid=grid)
50
51        #set the bad colour to transparent
52        cmap.set_bad('w', 0.0)
53       
54        #draw the grid on the axis
55        self._gridDrawer.draw(axes, grid,
56                              basemap=basemap, 
57                              limits=(xLimits, yLimits),
58                              norm=norm,
59                              cmap=cmap)
60                             
61   
62    ### properties ###
63                       
64    def __set_showGridLines(self, value):
65        self._gridDrawer.showGridLines = value
66   
67    def __get_showGridLines(self):
68        return self._gridDrawer.showGridLines
69   
70    showGridLines = property(__get_showGridLines, __set_showGridLines) 
71   
72    def __set_outline(self, value):
73        self._gridDrawer.outline = value
74       
75    def __get_outline(self):
76        return self._gridDrawer.outline
77   
78    outline = property(__get_outline, __set_outline)
79 
Note: See TracBrowser for help on using the repository browser.