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

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

New interface works in view.html

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, CdmsGrid
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, GridClass=CdmsGrid):
22        try:
23            title = cdmsVar.long_name
24        except AttributeError:
25            title = cdmsVar.id
26           
27        self._layer = SimpleCdmsLayer(cdmsVar, title, GridClass=GridClass)
28        self.abstract = None
29        self.crss = [GridClass.crs]
30        self.units = self._layer.units
31        self.dimensions = self._layer.dimensions
32
33    def getBBox(self, crs):
34        raise NotImplementedError
35
36    def getView(self, crs, dimValues=None, renderOpts={}):
37        if crs != self.crss[0]:
38            raise ValueError("CRS %s not supported on this layer" % crs)
39       
40        return CdmsLayerView(crs, dimValues, renderOpts, self)
41   
42
43class CdmsLayerView(ILayerView):
44    def __init__(self, crs, dimValues, renderOpts, layer):
45        self.crs = crs
46        self.dimValues = dimValues
47        self.renderOpts = renderOpts
48        self.layer = layer
49        self.bbox = NotImplemented
50
51        self._renderer = RGBARenderer(renderOpts['minValue'], renderOpts['maxValue'])
52
53    def getImage(self, bbox, width, height):
54        grid = self.layer._layer.selectGrid(bbox, self.dimValues)
55        cmap = get_cmap(self.renderOpts.get('cmap', 'jet'))
56
57        return self._renderer.renderGrid(grid, bbox, width, height, cmap)
58
59    def getCacheKey(self):
60        raise NotImplementedError
61   
Note: See TracBrowser for help on using the repository browser.