Mercurial > hg > nsaunier > traffic-intelligence
comparison python/pavement.py @ 477:ed4166b0ba9d
merged
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 25 Mar 2014 19:43:47 -0400 |
| parents | 819eef979d3f |
| children | 6ebdd90ce3ee |
comparison
equal
deleted
inserted
replaced
| 476:6551a3cf1750 | 477:ed4166b0ba9d |
|---|---|
| 131 else: | 131 else: |
| 132 somme_eau, somme_neige, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs, neigeMTQ_sup_seuil = '','','','','','','','','','' | 132 somme_eau, somme_neige, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs, neigeMTQ_sup_seuil = '','','','','','','','','','' |
| 133 | 133 |
| 134 return (somme_eau, somme_neige, neigeMTQ_sup_seuil, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs) | 134 return (somme_eau, somme_neige, neigeMTQ_sup_seuil, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs) |
| 135 | 135 |
| 136 def ecWeatherIndicators(data, startDate, endDate, snowThreshold, datatype, minProportionMeasures = 0.): | 136 def ecWeatherIndicators(data, startDate, endDate, snowThreshold, weatherDatatype, minProportionMeasures = 0.): |
| 137 '''Computes the indicators from Environment Canada files | 137 '''Computes the indicators from Environment Canada files |
| 138 (loaded as a recarray using csv2rec in data), | 138 (loaded as a recarray using csv2rec in data), |
| 139 between start and end dates (datetime.datetime objects) | 139 between start and end dates (datetime.datetime objects) |
| 140 | 140 |
| 141 dataType is to indicate Environnement Canada data ('ec') or else MTQ | 141 weatherDataType is to indicate Environnement Canada data ('ec') or else MTQ |
| 142 minProportionMeasures is proportion of measures necessary to consider the indicators''' | 142 minProportionMeasures is proportion of measures necessary to consider the indicators''' |
| 143 from matplotlib.mlab import find | 143 from matplotlib.mlab import find |
| 144 nbre_jours_T_negatif,nbre_jours_gel_degel,pluie_tot,neige_tot,ecart_type_T = 0,0,0,0,0 | 144 nbre_jours_T_negatif,nbre_jours_gel_degel,pluie_tot,neige_tot,ecart_type_T = 0,0,0,0,0 |
| 145 compteur,nbre_jours_gel_consecutifs=0,0 | 145 compteur,nbre_jours_gel_consecutifs=0,0 |
| 146 tmoys = [] | 146 tmoys = [] |
| 156 tmax = None | 156 tmax = None |
| 157 if not np.isnan(data['tmin'][i]): | 157 if not np.isnan(data['tmin'][i]): |
| 158 tmin = data['tmin'][i] | 158 tmin = data['tmin'][i] |
| 159 else: | 159 else: |
| 160 tmin = None | 160 tmin = None |
| 161 if datatype == 'ec': | 161 if weatherDatatype == 'ec': |
| 162 if data['pluie_tot'][i] != None and not np.isnan(data['pluie_tot'][i]): | 162 if data['pluie_tot'][i] != None and not np.isnan(data['pluie_tot'][i]): |
| 163 pluie_tot += data['pluie_tot'][i] | 163 pluie_tot += data['pluie_tot'][i] |
| 164 if data['neige_tot'][i] != None and not np.isnan(data['neige_tot'][i]): | 164 if data['neige_tot'][i] != None and not np.isnan(data['neige_tot'][i]): |
| 165 neige_tot += data['neige_tot'][i] | 165 neige_tot += data['neige_tot'][i] |
| 166 if tmax != None: | 166 if tmax != None: |
| 277 | 277 |
| 278 def plotMarkingMeasures(self, measure, options = 'o', dayRatio = 1., **kwargs): | 278 def plotMarkingMeasures(self, measure, options = 'o', dayRatio = 1., **kwargs): |
| 279 for i in range(1,7): | 279 for i in range(1,7): |
| 280 self.plot('{}_{}'.format(measure, i), options, dayRatio, **kwargs) | 280 self.plot('{}_{}'.format(measure, i), options, dayRatio, **kwargs) |
| 281 | 281 |
| 282 def computeMarkingMeasureVariations(self, dataLabel, lanePositions, weatherData, snowThreshold, minProportionMeasures = 0.): | 282 def computeMarkingMeasureVariations(self, dataLabel, lanePositions, weatherData, snowThreshold, weatherDataType = 'ec', minProportionMeasures = 0.): |
| 283 '''Computes for each successive measurement | 283 '''Computes for each successive measurement |
| 284 lanePositions = None | 284 lanePositions = None |
| 285 measure variation, initial measure, time duration, weather indicators | 285 measure variation, initial measure, time duration, weather indicators |
| 286 | 286 |
| 287 TODO if measurements per lane, add a variable for lane position (position1 to 6) | 287 TODO if measurements per lane, add a variable for lane position (position1 to 6) |
| 294 nonZeroIndices = ~np.isnan(self.data[dataLabel]) | 294 nonZeroIndices = ~np.isnan(self.data[dataLabel]) |
| 295 days = self.data[nonZeroIndices]['jours'] | 295 days = self.data[nonZeroIndices]['jours'] |
| 296 dates = self.data[nonZeroIndices]['date_mesure'] | 296 dates = self.data[nonZeroIndices]['date_mesure'] |
| 297 measures = self.data[nonZeroIndices][dataLabel] | 297 measures = self.data[nonZeroIndices][dataLabel] |
| 298 for i in range(1, len(dates)): | 298 for i in range(1, len(dates)): |
| 299 nDaysTNegative, nDaysThawFreeze, deltaTemp, nConsecutiveFrozenDays, totalRain, totalSnow, snowAboveThreshold, stdevTemp = ecWeatherIndicators(weatherData, dates[i-1], dates[i], snowThreshold, minProportionMeasures) | 299 nDaysTNegative, nDaysThawFreeze, deltaTemp, nConsecutiveFrozenDays, totalRain, totalSnow, snowAboveThreshold, stdevTemp = ecWeatherIndicators(weatherData, dates[i-1], dates[i], snowThreshold, weatherDataType, minProportionMeasures) |
| 300 if dates[i-1].year+1 == dates[i].year: | 300 if dates[i-1].year+1 == dates[i].year: |
| 301 winter = 1 | 301 winter = 1 |
| 302 if days[i-1]<365: | 302 if days[i-1]<365: |
| 303 firstWinter = 1 | 303 firstWinter = 1 |
| 304 else: | 304 else: |
