Mercurial Hosting > traffic-intelligence
changeset 511:ad518f0c3218
merged pulling from main
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 28 May 2014 17:46:38 -0400 |
parents | b0dac840c24f (current diff) 7978b286fcfa (diff) |
children | 81ff62a7c39f |
files | python/cvutils.py python/utils.py |
diffstat | 5 files changed, 31 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/python/cvutils.py Fri May 23 17:33:11 2014 -0400 +++ b/python/cvutils.py Wed May 28 17:46:38 2014 -0400 @@ -5,7 +5,7 @@ import cv2 opencvAvailable = True except ImportError: - print('OpenCV library could not be loaded (video replay functions will not be available)') + print('OpenCV library could not be loaded (video replay functions will not be available)') # TODO change to logging module opencvAvailable = False try: import skimage
--- a/python/ml.py Fri May 23 17:33:11 2014 -0400 +++ b/python/ml.py Wed May 28 17:46:38 2014 -0400 @@ -24,8 +24,8 @@ def train(self, samples, responses): self.model.train(samples, responses, params = self.params) - def predict(self, sample): - return np.float32(self.model.predict(s)) + def predict(self, samples): + return np.float32([self.model.predict(s) for s in samples]) class Centroid:
--- a/python/moving.py Fri May 23 17:33:11 2014 -0400 +++ b/python/moving.py Wed May 28 17:46:38 2014 -0400 @@ -805,11 +805,15 @@ at constant speed''' return predictPositionNoLimit(nTimeSteps, self.getPositionAtInstant(instant), self.getVelocityAtInstant(instant), externalAcceleration) - def classifyUserTypeSpeed(self, threshold, statisticsFunc = median): + def classifyUserTypeSpeed(self, threshold, statisticsFunc = median, ignoreNInstantsAtEnds = 0): '''Classifies slow and fast road users slow: non-motorized -> pedestrians fast: motorized -> cars''' - if statisticsFunc(self.velocities.norm()) >= threshold: + if ignoreNInstantsAtEnds > 0: + speeds = self.velocities.norm()[ignoreNInstantsAtEnds:-ignoreNInstantsAtEnds] + else: + speeds = self.velocities.norm() + if statisticsFunc(speeds) >= threshold: self.setUserType(userType2Num['car']) else: self.setUserType(userType2Num['pedestrian'])
--- a/python/pavement.py Fri May 23 17:33:11 2014 -0400 +++ b/python/pavement.py Wed May 28 17:46:38 2014 -0400 @@ -15,7 +15,7 @@ durabilities = {1: 98, #96 to 100 2: 85, #75 to 96 - 3: 72, #50 to 75 + 3: 62, #50 to 75 4: 32, #15 to 50 5: 7 #0 to 15 } @@ -106,12 +106,12 @@ '''Computes several winter maintenance indicators data = entretien_hivernal = pylab.csv2rec('C:\Users\Alexandre\Documents\Cours\Poly\Projet\mesures_entretien_hivernal\mesures_deneigement.txt', delimiter = ',')''' import datetime - somme_eau, somme_neige, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, compteur_somme_abrasif = 0,0,0,0,0,0,0,0,0 + somme_eau, somme_neige, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, compteur_premiere_neige, compteur_somme_abrasif = 0,0,0,0,0,0,0,0,0 if circuitReference in data['ref_circuit']: for i in range(len(data)): if data['ref_circuit'][i] == circuitReference and (data['date'][i] + datetime.timedelta(days = 6)) <= endDate and (data['date'][i] + datetime.timedelta(days = 6)) > startDate: - premiere_neige += data['premiere_neige'][i] + compteur_premiere_neige += float(data['premiere_neige'][i]) somme_neige += float(data['neige'][i]) somme_eau += float(data['eau'][i]) somme_abrasif += float(data['abrasif'][i]) @@ -119,7 +119,11 @@ somme_lc += float(data['lc'][i]) somme_lrg += float(data['lrg'][i]) somme_lrd += float(data['lrd'][i]) - compteur_somme_abrasif += float(data['autre_abrasif_binaire'][i]) + compteur_somme_abrasif += float(data['autre_abrasif_binaire'][i]) + if compteur_premiere_neige >= 1: + premiere_neige = 1 + else: + premiere_neige = 0 if compteur_somme_abrasif >= 1: autres_abrasifs = 1 else: @@ -133,7 +137,7 @@ return (somme_eau, somme_neige, neigeMTQ_sup_seuil, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs) -def ecWeatherIndicators(data, startDate, endDate, snowThreshold, weatherDatatype, minProportionMeasures = 0.): +def weatherIndicators(data, startDate, endDate, snowThreshold, weatherDatatype, minProportionMeasures = 0.): '''Computes the indicators from Environment Canada files (loaded as a recarray using csv2rec in data), between start and end dates (datetime.datetime objects) @@ -147,11 +151,12 @@ seuils_T = [20,15,10,5] deltas_T = [0,0,0,0] startIndex = find(data['date'] == startDate) - nDays = (endDate - startDate).days+1 - if startIndex.size != 0: - for i in range(startIndex, startIndex+int(nDays)): + nDays = int((endDate - startDate).days)+1 + if len(startIndex) > 0 and startIndex+nDays <= len(data): + startIndex = startIndex[0] + for i in range(startIndex, startIndex+nDays): if not np.isnan(data['tmax'][i]): - tmax = data['tmax'][i] + tmax = data['tmax'][i] else: tmax = None if not np.isnan(data['tmin'][i]): @@ -197,6 +202,7 @@ return [None]*2+[[None]*len(seuils_T)]+[None]*5 def mtqWeatherIndicators(data, startDate, endDate,tmax,tmin,tmoy): + print("Deprecated, use weatherIndicators") from matplotlib.mlab import find nbre_jours_T_negatif,nbre_jours_gel_degel,ecart_type_T = 0,0,0 compteur,nbre_jours_gel_consecutifs=0,0 @@ -296,7 +302,7 @@ dates = self.data[nonZeroIndices]['date_mesure'] measures = self.data[nonZeroIndices][dataLabel] for i in range(1, len(dates)): - nDaysTNegative, nDaysThawFreeze, deltaTemp, nConsecutiveFrozenDays, totalRain, totalSnow, snowAboveThreshold, stdevTemp = ecWeatherIndicators(weatherData, dates[i-1], dates[i], snowThreshold, weatherDataType, minProportionMeasures) + nDaysTNegative, nDaysThawFreeze, deltaTemp, nConsecutiveFrozenDays, totalRain, totalSnow, snowAboveThreshold, stdevTemp = weatherIndicators(weatherData, dates[i-1], dates[i], snowThreshold, weatherDataType, minProportionMeasures) if dates[i-1].year+1 == dates[i].year: winter = 1 if days[i-1]<365:
--- a/python/utils.py Fri May 23 17:33:11 2014 -0400 +++ b/python/utils.py Wed May 28 17:46:38 2014 -0400 @@ -32,7 +32,12 @@ return (k*stdev/tolerance)**2 def confidenceInterval(mean, stdev, nSamples, percentConfidence, trueStd = True, printLatex = False): - 'if trueStd, use normal distribution, otherwise, Student' + '''if trueStd, use normal distribution, otherwise, Student + + Use otherwise t.interval or norm.interval + ex: norm.interval(0.95, loc = 0., scale = 2.3/sqrt(11)) + t.interval(0.95, 10, loc=1.2, scale = 2.3/sqrt(nSamples)) + loc is mean, scale is sigma/sqrt(n) (for Student, 10 is df)''' from math import sqrt from scipy.stats.distributions import norm, t if trueStd: