Changeset 4228


Ignore:
Timestamp:
24/09/08 15:19:12 (11 years ago)
Author:
spascoe
Message:

Changed print statements to loggging calls where appropriate.

Location:
cows/trunk
Files:
1 added
7 edited

Legend:

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

    r4008 r4228  
    7777    return _wrap_func(*args, **kwargs)""" % (func.__name__, wrap_sig) 
    7878 
    79     print wrap_expr 
    8079    exec wrap_expr in wrap_vars 
    8180 
  • cows/trunk/cows/pylons/ows_controller.py

    r4163 r4228  
    2929 
    3030import logging 
    31 logger = logging.getLogger(__name__) 
     31log = logging.getLogger(__name__) 
    3232 
    3333# Instantiate Genshi template loader 
     
    7878                return super(OWSControllerBase, self).__call__(environ, start_response) 
    7979            except OWS_E.OwsError, e: 
    80                 logger.exception(e) 
     80                log.exception(e) 
    8181 
    8282                tmpl = templateLoader.load('exception_report.xml') 
     
    8787        # All OWS parameter names are case insensitive. 
    8888        self._owsParams = {} 
    89         print request 
    90         #if request.has_key('REQUEST'): 
    91         #print request['REQUEST'] 
     89        log.debug('REQUEST: %s' % request) 
    9290        for k in request.params: 
    9391            if k.lower() == 'x': 
  • cows/trunk/cows/pylons/wms_controller.py

    r4163 r4228  
    6464        """ 
    6565        #self.updateSequence = "hello" 
    66         print "loading layers" 
     66        log.debug("loading layers") 
    6767        #print self.layers 
    6868        self.layers = self.layerMapper.map(**kwargs) 
     
    101101        c.capabilities.contents = Contents() 
    102102        for layerName, layer in self.layers.items(): 
    103             print layerName 
     103            log.debug('LayerName: %s' % layerName) 
    104104            log.debug('Loading layer %s' % layerName) 
    105105 
     
    180180 
    181181        """ 
    182         #print self.getOwsParam(paramName) 
    183182        layers = {} 
    184183        layerNames = self.getOwsParam(paramName) 
     
    441440        format = self.getOwsParam('info_format', default='text/html') 
    442441        for layerName, layerObj in layers.iteritems(): 
    443             print format 
    444             print layerObj.title 
    445             print layerObj.featureInfoFormats 
     442            log.debug('Format: %s' % format) 
     443            log.debug('Title: %s' % layerObj.title) 
     444            log.debug('FeatureInfoFormats: %s' % layerObj.featureInfoFormats) 
    446445        if format not in layerObj.featureInfoFormats: 
    447446            raise InvalidParameterValue('Layer %s does not support GetFeatureInfo in format %s' %(layerName, format), 'info_format') 
  • cows/trunk/cows/service/imps/StationCollection.py

    r3786 r4228  
    1919         
    2020    def getStationsInBBox(self, minlat, minlon, maxlat, maxlon): 
    21         #print [minlat, minlon, maxlat, maxlon] 
    22         stationsInBbox = [] 
     21        stationsInBbox = [] 
    2322        for station in self.stations: 
    2423            if station.lat >= minlat: 
     
    4241                        curNearest = station 
    4342                        curDist = tempDist 
    44         #print curDist 
    4543        return curNearest 
    4644 
  • cows/trunk/cows/service/imps/pointrenderer.py

    r4008 r4228  
    1414import pylons 
    1515 
     16import logging 
     17log = logging.getLogger(__name__) 
     18 
    1619class PointRenderer(): 
    1720 
     
    2730        bboxH = bbox[3] - bbox[1] 
    2831        bboxA = bboxW * bboxH 
    29         print ["bbox area", bboxA] 
     32        log.debug("bbox area %s" % bboxA) 
    3033 
    3134        #load the primary icon using the icon path 
     
    4245                if station.checkDates("2006-01-01","2006-12-31"): 
    4346                        # then load a different icon to identify that, else keep the original icon 
    44                         #print station.desc 
    4547                        point = Image.open(icon+'1') 
    4648                else: 
     
    5052                # if bbox area is less than 100 then print name of each station next to its icon 
    5153                if bboxA < 100: 
    52                         #print ["plotting station", ox, oy, station.desc] 
    5354                        tileImg.paste(self.txt2img(station.desc, "lubR08.pil"),(ox+16, oy+5) ) 
    5455 
  • cows/trunk/cows/service/imps/wms_csmllayer.py

    r3954 r4228  
    110110        @raise ValueError: If no layers are available for these keywords.  
    111111        """ 
    112         #print kwargs 
    113112        fileoruri=kwargs['fileoruri'] 
    114113        if fileoruri in self.layermapcache.keys(): 
    115114            #we've accessed this layer map before, get it from the cache dictionary 
    116             #print 'found layer map in cache' 
    117115            return self.layermapcache[fileoruri] 
    118116          
     
    153151        self._feature=feature 
    154152        self.legendSize=(30,100) 
    155         bb= self._feature.getCSMLBoundingBox().getBox() 
     153        bb= self._feature.getCSMLBoundingBox().getBox() 
    156154        #convert 0 - 360 to -180, 180 as per common WMS convention 
    157155        if abs(bb[2]-bb[0]) >= 359 and abs(bb[2]-bb[0]) < 361: 
    158156            bb[0], bb[2]=-180, 180 
    159         self.wgs84BBox = bb 
    160         self.featureInfoFormats = ['text/html'] 
     157        self.wgs84BBox = bb 
     158        self.featureInfoFormats = ['text/html'] 
    161159        try: 
    162160            self.wgs84BBox = self.getBBox('EPSG:4326') 
     
    175173        #if abs(bb[2]-bb[0]) >= 359 and abs(bb[2]-bb[0]) < 361: 
    176174        #    bb[0], bb[2]=-180, 180 
    177         #self.wgs84BBox = bb 
     175        #self.wgs84BBox = bb 
    178176        return self.wgs84BBox 
    179177        #raise NotImplementedError 
     
    207205            result= self._feature.subsetToGridSeries(config['tmpfilebuffer'], ncname=randomname, **dimValues) 
    208206            #for now have to read netcdf back from  
    209             #disk (limitiation of CSML api) 
     207            #disk (limitiation of CSML api) 
    210208            netcdf=cdms.open(result[1]) 
    211209            #and then delete the temporary file 
     
    252250        dictindex=str((self._feature.id, dimValues)) 
    253251        if dictindex in self.featureinfofilecache: 
    254             print 'calling cache' 
     252            log.debug('calling cache') 
    255253            f=self.featureinfofilecache[dictindex] 
    256254        else: #else, use the csml api to subset the feature afresh 
    257             print 'not calling cache' 
     255            log.debug('not calling cache') 
    258256            randomname= csml.csmllibs.csmlextra.getRandomID() + '.nc' 
    259257            result= self._feature.subsetToGridSeries(config['tmpfilebuffer'], ncname=randomname, **dimValues) 
     
    264262            #and then delete the temporary file 
    265263            os.system('rm %s'%result[1]) 
    266          
     264         
    267265        netcdf = f(self.title)  #netcdf here is a cdms transient variable 
    268266         
    269267        
    270268        #Now grab the netCDF object for the point specified. 
    271         #The reason for the 'cob' option is so that if the grid the data  
    272         #is defined on does not have a grid point at the point specified,  
    273         #we should  still get the nearest location 
    274          
    275         t_point = netcdf(latitude=(point[1], point[1], 'cob'), longitude=(point[0], point[0], 'cob')) 
    276         #now get the value recorded at this location 
    277         value = t_point.getValue().tolist() 
    278         print value 
    279         print t_point.fill_value() 
    280         #and the fill_value too 
    281         fill_value = t_point.fill_value() 
    282         #value is actually embedded in a multi dimensional list,  
    283         #so we need to extract the actual value from the list 
    284         while type(value) is list: 
    285                 value = value[0] 
    286  
    287         #now check if the value is actually the fill_value rather than  
    288         #a value recorded at the point specified 
    289         print [value, fill_value] 
    290         if (2*fill_value) == value: 
    291                 value = "No value found at position: "+str(point[1])+", "+str(point[0]) 
    292         else: 
    293                 value = "Value found at position: "+str(point[1])+", "+str(point[0])+" is: "+str(value) 
     269        #The reason for the 'cob' option is so that if the grid the data  
     270        #is defined on does not have a grid point at the point specified,  
     271        #we should  still get the nearest location 
     272         
     273        t_point = netcdf(latitude=(point[1], point[1], 'cob'), longitude=(point[0], point[0], 'cob')) 
     274        #now get the value recorded at this location 
     275        value = t_point.getValue().tolist() 
     276        log.debug(value) 
     277        log.debug(t_point.fill_value()) 
     278        #and the fill_value too 
     279        fill_value = t_point.fill_value() 
     280        #value is actually embedded in a multi dimensional list,  
     281        #so we need to extract the actual value from the list 
     282        while type(value) is list: 
     283                value = value[0] 
     284 
     285        #now check if the value is actually the fill_value rather than  
     286        #a value recorded at the point specified 
     287        log.debug('%s %s' % (value, fill_value)) 
     288        if (2*fill_value) == value: 
     289                value = "No value found at position: "+str(point[1])+", "+str(point[0]) 
     290        else: 
     291                value = "Value found at position: "+str(point[1])+", "+str(point[0])+" is: "+str(value) 
    294292        # finally return the value 
    295293        return value 
     
    407405    def __init__(self, layer, netcdf, bbox, width, height): 
    408406        #we know the axes are called latitude and longitude as the CSML code has written it: 
    409         #print netcdf 
    410407        v=netcdf(layer.title) 
    411         #print v 
    412408        tvar=v(latitude=(bbox[1], bbox[3]), longitude=(bbox[0],bbox[2]),squeeze=1) 
    413409        order=tvar.getOrder() 
    414410        #array of data 
    415411        self.value=tvar.getValue() 
    416         #print self.value 
    417         #order of axes 
    418412        if order == 'xy': 
    419413            self.ix=0 
     
    428422        self.dx=abs(lon[0]-lon[1]) 
    429423        self.dy=abs(lat[0]-lat[1]) 
    430         #print [lon, len(lon)] 
    431         #print len(self.value) 
    432         print len(lon) 
    433         print len(lat) 
    434  
    435      
    436  
    437          
     424         
     425     
     426 
     427         
    438428 
    439429        self.nx=len(lon) 
  • cows/trunk/cows/service/imps/wms_layers.py

    r4106 r4228  
    1818from matplotlib import dates  
    1919 
     20import logging 
     21log = logging.getLogger(__name__) 
    2022 
    2123class WMSLayerMapper(object): 
     
    3941        if not os.path.exists(filename): 
    4042            raise Exception(str('Config File could not be found: %s')%filename) 
    41         print filename 
    42          
     43        log.debug('Initialising WMS layermapper from %s' % filename) 
     44         
    4345        #instantiate LayerParser class with the value of 'layer_config' as parameter to read layer infromation 
    4446        layerparser = LayerParser(filename) 
     
    4749        layers = layerparser.getLayers() 
    4850        for feature in layers: 
    49             # read information necessary to create a StationLayer object 
     51            # read information necessary to create a StationLayer object 
    5052            title, abstract, crss,formats, serverURL, icon, featureName, dataSet, bbox, dataSetURL =self._getInfo(feature) 
    51             # URL required to query the relevant WFS server to acquire a list of station for the current layer in the loop 
     53            # URL required to query the relevant WFS server to acquire a list of station for the current layer in the loop 
    5254            geoServerUrl =serverURL+'/wfs?request=getfeature&service=wfs&version=1.1.0&typename='+featureName+'&maxfeatures=100' 
    53             print geoServerUrl 
     55            log.debug('Geoserver URL: %s' % geoServerUrl) 
    5456            geoServerResponse = wget(geoServerUrl) 
    5557            stationCollection=StationCollection(geoServerResponse) 
    56             # specify the filepath for the static image to be used for representing each station in the GetMap image 
     58            # specify the filepath for the static image to be used for representing each station in the GetMap image 
    5759            icon =config['csml_config']+'/img/'+icon 
    58             print icon 
    59             #instantiate a StationLayer object and store that in the layermap dictionary with the name of the layer as the key 
     60            log.debug('icon: %s' % icon) 
     61            #instantiate a StationLayer object and store that in the layermap dictionary with the name of the layer as the key 
    6062            layermap[feature.findtext("Name")]=StationLayer(title,abstract, crss, stationCollection,bbox, formats, icon, dataSet, dataSetURL) 
    6163        if len(layermap) > 0: 
     
    8082        crs=feature.findtext("SRS") 
    8183        crss=[crs] 
    82         print crss 
     84        log.debug('crss: %s' % crss) 
    8385        formats = [] 
    84          
    85         #read supported getFeatureInfo formats from the "SupportedFormats" element 
    86         sFElem = feature.getchildren()[4] 
     86         
     87        #read supported getFeatureInfo formats from the "SupportedFormats" element 
     88        sFElem = feature.getchildren()[4] 
    8789        for format in sFElem.getchildren(): 
    88                 formats.append(format.text) 
    89          
    90         # read orignal bbox info 
    91         bboxElem = feature.getchildren()[5] 
     90                formats.append(format.text) 
     91         
     92        # read orignal bbox info 
     93        bboxElem = feature.getchildren()[5] 
    9294        bbox=[int(bboxElem.getchildren()[0].text),int(bboxElem.getchildren()[1].text),int(bboxElem.getchildren()[2].text),int(bboxElem.getchildren()[3].text)] 
    93         #static image to be used for GetMap response 
    94         icon = feature.getchildren()[6].text 
    95         #read WFS server information 
    96         wfsElem = feature.getchildren()[7] 
    97         serverURL = wfsElem.getchildren()[0].text 
    98         featureName = wfsElem.getchildren()[1].text 
    99         dataSet = wfsElem.getchildren()[2].text 
    100         dataSetURL =  wfsElem.getchildren()[3].text 
     95        #static image to be used for GetMap response 
     96        icon = feature.getchildren()[6].text 
     97        #read WFS server information 
     98        wfsElem = feature.getchildren()[7] 
     99        serverURL = wfsElem.getchildren()[0].text 
     100        featureName = wfsElem.getchildren()[1].text 
     101        dataSet = wfsElem.getchildren()[2].text 
     102        dataSetURL =  wfsElem.getchildren()[3].text 
    101103        return title, abstract, crss, formats, serverURL, icon, featureName,dataSet, bbox, dataSetURL 
    102104 
     
    105107    
    106108    def map(self, **kwargs): 
    107         '''this function is called by the wms_controller class to acquire information about all available layers''' 
     109        '''this function is called by the wms_controller class to acquire information about all available layers''' 
    108110        return self.layermap 
    109111 
     
    125127 
    126128    def __init__(self, title, abstract, crss, stationCollection, wgs84BBox, formats, icon,dataSet, dataSetURL):         
    127         self.title=title 
     129        self.title=title 
    128130        self.abstract=abstract 
    129131        self.crss=crss 
    130132        self.legendSize=(300,60) 
    131         self.dimensions ={} 
     133        self.dimensions ={} 
    132134        self.stationCollection = stationCollection 
    133135        self.featureInfoFormats= formats 
    134         self.wgs84BBox=wgs84BBox 
    135         self.dataSet = dataSet 
    136         self.dataSetURL = dataSetURL 
    137         self.icon = icon 
     136        self.wgs84BBox=wgs84BBox 
     137        self.dataSet = dataSet 
     138        self.dataSetURL = dataSetURL 
     139        self.icon = icon 
    138140    def getBBox(self, crs): 
    139141        """ 
     
    177179        return None 
    178180        #raise NotImplementedError 
    179          
     181         
    180182    def getFeatureInfo(self, format, crs, point, dimValues): 
    181183        """ 
    182184        Return a response string descibing the feature at a given 
    183185        point in a given CRS.  
    184          
    185         Currently only "html" is supported as output format 
     186         
     187        Currently only "html" is supported as output format 
    186188 
    187189        @param format: One of self.featureInfoFormats.  Defines which 
     
    192194        @param dimValues: A mapping of dimension names to dimansion values. 
    193195        @return: A string containing the response. 
    194          
    195         """ 
    196         print point 
    197         nearestStation = self.stationCollection.getNearestStation(point[1], point[0]) 
    198          
    199         print nearestStation.desc 
    200          
    201          
    202         responseURL = self.dataSetURL+'/list?dataset_id='+self.dataSet+'&station_name='+nearestStation.desc 
    203         # replace space characters in the URL with %20 to avoid any URL validation error on the client side  
    204         responseURL = responseURL.replace(' ', '%20') 
    205         print responseURL 
    206         #finally construct the response, in this case it is in HTML with the responseURL represented as a hyperlink in it 
    207         response = "Description: <em>"+nearestStation.desc+"</em><br /><a href='"+responseURL+"'>"+responseURL+"</a>" 
     196         
     197        """ 
     198        log.debug('Point: %s' % point) 
     199        nearestStation = self.stationCollection.getNearestStation(point[1], point[0]) 
     200         
     201        log.debug('Nearest station: %s' % nearestStation.desc) 
     202         
     203         
     204        responseURL = self.dataSetURL+'/list?dataset_id='+self.dataSet+'&station_name='+nearestStation.desc 
     205        # replace space characters in the URL with %20 to avoid any URL validation error on the client side  
     206        responseURL = responseURL.replace(' ', '%20') 
     207        log.debug('Response URL: %s' % responseURL) 
     208        #finally construct the response, in this case it is in HTML with the responseURL represented as a hyperlink in it 
     209        response = "Description: <em>"+nearestStation.desc+"</em><br /><a href='"+responseURL+"'>"+responseURL+"</a>" 
    208210        return response 
    209211 
     
    216218 
    217219        """ 
    218         width = self.legendSize[0] 
    219         height = self.legendSize[1] 
    220         # if width and height specified in the GetLegend request parameters 
    221         # then use them instead of the default values 
     220        width = self.legendSize[0] 
     221        height = self.legendSize[1] 
     222        # if width and height specified in the GetLegend request parameters 
     223        # then use them instead of the default values 
    222224        if 'width' in renderOpts: 
    223                 width = renderOpts['width'] 
    224         if 'height' in renderOpts: 
    225                 height = renderOpts['height'] 
    226         renderer=PointRenderer() 
    227         legImage = Image.new('RGBA', (width, height), (0,0,0,0)) 
    228         # legend for stations without any associated dataset 
    229         withoutData = Image.open(self.icon) 
    230         # legend for stations that contain datasets 
     225                width = renderOpts['width'] 
     226        if 'height' in renderOpts: 
     227                height = renderOpts['height'] 
     228        renderer=PointRenderer() 
     229        legImage = Image.new('RGBA', (width, height), (0,0,0,0)) 
     230        # legend for stations without any associated dataset 
     231        withoutData = Image.open(self.icon) 
     232        # legend for stations that contain datasets 
    231233        withData= Image.open(self.icon+'1') 
    232234        legImage.paste(withoutData, (0,0)) 
    233235        legImage.paste(renderer.txt2img(self.title+' without dataset', "helvB08.pil"),(30, 5) ) 
    234         legImage.paste(withData, (0, 30)) 
    235         legImage.paste(renderer.txt2img(self.title+' with dataset', "helvB08.pil"),(30, 35) )         
     236        legImage.paste(withData, (0, 30)) 
     237        legImage.paste(renderer.txt2img(self.title+' with dataset', "helvB08.pil"),(30, 35) )         
    236238        return legImage 
    237239 
     
    286288 
    287289        """ 
    288         print bbox 
     290        log.debug('BBOX: %s' % bbox) 
    289291        stationsInBbox = self.stationCollection.getStationsInBBox(bbox[1],bbox[0],bbox[3], bbox[2]) 
    290292         
    291          
    292         cmap=eval(config['colourmap'])  
     293         
     294        cmap=eval(config['colourmap'])  
    293295        renderer=PointRenderer()          
    294296        return renderer.renderPoint(bbox, stationsInBbox, width, height, cmap,self.icon) 
Note: See TracChangeset for help on using the changeset viewer.