Changeset 5682 for cows


Ignore:
Timestamp:
03/09/09 11:39:09 (10 years ago)
Author:
pnorton
Message:

Tidied up the datareader geoplot layer slabs so that there is only one class now, there was so little code in the style specific slabs that there seemed little point in keeping them.

Implemented a Modis file reader that reads and extracts a number of layers from a modis file on the filesystem. Currently the generated images appear to be the wrong way up but I can't find out why.

Location:
cows/trunk/cows
Files:
2 added
2 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • cows/trunk/cows/pylons/config.py

    r4914 r5682  
    1818    """ 
    1919    from cows.service.imps.csmlbackend.config import config 
     20    from cows.service.imps.data_reader_geoplot_backend.data_readers.mosid_config import config as modis_config 
     21     
    2022    for k in pylons.config: 
    2123        parts = k.split('.') 
     
    2325            k2 = '.'.join(parts[2:]) 
    2426            config[k2] = pylons.config[k] 
     27             
     28        elif parts[:2] == ['cows','modis']: 
     29            k2 = '.'.join(parts[2:]) 
     30            modis_config[k2] = pylons.config[k] 
    2531 
    2632 
  • cows/trunk/cows/service/imps/data_reader_geoplot_backend/data_reader_geoplot_layer_mapper.py

    r5676 r5682  
    1313 
    1414from 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 
    1516 
    1617log = logging.getLogger(__name__) 
     
    2021    def __init__(self): 
    2122        self.layermapcache={} 
    22          
    23         self.readerClasses = [CSMLDataReader] 
     23        self.readerClasses = [CSMLDataReader, ModisFileReader] 
    2424    
    25  
    2625    def map(self, **kwargs): 
    2726        """ 
  • cows/trunk/cows/service/imps/data_reader_geoplot_backend/data_reader_geoplot_wms_layer.py

    r5676 r5682  
    1717log = logging.getLogger(__name__) 
    1818 
    19 from cows.service.imps.data_reader_geoplot_backend.data_reader_geoplot_wms_layer_slab import DRGeoplotWmsLayerSlab 
    20 from cows.service.imps.data_reader_geoplot_backend.data_reader_geoplot_wms_layer_slab_contour import DRGeoplotWmsLayerSlabContour 
     19from cows.service.imps.data_reader_geoplot_backend.data_reader_geoplot_wms_layer_slab_base import DRGeoplotWmsLayerSlab, STYLES 
    2120from cows.service.imps.data_reader_geoplot_backend.data_reader_geoplot_render_options_parser import DRGeoplotRenderOptionsParser  
    2221 
     
    2726 
    2827from routes import url_for 
    29  
    30 class STYLES: 
    31     CONTOUR = 'contour' 
    32     GRID = 'grid' 
    33     DEFAULT = GRID 
    3428 
    3529class DRGeoplotWmsLayer(IwmsLayer): 
     
    111105        bbox=self.getBBox(crs) 
    112106         
    113         slabClass = self._getSlabClass(style) 
    114          
    115         slab = slabClass(netcdfVar, self.title, crs, dimValues, transparent, bbox, additionalParams) 
     107        slab = DRGeoplotWmsLayerSlab(netcdfVar, self.title, style, crs, dimValues, transparent, bbox, additionalParams) 
    116108                
    117109        return slab 
    118110   
    119     def _getSlabClass(self, style): 
    120         "Gets the slab class for a style value" 
    121          
    122         if style == None or style == "": 
    123             style = STYLES.DEFAULT 
    124              
    125         if style == STYLES.CONTOUR: 
    126             slabClass = DRGeoplotWmsLayerSlabContour 
    127         elif style == STYLES.GRID: 
    128             slabClass = DRGeoplotWmsLayerSlab 
    129         else: 
    130             raise Exception("Unknown style %s" % (style,)) 
    131          
    132         return slabClass 
    133                          
    134          
    135111    def getCacheKey(self, crs, style, dimValues, transparent, bgcolor,  
    136112                    additionalParams={}):  
  • cows/trunk/cows/service/imps/data_reader_geoplot_backend/data_reader_geoplot_wms_layer_slab_base.py

    r5676 r5682  
    66import numpy 
    77from geoplot.utils import isRangeInLimits 
     8from geoplot.layer_drawer_contour import LayerDrawerContour 
     9from geoplot.layer_drawer_grid import LayerDrawerGrid 
     10 
    811from cows.service.wms_iface import IwmsLayerSlab 
    912import Image 
     
    1114log = logging.getLogger(__name__) 
    1215 
    13 class DRGeoplotWmsLayerSlabBase(IwmsLayerSlab): 
     16 
     17class STYLES: 
     18    CONTOUR = 'contour' 
     19    GRID = 'grid' 
     20    DEFAULT = GRID 
     21     
     22    @staticmethod 
     23    def all(): 
     24        return [STYLES.CONTOUR, STYLES.GRID] 
     25 
     26class DRGeoplotWmsLayerSlab(IwmsLayerSlab): 
    1427    """ 
    1528    A layer slab that implements the IwmsLayerSlab interface and uses geoplot 
     
    1932    """ 
    2033 
    21     """ 
    22     contstructor 
    23      
    24     @param netcdf: the netcdf variable that contains the data for this slab 
    25     @param title: the title of the variable that is to be used 
    26     @param crs: the coordinate refrence system the data is stored in 
    27     @param dimValues: the dimension values for this slab 
    28     @param transparent: indicates if the produced image should be transparent or 
    29         not. 
    30     @param bbox: the bounds of the data in lat/lon 
    31     @param renderOpts: the additional parameters recieved by the WMS, may include 
    32         some custom rendering options. 
    33     """ 
    34     def __init__(self, variable, title, crs, dimValues, transparent, bbox, renderOpts): 
     34    def __init__(self, variable, title, style, crs, dimValues, transparent, bbox, renderOpts): 
     35        """ 
     36        contstructor 
     37         
     38        @param netcdf: the netcdf variable that contains the data for this slab 
     39        @param title: the title of the variable that is to be used 
     40        @param crs: the coordinate refrence system the data is stored in 
     41        @param dimValues: the dimension values for this slab 
     42        @param transparent: indicates if the produced image should be transparent or 
     43            not. 
     44        @param bbox: the bounds of the data in lat/lon 
     45        @param renderOpts: the additional parameters recieved by the WMS, may include 
     46            some custom rendering options. 
     47        """ 
    3548 
    3649        self.title = title 
     50         
     51        if style == None or style == "": 
     52            style = STYLES.DEFAULT 
     53             
     54        assert style in STYLES.all(), "Style %s not recognised" % (style,) 
     55         
     56        self.style = style 
     57         
    3758        self.crs = crs 
    3859        self.dimValues = dimValues 
     
    5071        self.ld = self._setupLayerDrawer() 
    5172     
    52     """ 
    53     Creates the layer drawer object so that it can be used in getImage 
    54     """ 
    5573    def _setupLayerDrawer(self): 
    56         raise NotImplementedError() 
    57      
    58     """ 
    59     returns an image of the data constructed using the layer drawer 
    60      
    61     @param bbox: the limits of the image requested 
    62     @param width: the width in px of the image 
    63     @param height: the height in px of the image 
    64     """ 
     74        """ 
     75        Creates the layer drawer object so that it can be used in getImage 
     76        """ 
     77         
     78        cmapRange = (self.parser.getOption('cmap_min'), self.parser.getOption('cmap_max')) 
     79         
     80        kwargs = { 
     81            'cmapRange':cmapRange, 
     82            'transparent':self.transparent, 
     83            'cmap':self.parser.getOption('cmap'), 
     84        } 
     85         
     86        if self.style == STYLES.CONTOUR: 
     87             
     88            ld = LayerDrawerContour(self.variable,  
     89                             labelInterval= self.parser.getOption('contour_label_interval'), 
     90                             numLines = self.parser.getOption('num_contour_lines'), 
     91                             fontSize = self.parser.getOption('contour_font_size'), 
     92                             **kwargs) 
     93             
     94        elif self.style == STYLES.GRID: 
     95             
     96            ld = LayerDrawerGrid(self.variable,  
     97                     showGridLines=self.parser.getOption('show_grid_lines'),  
     98                     **kwargs) 
     99         
     100        return ld 
     101         
    65102    def getImage(self, bbox, width, height): 
    66103        """ 
    67         Create an image of a sub-bbox of a given size. 
    68  
    69         @ivar bbox: A bbox 4-tuple. 
    70         @ivar width: width in pixels.`   
    71         @ivar height: height in pixels. 
    72         @return: A PIL Image object. 
    73  
     104        returns an image of the data constructed using the layer drawer 
     105         
     106        @param bbox: the limits of the image requested 
     107        @param width: the width in px of the image 
     108        @param height: the height in px of the image 
    74109        """ 
    75         #log.debug("GetImage called with bbox=%s, width=%s, height = %s" % (bbox, width, height,)) 
    76110        xLimits = (bbox[0], bbox[2]) 
    77111        yLimits = (bbox[1], bbox[3]) 
     
    96130         
    97131        return im 
     132 
     133     
    98134 
    99135    def _areBoundsInLimits(self, bbox, xLimits, yLimits): 
  • cows/trunk/cows/service/imps/data_reader_geoplot_backend/data_readers/csml_data_reader.py

    r5676 r5682  
    145145        else: 
    146146            variable = self.varcache[cacheKey] 
    147              
     147         
     148         
     149        log.debug("variable.getAxisList() = %s" % (variable.getAxisList(),)) 
     150         
    148151        return variable 
    149152     
Note: See TracChangeset for help on using the changeset viewer.