Changeset 3903 for TI05-delivery


Ignore:
Timestamp:
16/05/08 15:31:56 (11 years ago)
Author:
domlowe
Message:

csml layer caching added at the layermapper level and at the getfeatureinfo level - this has significantly speeded up the wms

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/service/imps/wms_csmllayer.py

    r3902 r3903  
    2828     
    2929    """ 
     30    def __init__(self): 
     31        self.layermapcache={} 
    3032     
    3133    def _getInfo(self, feature): 
     
    6668        @raise ValueError: If no layers are available for these keywords.  
    6769        """ 
    68         print "hello" 
    6970        #print kwargs 
    7071        fileoruri=kwargs['fileoruri'] 
     72        if fileoruri in self.layermapcache.keys(): 
     73            #we've accessed this layer map before, get it from the cache dictionary 
     74            #print 'found layer map in cache' 
     75            return self.layermapcache[fileoruri] 
    7176          
    7277        #TODO - handle file paths/directories URIs in config 
     
    7782        if not os.path.exists(filename): 
    7883            raise Exception(str('CSML File could not be found: %s')%filename) 
    79         print filename     
    8084        ds=csml.parser.Dataset(filename) 
    8185             
     
    8690            layermap[feature.id]=CSMLLayer(title,abstract, dimensions, units, crss, feature) 
    8791        if len(layermap) > 0: 
     92            self.layermapcache[fileoruri]=layermap 
    8893            return layermap 
    8994        else: 
     
    125130            raise ValueError("Layer must provide a bounding box in EPSG:4326 " 
    126131                             "coordinates for compatibility with WMS-1.3.0") 
    127  
     132        self.featureinfofilecache={} #used for caching netcdf file in getFeatureInfo 
     133         
    128134    def getBBox(self, crs): 
    129135        """ 
     
    168174            #for now have to read netcdf back from  
    169175            #disk (limitiation of CSML api) 
    170             print ['h', result[1]] 
    171176            netcdf=cdms.open(result[1]) 
    172177            #and then delete the temporary file 
     
    204209        @param point: a tuple (x, y) in the supplied crs of the point 
    205210            being selected. 
    206         @param dimValues: A mapping of dimension names to dimansion values. 
     211        @param dimValues: A mapping of dimension names to dimension values. 
    207212        @return: A string containing the response. 
    208213 
    209214        """ 
    210215        print point 
    211         randomname= csml.csmllibs.csmlextra.getRandomID() + '.nc' 
    212         result= self._feature.subsetToGridSeries(config['tmpfilebuffer'], ncname=randomname, **dimValues) 
    213         #for now have to read netcdf back from disk (limitiation of CSML api) 
    214          
    215         f=cdms.open(result[1]) 
    216         #and then delete the temporary file 
    217         os.system('rm %s'%result[1]) 
    218         netcdf = f(self.title) 
    219         #Now grab the netCDF object for the point specified. 
     216        print format 
     217        print crs 
     218        print dimValues 
     219        print self._feature.id 
     220         
     221        #cached netcdf is indexed by a tuple of feature id and dimvalues - i.e. typically a particular time and Z value for that feature. 
     222        #look in dictionary for cached copy, and if so use that as the file object. 
     223        dictindex=str((self._feature.id, dimValues)) 
     224        if dictindex in self.featureinfofilecache: 
     225            print 'calling cache' 
     226            f=self.featureinfofilecache[dictindex] 
     227        else: #else, use the csml api to subset the feature afresh 
     228            print 'not calling cache' 
     229            randomname= csml.csmllibs.csmlextra.getRandomID() + '.nc' 
     230            result= self._feature.subsetToGridSeries(config['tmpfilebuffer'], ncname=randomname, **dimValues) 
     231            #for now have to read netcdf back from disk (limitation of CSML api) 
     232            f=cdms.open(result[1]) 
     233            #append to cache: 
     234            self.featureinfofilecache[dictindex]=f 
     235            #and then delete the temporary file 
     236            os.system('rm %s'%result[1]) 
     237         
     238        netcdf = f(self.title)  #netcdf here is a cdms transient variable 
     239         
     240        
     241        #Now grab the netCDF object for the point specified. 
    220242        #The reason for the 'cob' option is so that if the grid the data  
    221243        #is defined on does not have a grid point at the point specified,  
Note: See TracChangeset for help on using the changeset viewer.