Ignore:
Timestamp:
03/03/08 16:42:12 (14 years ago)
Author:
spascoe
Message:

Testcard works demonstrating new WMS layer interface.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • DPPP/ukcip02_server/trunk/ukcip_server/ukcip_server/model/ukcip02.py

    r3533 r3551  
    1010from ukcip_server.model.pywms.wms_cdms import CdmsBNGGrid 
    1111from ukcip_server.model.pywms.impl import CdmsLayer 
     12from ows_common.service.wms_iface import ILayerMapper 
    1213 
    1314import cdms2 as cdms 
     
    1617log = logging.getLogger(__name__) 
    1718 
    18 data_dir = config['ukcip02.data_dir'] 
    1919log.debug('Data dir set to %s' % data_dir) 
    2020 
    21 layers = {} 
    22 datasets = {} 
    2321 
    24 for f in glob(os.path.join(data_dir, '*.nc')): 
    25     log.debug('Looking for layers in %s' % f) 
    26     ds = cdms.open(f) 
    27     for varName in ds.listvariables(): 
    28         log.debug('Found layer %s' % varName) 
    29         #!TODO: Min/Max values 
    30         layers[varName] = CdmsLayer(ds[varName], GridClass=CdmsBNGGrid) 
    31     datasets[f] = ds 
     22class UKCIP02LayerMapper(ILayerMapper): 
     23    def __init__(self): 
     24        self.dataDir = config['ukcip02.data_dir'] 
     25        log.debug('Data dir set to %s' % self.dataDir) 
     26 
     27    def map(self, **kwargs): 
     28        g = '%s*.nc' % kwargs['pattern'] 
     29        try: 
     30            f = glob(os.path.join(self.dataDir, g))[0] 
     31        except IndexError: 
     32            raise ValueError("No matching NetCDF found") 
     33 
     34        ds = cdms.open(f) 
     35        layers = {} 
     36        for varName in ds.listvariables(): 
     37            log.debug('Found layer %s' % varName) 
     38            #!TODO: Min/Max values 
     39            layers[varName] = CdmsLayer(ds[varName], GridClass=CdmsBNGGrid) 
     40 
     41        return layers 
    3242 
    3343# We need to hard-code the bbox for now 
Note: See TracChangeset for help on using the changeset viewer.