source: DPPP/ukcip02_server/trunk/ukcip_server/ukcip_server/model/pywms/impl.py @ 3532

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/DPPP/ukcip02_server/trunk/ukcip_server/ukcip_server/model/pywms/impl.py@3532
Revision 3532, 1.8 KB checked in by spascoe, 13 years ago (diff)

Moving to a different interface between the WMS controller and the
data. interfaces.py now contains ILayer et al. to represent layers
of data.

Line 
1"""
2Implements the WMS interfaces for simple CDMS variables
3
4This implementation is for backward compatibility between the old interface and
5the new.  Only one CRS per layer is supported.
6
7"""
8from interfaces import ILayer, ILayerView, IDimension
9from wms_cdms import SimpleCdmsLayer, CdmsTimeDimension
10import cdtime
11from render_imp import RGBARenderer
12from matplotlib.cm import get_cmap
13
14class CdmsLayer(ILayer):
15    """
16    The ILayer interface has superceded model.Layer and therefore CdmsLayer
17    does not inherit from model.Layer or SimpleCdmsLayer.  Instead encapsulation
18    is used.
19
20    """
21    def __init__(self, cdmsVar, title, GridClass=CdmsGrid):
22        self._layer = SimpleCdmsLayer(cdmsVar, title, GridClass)
23        self.abstract = None
24        self.crss = [GridClass.crs]
25        self.units = self._layer.units
26        self.dimensions = self._layer.dimensions
27
28    def getBBox(self, crs):
29        raise NotImplementedError
30
31    def getView(self, crs, dimValues=None, renderOpts={}):
32        if crs != GridClass.crs:
33            raise ValueError("CRS %s not supported on this layer" % crs)
34       
35        return CdmsLayerView(crs, dimValues, renderOpts, self)
36   
37
38class CdmsLayerView(ILayerView):
39    def __init__(self, crs, dimValues, renderOpts, layer):
40        self.crs = crs
41        self.dimValues = dimValues
42        self.renderOpts = renderOpts
43        self.layer = layer
44        self.bbox = NotImplemented
45
46        self._renderer = RGBARenderer(renderOpts['minValue'], renderOpts['maxValue'])
47
48    def getImage(self, bbox, width, height):
49        grid = self.layer.selectGrid(bbox, self.dimValues)
50        cmap = get_cmap(self.renderOpts.get('cmap', 'jet'))
51
52        return self._renderer.renderGrid(grid, bbox, width, height, self.renderOpts,
53                                         cmap)
54
55    def getCacheKey(self):
56        raise NotImplementedError
57   
Note: See TracBrowser for help on using the repository browser.