Changeset 3784
- Timestamp:
- 15/04/08 14:27:58 (13 years ago)
- Location:
- DPPP/kml/python/csml2kmlpylon
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
DPPP/kml/python/csml2kmlpylon/csml2kmlpylon.egg-info/PKG-INFO
r3657 r3784 1 1 Metadata-Version: 1.0 2 2 Name: csml2kmlpylon 3 Version: 1.0 b3 Version: 1.0.1b 4 4 Summary: Web service providing dynamic content for KML documents generated by the csml2kml package. 5 5 Home-page: UNKNOWN -
DPPP/kml/python/csml2kmlpylon/csml2kmlpylon.egg-info/SOURCES.txt
r3782 r3784 7 7 test.ini 8 8 csml2kmlpylon/__init__.py 9 csml2kmlpylon/__init__.pyc10 9 csml2kmlpylon/websetup.py 11 10 csml2kmlpylon.egg-info/PKG-INFO … … 18 17 csml2kmlpylon.egg-info/top_level.txt 19 18 csml2kmlpylon/config/__init__.py 20 csml2kmlpylon/config/__init__.pyc21 19 csml2kmlpylon/config/csml2kmlpylon.conf.xml 22 20 csml2kmlpylon/config/environment.py 23 csml2kmlpylon/config/environment.pyc24 21 csml2kmlpylon/config/middleware.py 25 csml2kmlpylon/config/middleware.pyc26 22 csml2kmlpylon/config/routing.py 27 csml2kmlpylon/config/routing.pyc28 23 csml2kmlpylon/controllers/__init__.py 29 csml2kmlpylon/controllers/ __init__.pyc24 csml2kmlpylon/controllers/auth.py 30 25 csml2kmlpylon/controllers/csmlGrapher.py 31 csml2kmlpylon/controllers/csmlGrapher.pyc32 26 csml2kmlpylon/controllers/error.py 33 27 csml2kmlpylon/controllers/template.py 34 28 csml2kmlpylon/lib/__init__.py 35 csml2kmlpylon/lib/__init__.pyc36 29 csml2kmlpylon/lib/app_globals.py 37 csml2kmlpylon/lib/app_globals.pyc38 30 csml2kmlpylon/lib/base.py 39 31 csml2kmlpylon/lib/helpers.py 40 csml2kmlpylon/lib/helpers.pyc41 32 csml2kmlpylon/model/__init__.py 42 33 csml2kmlpylon/public/index.html … … 44 35 csml2kmlpylon/tests/test_models.py 45 36 csml2kmlpylon/tests/functional/__init__.py 37 csml2kmlpylon/tests/functional/test_auth.py 46 38 docs/index.txt -
DPPP/kml/python/csml2kmlpylon/csml2kmlpylon/controllers/csmlGrapher.py
r3782 r3784 167 167 return csmlPointSeriesFeature 168 168 169 @authorize(ValidAuthKitUser())170 169 def plot(self): 171 170 ''' … … 179 178 Response: An image/png of the time series for the CSML PointSeries feature. 180 179 ''' 181 def _plot_feature(feature, dataset):182 '''183 Plot a PointSeries feature using matplotlib, into a temporary file.184 @return: An file-like object which represents the file, which can be read from and also closed185 as a normal file.186 @rtype: C{tempfile.NamedTemporaryFile}187 '''188 189 # Make sure that time is considered to be UTC time. This is because all CSML data is supposed to be in UTC,190 # but actually pylab is "time zone aware" and will interpret the time as local time zone time.191 # Not quite sure if this would be a problem, but rather enforce it is UTC.192 def _enforce_UTC_timezone(datestr):193 if datestr[-1] == 'Z':194 return datestr195 else:196 return datestr + 'Z'197 198 # Isolate time points199 times=feature.value.pointSeriesDomain.timePositionList.CONTENT.split()200 times = map(_enforce_UTC_timezone, times)201 202 # Make a list of times as float numbers being days passed since start of epoch (here 01-01-0001).203 # (We need to use the wrapping function csml2kml.utils.parseTimestamp() because unfortunately the matplotlib's204 # datetime parser cannot handle timestamps like "2004-02-17T24:00:00" directly.)205 elapsed_times = map(date2num,206 map(csml2kml.utils.parseTimestamp,207 times208 )209 )210 211 # Get values of the measured quantity212 ql = feature.value.rangeSet.quantityList213 vals = map(float, ql.CONTENT.split())214 215 # Make sure the times are sorted in ascending order (and rearrange the values accordingly),216 # this is because we get them potentially unsorted from GeoServer. Also have to handle the sad fact,217 # that sometimes we are getting duplicate time-value samples from the MIDAS dataset!218 sortTimesExplicitly = True219 if sortTimesExplicitly:220 reorder = {}221 for i in range(len(elapsed_times)):222 reorder[elapsed_times[i]] = i223 elapsed_times = reorder.keys()224 elapsed_times.sort()225 times2 = []226 vals2 = []227 for et in elapsed_times:228 times2.append(times[reorder[et]])229 vals2.append(vals[reorder[et]])230 times = times2231 vals = vals2232 233 print '---times (' + str(len(times)) + ' of them):\n' + str(times)234 print '---vals (' + str(len(times)) + ' of them):\n' + str(vals)235 236 # Note the start and end date (they are actually date+time), and time span between them237 238 start_date = dates.num2date(elapsed_times[0])239 end_date = dates.num2date(elapsed_times[-1])240 span = elapsed_times[-1] - elapsed_times[0]241 242 # Generate tick locator and formatter; these determine the time axis: locator determines tick positions243 # and formatter format of time. There will be a total of eight ticks.244 print '---start_date:' + str(start_date)245 print '---end_date:' + str(end_date)246 print '---span: ' + str(span)247 (tickLocator, tickFormatter) = dates.date_ticker_factory(span, numticks=8)248 249 # Determine the units of measurement250 uom=ql.uom.title()251 if ql.uom.islower():252 uom = uom.lower()253 if ql.uom.isupper():254 uom = uom.upper()255 256 # Prepare the plot of the figure (matplotlib does the actual plotting actions are postponed on file save)257 fig = figure()258 plot_date(elapsed_times, vals, 'b-', xdate=True, lw=1)259 plot_date(elapsed_times, vals, 'go', markeredgecolor = 'g', xdate=True, lw=2)260 ax = gca()261 ax.xaxis.set_major_locator(tickLocator)262 ax.xaxis.set_major_formatter(tickFormatter)263 fig.autofmt_xdate() # make sure times are shown with no overlapping timestamps264 time_format = '%d-%b-%Y %H:%M:%S UTC'265 xlabel('Times between %s and %s ' % (start_date.strftime(time_format), end_date.strftime(time_format)))266 ylabel('Values [%s]' % uom)267 title('"%s:%s" (%s station %s)' % (dataset.id, feature.id, dataset.name, feature.description.CONTENT))268 grid(True)269 270 # Save the figure to a temporary file271 tempFile = NamedTemporaryFile(suffix='.png')272 savefig(tempFile.name)273 274 return tempFile275 276 def _set_response(tempFile):277 """278 Set the service's response to an image, containing image read from a temporary location.279 @param tempFile: An object representing a temporary file280 @type tempFile: C{tempfile.NamedTemporaryFile}281 """282 img = Image.open(tempFile.name)283 buf = StringIO()284 img.save(buf, 'PNG')285 response.content_type = 'image/png'286 response.content = buf.getvalue()287 288 #---------------------- (function main body) -----------------------289 180 290 181 # Get parameters from the request object … … 296 187 raise HTTPBadRequest('Parameters "dataset_id", "feature_id" and "station_name" must be supplied.') 297 188 189 # Very hacky security because I only want to secure midas 190 secured_datasets = ['midas'] 191 if dataset_id in secured_datasets: 192 return self._plot_secured(dataset_id, feature_id, station_name) 193 else: 194 return self._plot2(dataset_id, feature_id, station_name) 195 196 @authorize(ValidAuthKitUser()) 197 def _plot_secured(self, dataset_id, feature_id, station_name): 198 return self._plot2(dataset_id, feature_id, station_name) 199 200 def _plot2(self, dataset_id, feature_id, station_name): 298 201 # Try to retrieve the csmlPointSeriesFeature object from the appropriate dataset 299 202 try: … … 399 302 response.content_type = 'text/html' 400 303 response.content = html 304 305 306 307 def _plot_feature(feature, dataset): 308 ''' 309 Plot a PointSeries feature using matplotlib, into a temporary file. 310 @return: An file-like object which represents the file, which can be read from and also closed 311 as a normal file. 312 @rtype: C{tempfile.NamedTemporaryFile} 313 ''' 314 315 # Make sure that time is considered to be UTC time. This is because all CSML data is supposed to be in UTC, 316 # but actually pylab is "time zone aware" and will interpret the time as local time zone time. 317 # Not quite sure if this would be a problem, but rather enforce it is UTC. 318 def _enforce_UTC_timezone(datestr): 319 if datestr[-1] == 'Z': 320 return datestr 321 else: 322 return datestr + 'Z' 323 324 # Isolate time points 325 times=feature.value.pointSeriesDomain.timePositionList.CONTENT.split() 326 times = map(_enforce_UTC_timezone, times) 327 328 # Make a list of times as float numbers being days passed since start of epoch (here 01-01-0001). 329 # (We need to use the wrapping function csml2kml.utils.parseTimestamp() because unfortunately the matplotlib's 330 # datetime parser cannot handle timestamps like "2004-02-17T24:00:00" directly.) 331 elapsed_times = map(date2num, 332 map(csml2kml.utils.parseTimestamp, 333 times 334 ) 335 ) 336 337 # Get values of the measured quantity 338 ql = feature.value.rangeSet.quantityList 339 vals = map(float, ql.CONTENT.split()) 340 341 # Make sure the times are sorted in ascending order (and rearrange the values accordingly), 342 # this is because we get them potentially unsorted from GeoServer. Also have to handle the sad fact, 343 # that sometimes we are getting duplicate time-value samples from the MIDAS dataset! 344 sortTimesExplicitly = True 345 if sortTimesExplicitly: 346 reorder = {} 347 for i in range(len(elapsed_times)): 348 reorder[elapsed_times[i]] = i 349 elapsed_times = reorder.keys() 350 elapsed_times.sort() 351 times2 = [] 352 vals2 = [] 353 for et in elapsed_times: 354 times2.append(times[reorder[et]]) 355 vals2.append(vals[reorder[et]]) 356 times = times2 357 vals = vals2 358 359 print '---times (' + str(len(times)) + ' of them):\n' + str(times) 360 print '---vals (' + str(len(times)) + ' of them):\n' + str(vals) 361 362 # Note the start and end date (they are actually date+time), and time span between them 363 364 start_date = dates.num2date(elapsed_times[0]) 365 end_date = dates.num2date(elapsed_times[-1]) 366 span = elapsed_times[-1] - elapsed_times[0] 367 368 # Generate tick locator and formatter; these determine the time axis: locator determines tick positions 369 # and formatter format of time. There will be a total of eight ticks. 370 print '---start_date:' + str(start_date) 371 print '---end_date:' + str(end_date) 372 print '---span: ' + str(span) 373 (tickLocator, tickFormatter) = dates.date_ticker_factory(span, numticks=8) 374 375 # Determine the units of measurement 376 uom=ql.uom.title() 377 if ql.uom.islower(): 378 uom = uom.lower() 379 if ql.uom.isupper(): 380 uom = uom.upper() 381 382 # Prepare the plot of the figure (matplotlib does the actual plotting actions are postponed on file save) 383 fig = figure() 384 plot_date(elapsed_times, vals, 'b-', xdate=True, lw=1) 385 plot_date(elapsed_times, vals, 'go', markeredgecolor = 'g', xdate=True, lw=2) 386 ax = gca() 387 ax.xaxis.set_major_locator(tickLocator) 388 ax.xaxis.set_major_formatter(tickFormatter) 389 fig.autofmt_xdate() # make sure times are shown with no overlapping timestamps 390 time_format = '%d-%b-%Y %H:%M:%S UTC' 391 xlabel('Times between %s and %s ' % (start_date.strftime(time_format), end_date.strftime(time_format))) 392 ylabel('Values [%s]' % uom) 393 title('"%s:%s" (%s station %s)' % (dataset.id, feature.id, dataset.name, feature.description.CONTENT)) 394 grid(True) 395 396 # Save the figure to a temporary file 397 tempFile = NamedTemporaryFile(suffix='.png') 398 savefig(tempFile.name) 399 400 return tempFile 401 402 def _set_response(tempFile): 403 """ 404 Set the service's response to an image, containing image read from a temporary location. 405 @param tempFile: An object representing a temporary file 406 @type tempFile: C{tempfile.NamedTemporaryFile} 407 """ 408 img = Image.open(tempFile.name) 409 buf = StringIO() 410 img.save(buf, 'PNG') 411 response.content_type = 'image/png' 412 response.content = buf.getvalue() 413
Note: See TracChangeset
for help on using the changeset viewer.