Changeset 4228
- Timestamp:
- 24/09/08 15:19:12 (12 years ago)
- Location:
- cows/trunk
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
cows/trunk/cows/pylons/decorators.py
r4008 r4228 77 77 return _wrap_func(*args, **kwargs)""" % (func.__name__, wrap_sig) 78 78 79 print wrap_expr80 79 exec wrap_expr in wrap_vars 81 80 -
cows/trunk/cows/pylons/ows_controller.py
r4163 r4228 29 29 30 30 import logging 31 log ger= logging.getLogger(__name__)31 log = logging.getLogger(__name__) 32 32 33 33 # Instantiate Genshi template loader … … 78 78 return super(OWSControllerBase, self).__call__(environ, start_response) 79 79 except OWS_E.OwsError, e: 80 log ger.exception(e)80 log.exception(e) 81 81 82 82 tmpl = templateLoader.load('exception_report.xml') … … 87 87 # All OWS parameter names are case insensitive. 88 88 self._owsParams = {} 89 print request 90 #if request.has_key('REQUEST'): 91 #print request['REQUEST'] 89 log.debug('REQUEST: %s' % request) 92 90 for k in request.params: 93 91 if k.lower() == 'x': -
cows/trunk/cows/pylons/wms_controller.py
r4163 r4228 64 64 """ 65 65 #self.updateSequence = "hello" 66 print "loading layers"66 log.debug("loading layers") 67 67 #print self.layers 68 68 self.layers = self.layerMapper.map(**kwargs) … … 101 101 c.capabilities.contents = Contents() 102 102 for layerName, layer in self.layers.items(): 103 print layerName103 log.debug('LayerName: %s' % layerName) 104 104 log.debug('Loading layer %s' % layerName) 105 105 … … 180 180 181 181 """ 182 #print self.getOwsParam(paramName)183 182 layers = {} 184 183 layerNames = self.getOwsParam(paramName) … … 441 440 format = self.getOwsParam('info_format', default='text/html') 442 441 for layerName, layerObj in layers.iteritems(): 443 print format444 print layerObj.title445 print layerObj.featureInfoFormats442 log.debug('Format: %s' % format) 443 log.debug('Title: %s' % layerObj.title) 444 log.debug('FeatureInfoFormats: %s' % layerObj.featureInfoFormats) 446 445 if format not in layerObj.featureInfoFormats: 447 446 raise InvalidParameterValue('Layer %s does not support GetFeatureInfo in format %s' %(layerName, format), 'info_format') -
cows/trunk/cows/service/imps/StationCollection.py
r3786 r4228 19 19 20 20 def getStationsInBBox(self, minlat, minlon, maxlat, maxlon): 21 #print [minlat, minlon, maxlat, maxlon] 22 stationsInBbox = [] 21 stationsInBbox = [] 23 22 for station in self.stations: 24 23 if station.lat >= minlat: … … 42 41 curNearest = station 43 42 curDist = tempDist 44 #print curDist45 43 return curNearest 46 44 -
cows/trunk/cows/service/imps/pointrenderer.py
r4008 r4228 14 14 import pylons 15 15 16 import logging 17 log = logging.getLogger(__name__) 18 16 19 class PointRenderer(): 17 20 … … 27 30 bboxH = bbox[3] - bbox[1] 28 31 bboxA = bboxW * bboxH 29 print ["bbox area", bboxA]32 log.debug("bbox area %s" % bboxA) 30 33 31 34 #load the primary icon using the icon path … … 42 45 if station.checkDates("2006-01-01","2006-12-31"): 43 46 # then load a different icon to identify that, else keep the original icon 44 #print station.desc45 47 point = Image.open(icon+'1') 46 48 else: … … 50 52 # if bbox area is less than 100 then print name of each station next to its icon 51 53 if bboxA < 100: 52 #print ["plotting station", ox, oy, station.desc]53 54 tileImg.paste(self.txt2img(station.desc, "lubR08.pil"),(ox+16, oy+5) ) 54 55 -
cows/trunk/cows/service/imps/wms_csmllayer.py
r3954 r4228 110 110 @raise ValueError: If no layers are available for these keywords. 111 111 """ 112 #print kwargs113 112 fileoruri=kwargs['fileoruri'] 114 113 if fileoruri in self.layermapcache.keys(): 115 114 #we've accessed this layer map before, get it from the cache dictionary 116 #print 'found layer map in cache'117 115 return self.layermapcache[fileoruri] 118 116 … … 153 151 self._feature=feature 154 152 self.legendSize=(30,100) 155 153 bb= self._feature.getCSMLBoundingBox().getBox() 156 154 #convert 0 - 360 to -180, 180 as per common WMS convention 157 155 if abs(bb[2]-bb[0]) >= 359 and abs(bb[2]-bb[0]) < 361: 158 156 bb[0], bb[2]=-180, 180 159 160 157 self.wgs84BBox = bb 158 self.featureInfoFormats = ['text/html'] 161 159 try: 162 160 self.wgs84BBox = self.getBBox('EPSG:4326') … … 175 173 #if abs(bb[2]-bb[0]) >= 359 and abs(bb[2]-bb[0]) < 361: 176 174 # bb[0], bb[2]=-180, 180 177 175 #self.wgs84BBox = bb 178 176 return self.wgs84BBox 179 177 #raise NotImplementedError … … 207 205 result= self._feature.subsetToGridSeries(config['tmpfilebuffer'], ncname=randomname, **dimValues) 208 206 #for now have to read netcdf back from 209 207 #disk (limitiation of CSML api) 210 208 netcdf=cdms.open(result[1]) 211 209 #and then delete the temporary file … … 252 250 dictindex=str((self._feature.id, dimValues)) 253 251 if dictindex in self.featureinfofilecache: 254 print 'calling cache'252 log.debug('calling cache') 255 253 f=self.featureinfofilecache[dictindex] 256 254 else: #else, use the csml api to subset the feature afresh 257 print 'not calling cache'255 log.debug('not calling cache') 258 256 randomname= csml.csmllibs.csmlextra.getRandomID() + '.nc' 259 257 result= self._feature.subsetToGridSeries(config['tmpfilebuffer'], ncname=randomname, **dimValues) … … 264 262 #and then delete the temporary file 265 263 os.system('rm %s'%result[1]) 266 264 267 265 netcdf = f(self.title) #netcdf here is a cdms transient variable 268 266 269 267 270 268 #Now grab the netCDF object for the point specified. 271 272 273 274 275 276 277 278 print value279 print t_point.fill_value()280 281 282 283 284 285 286 287 288 289 print [value, fill_value] 290 291 292 293 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) 294 292 # finally return the value 295 293 return value … … 407 405 def __init__(self, layer, netcdf, bbox, width, height): 408 406 #we know the axes are called latitude and longitude as the CSML code has written it: 409 #print netcdf410 407 v=netcdf(layer.title) 411 #print v412 408 tvar=v(latitude=(bbox[1], bbox[3]), longitude=(bbox[0],bbox[2]),squeeze=1) 413 409 order=tvar.getOrder() 414 410 #array of data 415 411 self.value=tvar.getValue() 416 #print self.value417 #order of axes418 412 if order == 'xy': 419 413 self.ix=0 … … 428 422 self.dx=abs(lon[0]-lon[1]) 429 423 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 438 428 439 429 self.nx=len(lon) -
cows/trunk/cows/service/imps/wms_layers.py
r4106 r4228 18 18 from matplotlib import dates 19 19 20 import logging 21 log = logging.getLogger(__name__) 20 22 21 23 class WMSLayerMapper(object): … … 39 41 if not os.path.exists(filename): 40 42 raise Exception(str('Config File could not be found: %s')%filename) 41 print filename42 43 log.debug('Initialising WMS layermapper from %s' % filename) 44 43 45 #instantiate LayerParser class with the value of 'layer_config' as parameter to read layer infromation 44 46 layerparser = LayerParser(filename) … … 47 49 layers = layerparser.getLayers() 48 50 for feature in layers: 49 51 # read information necessary to create a StationLayer object 50 52 title, abstract, crss,formats, serverURL, icon, featureName, dataSet, bbox, dataSetURL =self._getInfo(feature) 51 53 # URL required to query the relevant WFS server to acquire a list of station for the current layer in the loop 52 54 geoServerUrl =serverURL+'/wfs?request=getfeature&service=wfs&version=1.1.0&typename='+featureName+'&maxfeatures=100' 53 print geoServerUrl55 log.debug('Geoserver URL: %s' % geoServerUrl) 54 56 geoServerResponse = wget(geoServerUrl) 55 57 stationCollection=StationCollection(geoServerResponse) 56 58 # specify the filepath for the static image to be used for representing each station in the GetMap image 57 59 icon =config['csml_config']+'/img/'+icon 58 print icon59 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 60 62 layermap[feature.findtext("Name")]=StationLayer(title,abstract, crss, stationCollection,bbox, formats, icon, dataSet, dataSetURL) 61 63 if len(layermap) > 0: … … 80 82 crs=feature.findtext("SRS") 81 83 crss=[crs] 82 print crss 84 log.debug('crss: %s' % crss) 83 85 formats = [] 84 85 86 86 87 #read supported getFeatureInfo formats from the "SupportedFormats" element 88 sFElem = feature.getchildren()[4] 87 89 for format in sFElem.getchildren(): 88 89 90 91 90 formats.append(format.text) 91 92 # read orignal bbox info 93 bboxElem = feature.getchildren()[5] 92 94 bbox=[int(bboxElem.getchildren()[0].text),int(bboxElem.getchildren()[1].text),int(bboxElem.getchildren()[2].text),int(bboxElem.getchildren()[3].text)] 93 94 95 96 97 98 99 100 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 101 103 return title, abstract, crss, formats, serverURL, icon, featureName,dataSet, bbox, dataSetURL 102 104 … … 105 107 106 108 def map(self, **kwargs): 107 109 '''this function is called by the wms_controller class to acquire information about all available layers''' 108 110 return self.layermap 109 111 … … 125 127 126 128 def __init__(self, title, abstract, crss, stationCollection, wgs84BBox, formats, icon,dataSet, dataSetURL): 127 129 self.title=title 128 130 self.abstract=abstract 129 131 self.crss=crss 130 132 self.legendSize=(300,60) 131 133 self.dimensions ={} 132 134 self.stationCollection = stationCollection 133 135 self.featureInfoFormats= formats 134 135 136 137 136 self.wgs84BBox=wgs84BBox 137 self.dataSet = dataSet 138 self.dataSetURL = dataSetURL 139 self.icon = icon 138 140 def getBBox(self, crs): 139 141 """ … … 177 179 return None 178 180 #raise NotImplementedError 179 181 180 182 def getFeatureInfo(self, format, crs, point, dimValues): 181 183 """ 182 184 Return a response string descibing the feature at a given 183 185 point in a given CRS. 184 185 186 187 Currently only "html" is supported as output format 186 188 187 189 @param format: One of self.featureInfoFormats. Defines which … … 192 194 @param dimValues: A mapping of dimension names to dimansion values. 193 195 @return: A string containing the response. 194 195 """ 196 print point 197 198 199 print nearestStation.desc200 201 202 203 204 205 print responseURL 206 207 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>" 208 210 return response 209 211 … … 216 218 217 219 """ 218 219 220 221 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 222 224 if 'width' in renderOpts: 223 224 225 226 227 228 229 230 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 231 233 withData= Image.open(self.icon+'1') 232 234 legImage.paste(withoutData, (0,0)) 233 235 legImage.paste(renderer.txt2img(self.title+' without dataset', "helvB08.pil"),(30, 5) ) 234 235 236 legImage.paste(withData, (0, 30)) 237 legImage.paste(renderer.txt2img(self.title+' with dataset', "helvB08.pil"),(30, 35) ) 236 238 return legImage 237 239 … … 286 288 287 289 """ 288 print bbox290 log.debug('BBOX: %s' % bbox) 289 291 stationsInBbox = self.stationCollection.getStationsInBBox(bbox[1],bbox[0],bbox[3], bbox[2]) 290 292 291 292 293 294 cmap=eval(config['colourmap']) 293 295 renderer=PointRenderer() 294 296 return renderer.renderPoint(bbox, stationsInBbox, width, height, cmap,self.icon)
Note: See TracChangeset
for help on using the changeset viewer.