source: cows/trunk/cows/service/imps/data_reader_geoplot_backend/data_reader_geoplot_layer_mapper.py @ 5684

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/trunk/cows/service/imps/data_reader_geoplot_backend/data_reader_geoplot_layer_mapper.py@5684
Revision 5684, 2.5 KB checked in by pnorton, 11 years ago (diff)

Fixed a problem in the masking of the landtype_common variable from the modis_file_reader. The index 0 data was bing masked along with the cases where all the indicies are 0.0.

Also made some small improvements to the geoplot layers.

Line 
1'''
2Created on 9 Jun 2009
3
4@author: pnorton
5'''
6
7import logging
8from copy import copy
9
10from cows.service.wxs_iface import ILayerMapper
11
12from cows.service.imps.data_reader_geoplot_backend.data_reader_geoplot_wms_layer import DRGeoplotWmsLayer
13
14from cows.service.imps.data_reader_geoplot_backend.data_readers.csml_data_reader import CSMLDataReader
15from cows.service.imps.data_reader_geoplot_backend.data_readers.modis_file_reader import ModisFileReader
16
17log = logging.getLogger(__name__)
18
19class DRGeoplotLayerMapper(ILayerMapper):
20   
21    def __init__(self):
22        self.layermapcache={}
23        self.readerClasses = [CSMLDataReader, ModisFileReader]
24   
25    def map(self, **kwargs):
26        """
27        Given csml.parser.Dataset object list the names of
28        all layers available.
29       
30        @return: A mapping of layer names to ILayer implementations.
31        @raise ValueError: If no layers are available for these keywords.
32        """
33        fileoruri=kwargs['fileoruri']
34               
35        if fileoruri in self.layermapcache.keys():
36           
37            log.debug("cached layermap used for fileoruri = %s" % (fileoruri,))
38           
39            #we've accessed this layer map before, get it from the cache dictionary
40            return self.layermapcache[fileoruri]
41       
42
43        layermap={}
44       
45        reader = self._getReader(fileoruri)
46       
47        for name, title, abstract, dimensions, units, crss, bb in \
48                                     reader.getWMSLayerInfo():
49           
50            layermap[name] = DRGeoplotWmsLayer(name, title, abstract, dimensions, units, crss, bb, reader)
51           
52           
53        if len(layermap) > 0:
54            self.layermapcache[fileoruri]=layermap
55            return layermap
56        else:
57            raise ValueError
58       
59    def _getReader(self, fileoruri):
60        """
61        Searches the reader classes to find one that contains the data for
62        the fileoruri given, when found the class is returned. If no
63        reader class is found and Exception is raised.
64        """
65       
66        log.debug("CSMLDataReader.isDataPresent(fileoruri) = %s" % (CSMLDataReader.isDataPresent(fileoruri),))
67        reader = None
68       
69        for klass in self.readerClasses:
70            if klass.isDataPresent(fileoruri):
71                reader = klass(fileoruri)
72                break
73       
74        if reader == None:
75            raise Exception("No reader found for fileoruri = %s" % (fileoruri,))
76       
77        return reader
Note: See TracBrowser for help on using the repository browser.