Changeset 3636 for DPPP


Ignore:
Timestamp:
17/03/08 17:48:33 (11 years ago)
Author:
mkochan
Message:

Made csmlGrapher use mapping of times to values, to avoid duplicates.

Location:
DPPP/kml/csml2kml/python/csml2kmlpylon/csml2kmlpylon/controllers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • DPPP/kml/csml2kml/python/csml2kmlpylon/csml2kmlpylon/controllers/csmlGrapher.py

    r3633 r3636  
    109109                    return datestr + 'Z' 
    110110             
    111             # Isolate time points     
     111            # Isolate time points 
    112112            times=feature.value.pointSeriesDomain.timePositionList.CONTENT.split() 
    113113            times = map(_enforce_UTC_timezone, times) 
    114              
    115             # Note the start and end date (they are actually date+time), and time span between them 
    116             start_date = dates.dateutil.parser.parse(times[0]) 
    117             end_date = dates.dateutil.parser.parse(times[-1]) 
    118             span = datestr2num(times[-1]) - datestr2num(times[0]) 
    119114 
    120115            # Make a list of times as float numbers being days passed since start of epoch (here 01-01-0001) 
    121116            elapsed_times = map(datestr2num, times) 
    122  
    123             # Generate tick locator and formatter; these determine the time axis: locator determines tick positions 
    124             # and formatter format of time 
    125             (tickLocator, tickFormatter) = dates.date_ticker_factory(span, numticks=8) 
    126  
    127             # We may need to do this for bodc data (i.e. not inline data) 
    128             # vals=feature.value.rangeSet.valueArray.valueComponent.insertedExtract.components.getDataFromChunks(0,19) 
    129117 
    130118            # Get values of the measured quantity 
    131119            ql = feature.value.rangeSet.quantityList 
    132120            vals = map(float, ql.CONTENT.split()) 
     121 
     122            print '---times (' + str(len(times)) + ' of them):\n' + str(times) 
     123            print '---vals (' + str(len(times)) + ' of them):\n' + str(vals) 
     124 
     125            # Make sure the times are sorted in ascending order (and rearrange the values accordingly), 
     126            # this is because we get them potentially unsorted from GeoServer. Also have to handle the sad fact, 
     127            # that sometimes we are getting duplicate time-value samples from the MIDAS dataset! 
     128            sortTimesExplicitly = True 
     129            if sortTimesExplicitly: 
     130                reorder = {} 
     131                for i in range(len(elapsed_times)): 
     132                    reorder[elapsed_times[i]] = i 
     133                elapsed_times = reorder.keys() 
     134                elapsed_times.sort() 
     135                times2 = [] 
     136                vals2 = [] 
     137                for et in elapsed_times: 
     138                    times2.append(times[reorder[et]]) 
     139                    vals2.append(vals[reorder[et]]) 
     140                times = times2 
     141                vals = vals2 
     142 
     143            print '---times (' + str(len(times)) + ' of them):\n' + str(times) 
     144            print '---vals (' + str(len(times)) + ' of them):\n' + str(vals) 
     145 
     146            # Note the start and end date (they are actually date+time), and time span between them 
     147 
     148            start_date = dates.num2date(elapsed_times[0]) 
     149            end_date = dates.num2date(elapsed_times[-1]) 
     150            span = elapsed_times[-1] - elapsed_times[0] 
     151 
     152            # Generate tick locator and formatter; these determine the time axis: locator determines tick positions 
     153            # and formatter format of time 
     154            print '---start_date:' + str(start_date) 
     155            print '---end_date:' + str(end_date) 
     156            print '---span: ' + str(span) 
     157            (tickLocator, tickFormatter) = dates.date_ticker_factory(span, numticks=8) 
    133158 
    134159            # Determine the units of measurement 
     
    139164                uom = uom.upper() 
    140165 
    141             # Make sure the times are sorted in ascending order (and rearrange the values accordingly) 
    142             sortTimesExplicitly = True 
    143             if sortTimesExplicitly: 
    144                 valuesAtTimes = {} 
    145                 for i in range(len(elapsed_times)): 
    146                     valuesAtTimes[elapsed_times[i]] = vals[i] 
    147                     elapsed_times.sort() 
    148                 for i in range(len(elapsed_times)): 
    149                     vals[i] = valuesAtTimes[elapsed_times[i]] 
    150166 
    151167            # Prepare the plot the figure (actual plotting actions are postponed until save) 
Note: See TracChangeset for help on using the changeset viewer.