source: qesdi/wms_ddc_vis/trunk/lib/wms_ddc_vis/model/ddc_wms_layer_slab_base.py @ 5529

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/qesdi/wms_ddc_vis/trunk/lib/wms_ddc_vis/model/ddc_wms_layer_slab_base.py@5529
Revision 5529, 2.8 KB checked in by pnorton, 11 years ago (diff)

Added the style specific display options to the grid and contour renderers. Also added the required JSON.

Line 
1import logging
2import time
3
4from wms_ddc_vis.model.ddc_render_options_parser import DDCRenderOptionsParser
5
6from cows.service.wms_iface import IwmsLayerSlab
7
8log = logging.getLogger(__name__)
9
10class DDCWmsLayerSlabBase(IwmsLayerSlab):
11    """
12    A layer slab that implements the IwmsLayerSlab interface and uses geoplot
13    to render the required images.
14   
15    This is an abstract base class and should not be used directly.
16    """
17
18    """
19    contstructor
20   
21    @param netcdf: the netcdf variable that contains the data for this slab
22    @param title: the title of the variable that is to be used
23    @param crs: the coordinate refrence system the data is stored in
24    @param dimValues: the dimension values for this slab
25    @param transparent: indicates if the produced image should be transparent or
26        not.
27    @param bbox: the bounds of the data in lat/lon
28    @param renderOpts: the additional parameters recieved by the WMS, may include
29        some custom rendering options.
30    """
31    def __init__(self, netcdf, title, crs, dimValues, transparent, bbox, renderOpts):
32        self._netcdf=netcdf
33        self.title = title
34        self.crs = crs
35        self.dimValues = dimValues
36        self.renderOpts = renderOpts
37        self.transparent = transparent
38        self.bbox=bbox
39       
40        self.variable =  self._netcdf(self.title, squeeze=1) 
41       
42        self.minval = self.variable.min()
43        self.maxval = self.variable.max()
44       
45        #log.debug("renderOpts = %s" % (renderOpts,))
46       
47        self.parser = DDCRenderOptionsParser(renderOpts, self.minval, self.maxval)
48        self.ld = self._setupLayerDrawer()
49   
50    """
51    Creates the layer drawer object so that it can be used in getImage
52    """
53    def _setupLayerDrawer(self):
54        raise NotImplementedError()
55   
56    """
57    returns an image of the data constructed using the layer drawer
58   
59    @param bbox: the limits of the image requested
60    @param width: the width in px of the image
61    @param height: the height in px of the image
62    """
63    def getImage(self, bbox, width, height):
64        """
65        Create an image of a sub-bbox of a given size.
66
67        @ivar bbox: A bbox 4-tuple.
68        @ivar width: width in pixels.` 
69        @ivar height: height in pixels.
70        @return: A PIL Image object.
71
72        """
73
74        log.debug('getImage(%s, %s, %s) ' % (bbox, width, height))
75       
76        xLimits = (bbox[0], bbox[2])
77        yLimits = (bbox[1], bbox[3])
78                       
79        st = time.time()
80        im = self.ld.makeImage(xLimits, yLimits, width, height)
81       
82        log.debug("generated contour image id=%s (%sx%s, lon=%s, lat=%s in %.2fs" % \
83                  (self.variable.id, width, height, xLimits, yLimits,  time.time() - st,))
84       
85        return im
86
87       
Note: See TracBrowser for help on using the repository browser.