Mercurial > hg > nsaunier > traffic-intelligence
comparison python/pavement.py @ 453:15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Thu, 13 Feb 2014 15:11:31 -0500 |
| parents | c0786fe4ad94 |
| children | 825e5d49325d |
comparison
equal
deleted
inserted
replaced
| 452:c59a47ce0209 | 453:15c6f1bc30a2 |
|---|---|
| 138 tmoys = [] | 138 tmoys = [] |
| 139 seuils_T = [20,15,10,5] | 139 seuils_T = [20,15,10,5] |
| 140 deltas_T = [0,0,0,0] | 140 deltas_T = [0,0,0,0] |
| 141 startIndex = find(data['date'] == startDate) | 141 startIndex = find(data['date'] == startDate) |
| 142 nDays = (endDate - startDate).days+1 | 142 nDays = (endDate - startDate).days+1 |
| 143 for i in range(startIndex, startIndex+int(nDays)): | 143 if startIndex.size != 0: |
| 144 if data['tmax'][i] != '' and data['tmax'][i] != None: | 144 for i in range(startIndex, startIndex+int(nDays)): |
| 145 tmax = float(data['tmax'][i].replace(',','.')) | 145 if data['tmax'][i] != '' and data['tmax'][i] != None: |
| 146 else: | 146 tmax = float(data['tmax'][i].replace(',','.')) |
| 147 tmax = None | |
| 148 if data['tmin'][i] != '' and data['tmin'][i] != None: | |
| 149 tmin = float(data['tmin'][i].replace(',','.')) | |
| 150 if data['pluie_tot'][i] != '' and data['pluie_tot'][i] != None: | |
| 151 pluie_tot += float(data['pluie_tot'][i].replace(',','.')) | |
| 152 if data['neige_tot'][i] != '' and data['neige_tot'][i] != None: | |
| 153 neige_tot += float(data['neige_tot'][i].replace(',','.')) | |
| 154 if tmax != None: | |
| 155 if tmax < 0: | |
| 156 nbre_jours_T_negatif += 1 | |
| 157 if tmax != None and data['tmin'][i] != '' and data['tmin'][i] != None: | |
| 158 if tmax > 0 and tmin < 0: | |
| 159 nbre_jours_gel_degel += 1 | |
| 160 for l in range(len(seuils_T)): | |
| 161 if tmax - tmin >=seuils_T[l]: | |
| 162 deltas_T[l] += 1 | |
| 163 if data['tmoy'][i] != '' and data['tmoy'][i] != None: | |
| 164 tmoys.append(float(data['tmoy'][i].replace(',','.'))) | |
| 165 if tmax != None: | |
| 166 if tmax < 0: | |
| 167 compteur += 1 | |
| 168 elif tmax >= 0 and compteur >= nbre_jours_gel_consecutifs: | |
| 169 nbre_jours_gel_consecutifs = compteur | |
| 170 compteur = 0 | |
| 171 else: | 147 else: |
| 172 compteur = 0 | 148 tmax = None |
| 173 nbre_jours_gel_consecutifs = max(nbre_jours_gel_consecutifs,compteur) | 149 if data['tmin'][i] != '' and data['tmin'][i] != None: |
| 174 if tmoys != [] and float(len(tmoys))/nDays >= minProportionMeasures: | 150 tmin = float(data['tmin'][i].replace(',','.')) |
| 175 ecart_type_T = np.std(tmoys) | 151 if data['pluie_tot'][i] != '' and data['pluie_tot'][i] != None: |
| 152 pluie_tot += float(data['pluie_tot'][i].replace(',','.')) | |
| 153 if data['neige_tot'][i] != '' and data['neige_tot'][i] != None: | |
| 154 neige_tot += float(data['neige_tot'][i].replace(',','.')) | |
| 155 if tmax != None: | |
| 156 if tmax < 0: | |
| 157 nbre_jours_T_negatif += 1 | |
| 158 if tmax != None and data['tmin'][i] != '' and data['tmin'][i] != None: | |
| 159 if tmax > 0 and tmin < 0: | |
| 160 nbre_jours_gel_degel += 1 | |
| 161 for l in range(len(seuils_T)): | |
| 162 if tmax - tmin >=seuils_T[l]: | |
| 163 deltas_T[l] += 1 | |
| 164 if data['tmoy'][i] != '' and data['tmoy'][i] != None: | |
| 165 tmoys.append(float(data['tmoy'][i].replace(',','.'))) | |
| 166 if tmax != None: | |
| 167 if tmax < 0: | |
| 168 compteur += 1 | |
| 169 elif tmax >= 0 and compteur >= nbre_jours_gel_consecutifs: | |
| 170 nbre_jours_gel_consecutifs = compteur | |
| 171 compteur = 0 | |
| 172 else: | |
| 173 compteur = 0 | |
| 174 nbre_jours_gel_consecutifs = max(nbre_jours_gel_consecutifs,compteur) | |
| 175 if float(len(tmoys))/nDays >= minProportionMeasures: | |
| 176 if tmoys != []: | |
| 177 ecart_type_T = np.std(tmoys) | |
| 178 else: | |
| 179 ecart_type = None | |
| 176 if neige_tot < snowThreshold: | 180 if neige_tot < snowThreshold: |
| 177 neigeEC_sup_seuil = 0 | 181 neigeEC_sup_seuil = 0 |
| 178 else: | 182 else: |
| 179 neigeEC_sup_seuil = 1 | 183 neigeEC_sup_seuil = 1 |
| 180 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) | 184 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) |
| 181 else: | 185 else: |
| 182 return [None]*2+[[None]*len(seuils_T)]+[None]*5 | 186 return [None]*2+[[None]*len(seuils_T)]+[None]*5 |
| 183 | 187 |
| 188 def mtqWeatherIndicators(data, startDate, endDate,tmax,tmin,tmoy): | |
| 189 from matplotlib.mlab import find | |
| 190 nbre_jours_T_negatif,nbre_jours_gel_degel,ecart_type_T = 0,0,0 | |
| 191 compteur,nbre_jours_gel_consecutifs=0,0 | |
| 192 tmoys = [] | |
| 193 seuils_T = [20,15,10,5] | |
| 194 deltas_T = [0,0,0,0] | |
| 195 startIndex = find(data['date'] == startDate) | |
| 196 nDays = (endDate - startDate).days+1 | |
| 197 for i in range(startIndex, startIndex+nDays): | |
| 198 if tmax[i] < 0: | |
| 199 nbre_jours_T_negatif += 1 | |
| 200 if tmax[i] > 0 and tmin[i] < 0: | |
| 201 nbre_jours_gel_degel += 1 | |
| 202 for l in range(len(seuils_T)): | |
| 203 if tmax[i] - tmin[i] >=seuils_T[l]: | |
| 204 deltas_T[l] += 1 | |
| 205 tmoys.append(tmoy[i]) | |
| 206 if tmax[i] < 0: | |
| 207 compteur += 1 | |
| 208 elif tmax[i] >= 0 and compteur >= nbre_jours_gel_consecutifs: | |
| 209 nbre_jours_gel_consecutifs = compteur | |
| 210 compteur = 0 | |
| 211 else: | |
| 212 compteur = 0 | |
| 213 nbre_jours_gel_consecutifs = max(nbre_jours_gel_consecutifs,compteur) | |
| 214 if tmoys != []: | |
| 215 ecart_type_T = np.std(tmoys) | |
| 216 else: | |
| 217 ecart_type = None | |
| 218 | |
| 219 return (nbre_jours_T_negatif,nbre_jours_gel_degel, deltas_T, nbre_jours_gel_consecutifs, ecart_type_T) | |
| 184 | 220 |
| 185 class RTSS: | 221 class RTSS: |
| 186 '''class for data related to a RTSS: | 222 '''class for data related to a RTSS: |
| 187 - agregating pavement marking measurements | 223 - agregating pavement marking measurements |
| 188 - RTSS characteristics from FMR: pavement type, age, AADT, truck AADT | 224 - RTSS characteristics from FMR: pavement type, age, AADT, truck AADT |
