Mercurial Hosting > traffic-intelligence
comparison python/pavement.py @ 440:b5cc6b001ae6
correction for tmax and returns as tuples
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 22 Jan 2014 23:41:32 -0500 |
parents | ad61d21d3d1b |
children | a65a14c90834 |
comparison
equal
deleted
inserted
replaced
439:ad61d21d3d1b | 440:b5cc6b001ae6 |
---|---|
116 peinture_lrg = occ_max(peinture_rg) | 116 peinture_lrg = occ_max(peinture_rg) |
117 peinture_lc = occ_max(peinture_cl) | 117 peinture_lc = occ_max(peinture_cl) |
118 else: | 118 else: |
119 peinture_lrd, peinture_lrg, peinture_lc = '','','' | 119 peinture_lrd, peinture_lrg, peinture_lc = '','','' |
120 | 120 |
121 return [exigence, x_moy, y_moy, age_revtm, classe_fonct, type_revtm, milieu, djma, djma_camions, peinture_lrd, peinture_lrg, peinture_lc] | 121 return (exigence, x_moy, y_moy, age_revtm, classe_fonct, type_revtm, milieu, djma, djma_camions, peinture_lrd, peinture_lrg, peinture_lc) |
122 | 122 |
123 def winterMaintenanceIndicators(data, startDate, endDate, circuitReference, snowThreshold): | 123 def winterMaintenanceIndicators(data, startDate, endDate, circuitReference, snowThreshold): |
124 '''Computes several winter maintenance indicators | 124 '''Computes several winter maintenance indicators |
125 data = entretien_hivernal = pylab.csv2rec('C:\Users\Alexandre\Documents\Cours\Poly\Projet\mesures_entretien_hivernal\mesures_deneigement.txt', delimiter = ',')''' | 125 data = entretien_hivernal = pylab.csv2rec('C:\Users\Alexandre\Documents\Cours\Poly\Projet\mesures_entretien_hivernal\mesures_deneigement.txt', delimiter = ',')''' |
126 import datetime | 126 import datetime |
147 else: | 147 else: |
148 neigeMTQ_sup_seuil = 1 | 148 neigeMTQ_sup_seuil = 1 |
149 else: | 149 else: |
150 somme_eau, somme_neige, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs, neigeMTQ_sup_seuil = '','','','','','','','','','' | 150 somme_eau, somme_neige, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs, neigeMTQ_sup_seuil = '','','','','','','','','','' |
151 | 151 |
152 return [somme_eau, somme_neige, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs, neigeMTQ_sup_seuil] | 152 return (somme_eau, somme_neige, neigeMTQ_sup_seuil, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs) |
153 | 153 |
154 def ecWeatherIndicators(data, startDate, endDate): | 154 def ecWeatherIndicators(data, startDate, endDate, snowThreshold): |
155 '''Computes the indicators from Environment Canada files | 155 '''Computes the indicators from Environment Canada files |
156 (loaded as a recarray using csv2rec in data), | 156 (loaded as a recarray using csv2rec in data), |
157 between start and end dates (datetime.datetime objects)''' | 157 between start and end dates (datetime.datetime objects)''' |
158 nbre_jours_T_negatif,nbre_jours_gel_degel,pluie_tot,neige_tot,ecart_type_T = 0,0,0,0,0 | 158 nbre_jours_T_negatif,nbre_jours_gel_degel,pluie_tot,neige_tot,ecart_type_T = 0,0,0,0,0 |
159 compteur,nbre_jours_gel_consecutifs=0,0 | 159 compteur,nbre_jours_gel_consecutifs=0,0 |
161 seuils_T = [20,15,10,5] | 161 seuils_T = [20,15,10,5] |
162 deltas_T = [0,0,0,0] | 162 deltas_T = [0,0,0,0] |
163 for i in range(int((endDate - startDate).days)+1): | 163 for i in range(int((endDate - startDate).days)+1): |
164 if data['tmax'][i] != '' and data['tmax'][i] != None: | 164 if data['tmax'][i] != '' and data['tmax'][i] != None: |
165 tmax = float(data['tmax'][i].replace(',','.')) | 165 tmax = float(data['tmax'][i].replace(',','.')) |
166 else: | |
167 tmax = None | |
166 if data['tmin'][i] != '' and data['tmin'][i] != None: | 168 if data['tmin'][i] != '' and data['tmin'][i] != None: |
167 tmin = float(data['tmin'][i].replace(',','.')) | 169 tmin = float(data['tmin'][i].replace(',','.')) |
168 if data['pluie_tot'][i] != '' and data['pluie_tot'][i] != None: | 170 if data['pluie_tot'][i] != '' and data['pluie_tot'][i] != None: |
169 pluie_tot += float(data['pluie_tot'][i].replace(',','.')) | 171 pluie_tot += float(data['pluie_tot'][i].replace(',','.')) |
170 if data['neige_tot'][i] != '' and data['neige_tot'][i] != None: | 172 if data['neige_tot'][i] != '' and data['neige_tot'][i] != None: |
171 neige_tot += float(data['neige_tot'][i].replace(',','.')) | 173 neige_tot += float(data['neige_tot'][i].replace(',','.')) |
172 if data['tmax'][i] != '' and data['tmax'][i] != None: | 174 if tmax != None: |
173 if tmax < 0: | 175 if tmax < 0: |
174 nbre_jours_T_negatif += 1 | 176 nbre_jours_T_negatif += 1 |
175 if data['tmax'][i] != '' and data['tmax'][i] != None and data['tmin'][i] != '' and data['tmin'][i] != None: | 177 if tmax != None and data['tmin'][i] != '' and data['tmin'][i] != None: |
176 if tmax > 0 and tmin < 0: | 178 if tmax > 0 and tmin < 0: |
177 nbre_jours_gel_degel += 1 | 179 nbre_jours_gel_degel += 1 |
178 for l in range(len(seuils_T)): | 180 for l in range(len(seuils_T)): |
179 if tmax - tmin >=seuils_T[l]: | 181 if tmax - tmin >=seuils_T[l]: |
180 deltas_T[l] += 1 | 182 deltas_T[l] += 1 |
181 if data['tmoy'][i] != '' and data['tmoy'][i] != None: | 183 if data['tmoy'][i] != '' and data['tmoy'][i] != None: |
182 tmoys.append(float(data['tmoy'][i].replace(',','.'))) | 184 tmoys.append(float(data['tmoy'][i].replace(',','.'))) |
183 if data['tmax'][i] != '' and data['tmax'][i] != None and tmax < 0: | 185 if tmax != None: |
184 compteur += 1 | 186 if tmax < 0: |
185 elif (tmax >= 0 or data['tmax'][i] == '' or data['tmax'][i] == None) and compteur >= nbre_jours_gel_consecutifs: | 187 compteur += 1 |
186 nbre_jours_gel_consecutifs = compteur | 188 elif tmax >= 0 and compteur >= nbre_jours_gel_consecutifs: |
187 compteur = 0 | 189 nbre_jours_gel_consecutifs = compteur |
188 else: | 190 compteur = 0 |
189 compteur = 0 | 191 else: |
192 compteur = 0 | |
190 nbre_jours_gel_consecutifs = max(nbre_jours_gel_consecutifs,compteur) | 193 nbre_jours_gel_consecutifs = max(nbre_jours_gel_consecutifs,compteur) |
191 ecart_type_T = np.std(tmoys) | 194 ecart_type_T = np.std(tmoys) |
192 | 195 if neige_tot < snowThreshold: |
193 return (nbre_jours_T_negatif,nbre_jours_gel_degel, deltas_T, nbre_jours_gel_consecutifs, pluie_tot, neige_tot, ecart_type_T) | 196 neigeEC_sup_seuil = 0 |
197 else: | |
198 neigeEC_sup_seuil = 1 | |
199 | |
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) |