Mercurial Hosting > traffic-intelligence
comparison python/pavement.py @ 446:a65a14c90834
adding weather info to pavement data
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 04 Feb 2014 02:13:27 -0500 |
parents | b5cc6b001ae6 |
children | 7ef40014236c |
comparison
equal
deleted
inserted
replaced
445:f0ce17ea9273 | 446:a65a14c90834 |
---|---|
2 '''Tools for processing and analyzing pavement marking data''' | 2 '''Tools for processing and analyzing pavement marking data''' |
3 | 3 |
4 import numpy as np | 4 import numpy as np |
5 | 5 |
6 __metaclass__ = type | 6 __metaclass__ = type |
7 | |
8 class RTSS: | |
9 'class for data related to a RTSS, including agregating pavement marking measurements' | |
10 | |
11 def __init__(self, id): | |
12 self.id = id | |
13 | |
14 class MarkingTest: | |
15 '''class for a test site for a given product''' | |
16 | |
17 def __init__(self, siteId, paintingDate, paintingType, color, data): | |
18 self.siteId = siteId | |
19 self.paintingDate = paintingDate | |
20 self.paintingType = paintingType | |
21 self.color = color | |
22 self.data = data | |
23 self.nMeasures = len(data) | |
24 | |
25 def plot(self, measure, options = 'o', dayRatio = 1., **kwargs): | |
26 from matplotlib.pyplot import plot | |
27 plot(self.data['jours']/float(dayRatio), | |
28 self.data[measure], options, **kwargs) | |
29 | |
30 def getMarkingMeasures(self, dataLabel): | |
31 from numpy import isnan | |
32 nonZeroIndices = ~isnan(self.data[dataLabel]) | |
33 return self.data[nonZeroIndices]['jours'], self.data[nonZeroIndices][dataLabel] | |
34 | |
35 def plotMarkingMeasures(self, measure, options = 'o', dayRatio = 1., **kwargs): | |
36 for i in range(1,7): | |
37 self.plot('{}_{}'.format(measure, i), options, dayRatio, **kwargs) | |
38 | |
39 | 7 |
40 def occ_max(a): | 8 def occ_max(a): |
41 if a != []: | 9 if a != []: |
42 s = set(a) | 10 s = set(a) |
43 l = list(s) | 11 l = list(s) |
196 neigeEC_sup_seuil = 0 | 164 neigeEC_sup_seuil = 0 |
197 else: | 165 else: |
198 neigeEC_sup_seuil = 1 | 166 neigeEC_sup_seuil = 1 |
199 | 167 |
200 return (nbre_jours_T_negatif,nbre_jours_gel_degel, deltas_T, nbre_jours_gel_consecutifs, pluie_tot, neige_tot, neigeEC_sup_seuil, ecart_type_T) | 168 return (nbre_jours_T_negatif,nbre_jours_gel_degel, deltas_T, nbre_jours_gel_consecutifs, pluie_tot, neige_tot, neigeEC_sup_seuil, ecart_type_T) |
169 | |
170 | |
171 class RTSS: | |
172 'class for data related to a RTSS, including agregating pavement marking measurements' | |
173 | |
174 def __init__(self, id): | |
175 self.id = id | |
176 | |
177 class MarkingTest: | |
178 '''class for a test site for a given product | |
179 | |
180 including the series of measurements over the years''' | |
181 | |
182 def __init__(self, id, paintingDate, paintingType, color, data): | |
183 self.id = id | |
184 self.paintingDate = paintingDate | |
185 self.paintingType = paintingType | |
186 self.color = color | |
187 self.data = data | |
188 self.nMeasures = len(data) | |
189 | |
190 def getSite(self): | |
191 return int(self.id[:2]) | |
192 | |
193 def getTestAttributes(self): | |
194 return [self.paintingType, self.color] | |
195 | |
196 def plot(self, measure, options = 'o', dayRatio = 1., **kwargs): | |
197 from matplotlib.pyplot import plot | |
198 plot(self.data['jours']/float(dayRatio), | |
199 self.data[measure], options, **kwargs) | |
200 | |
201 def getMarkingMeasures(self, dataLabel): | |
202 from numpy import isnan | |
203 nonZeroIndices = ~isnan(self.data[dataLabel]) | |
204 return self.data[nonZeroIndices]['jours'], self.data[nonZeroIndices][dataLabel] | |
205 | |
206 def plotMarkingMeasures(self, measure, options = 'o', dayRatio = 1., **kwargs): | |
207 for i in range(1,7): | |
208 self.plot('{}_{}'.format(measure, i), options, dayRatio, **kwargs) | |
209 | |
210 def computeMarkingMeasureVariations(self, dataLabel, lanePositions, weatherData, snowThreshold): | |
211 '''Computes for each successive measurement | |
212 lanePositions = None | |
213 measure variation, initial measure, time duration, weather indicators | |
214 | |
215 TODO if measurements per lane, add a variable for lane position (position1 to 6) | |
216 lanePositions = list of integers (range(1,7)) | |
217 measure variation, initial measure, time duration, lane position1, weather indicators | |
218 measure variation, initial measure, time duration, lane position2, weather indicators | |
219 ...''' | |
220 from numpy import isnan | |
221 variationData = [] | |
222 if lanePositions == None: | |
223 nonZeroIndices = ~isnan(self.data[dataLabel]) | |
224 days = self.data[nonZeroIndices]['jours'] | |
225 dates = self.data[nonZeroIndices]['date_mesure'] | |
226 measures = self.data[nonZeroIndices][dataLabel] | |
227 for i in range(1, len(dates)): | |
228 nDaysTNegative, nDaysThawFreeze, deltaTemp, nConsecutiveFrozenDays, totalRain, totalSnow, snowAboveThreshold, stdevTemp = ecWeatherIndicators(weatherData, dates[i-1], dates[i], snowThreshold) | |
229 variationData.append([measures[i-1]-measures[i], measures[i-1], days[i]-days[i-1], nDaysTNegative, nDaysThawFreeze] + deltaTemp + [nConsecutiveFrozenDays, totalRain, totalSnow, snowAboveThreshold, stdevTemp]) | |
230 return variationData |