Mercurial > hg > nsaunier > traffic-intelligence
comparison python/pavement.py @ 457:95a8eb38d9a2
update to weather function
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Wed, 19 Feb 2014 16:33:49 -0500 |
| parents | 825e5d49325d |
| children | 28ff95845c65 |
comparison
equal
deleted
inserted
replaced
| 456:825e5d49325d | 457:95a8eb38d9a2 |
|---|---|
| 138 else: | 138 else: |
| 139 somme_eau, somme_neige, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs, neigeMTQ_sup_seuil = '','','','','','','','','','' | 139 somme_eau, somme_neige, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs, neigeMTQ_sup_seuil = '','','','','','','','','','' |
| 140 | 140 |
| 141 return (somme_eau, somme_neige, neigeMTQ_sup_seuil, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs) | 141 return (somme_eau, somme_neige, neigeMTQ_sup_seuil, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs) |
| 142 | 142 |
| 143 def ecWeatherIndicators(data, startDate, endDate, snowThreshold, minProportionMeasures = 0.): | 143 def ecWeatherIndicators(data, startDate, endDate, snowThreshold, datatype, minProportionMeasures = 0.): |
| 144 '''Computes the indicators from Environment Canada files | 144 '''Computes the indicators from Environment Canada files |
| 145 (loaded as a recarray using csv2rec in data), | 145 (loaded as a recarray using csv2rec in data), |
| 146 between start and end dates (datetime.datetime objects) | 146 between start and end dates (datetime.datetime objects) |
| 147 | 147 |
| 148 dataType is to indicate Environnement Canada data ('ec') or else MTQ | |
| 148 minProportionMeasures is proportion of measures necessary to consider the indicators''' | 149 minProportionMeasures is proportion of measures necessary to consider the indicators''' |
| 149 from matplotlib.mlab import find | 150 from matplotlib.mlab import find |
| 150 nbre_jours_T_negatif,nbre_jours_gel_degel,pluie_tot,neige_tot,ecart_type_T = 0,0,0,0,0 | 151 nbre_jours_T_negatif,nbre_jours_gel_degel,pluie_tot,neige_tot,ecart_type_T = 0,0,0,0,0 |
| 151 compteur,nbre_jours_gel_consecutifs=0,0 | 152 compteur,nbre_jours_gel_consecutifs=0,0 |
| 152 tmoys = [] | 153 tmoys = [] |
| 154 deltas_T = [0,0,0,0] | 155 deltas_T = [0,0,0,0] |
| 155 startIndex = find(data['date'] == startDate) | 156 startIndex = find(data['date'] == startDate) |
| 156 nDays = (endDate - startDate).days+1 | 157 nDays = (endDate - startDate).days+1 |
| 157 if startIndex.size != 0: | 158 if startIndex.size != 0: |
| 158 for i in range(startIndex, startIndex+int(nDays)): | 159 for i in range(startIndex, startIndex+int(nDays)): |
| 159 if data['tmax'][i] != '' and data['tmax'][i] != None: | 160 if not np.isnan(data['tmax'][i]): |
| 160 tmax = float(data['tmax'][i].replace(',','.')) | 161 tmax = data['tmax'][i] |
| 161 else: | 162 else: |
| 162 tmax = None | 163 tmax = None |
| 163 if data['tmin'][i] != '' and data['tmin'][i] != None: | 164 if not np.isnan(data['tmin'][i]): |
| 164 tmin = float(data['tmin'][i].replace(',','.')) | 165 tmin = data['tmin'][i] |
| 165 if data['pluie_tot'][i] != '' and data['pluie_tot'][i] != None: | 166 else: |
| 166 pluie_tot += float(data['pluie_tot'][i].replace(',','.')) | 167 tmin = None |
| 167 if data['neige_tot'][i] != '' and data['neige_tot'][i] != None: | 168 if datatype == 'ec': |
| 168 neige_tot += float(data['neige_tot'][i].replace(',','.')) | 169 if data['pluie_tot'][i] != None and not np.isnan(data['pluie_tot'][i]): |
| 170 pluie_tot += data['pluie_tot'][i] | |
| 171 if data['neige_tot'][i] != None and not np.isnan(data['neige_tot'][i]): | |
| 172 neige_tot += data['neige_tot'][i] | |
| 169 if tmax != None: | 173 if tmax != None: |
| 170 if tmax < 0: | 174 if tmax < 0: |
| 171 nbre_jours_T_negatif += 1 | 175 nbre_jours_T_negatif += 1 |
| 172 if tmax != None and data['tmin'][i] != '' and data['tmin'][i] != None: | 176 if tmax != None and tmin != None: |
| 173 if tmax > 0 and tmin < 0: | 177 if tmax > 0 and tmin < 0: |
| 174 nbre_jours_gel_degel += 1 | 178 nbre_jours_gel_degel += 1 |
| 175 for l in range(len(seuils_T)): | 179 for l in range(len(seuils_T)): |
| 176 if tmax - tmin >=seuils_T[l]: | 180 if tmax - tmin >=seuils_T[l]: |
| 177 deltas_T[l] += 1 | 181 deltas_T[l] += 1 |
| 178 if data['tmoy'][i] != '' and data['tmoy'][i] != None: | 182 if not np.isnan(data['tmoy'][i]): |
| 179 tmoys.append(float(data['tmoy'][i].replace(',','.'))) | 183 tmoys.append(data['tmoy'][i]) |
| 180 if tmax != None: | 184 if tmax != None: |
| 181 if tmax < 0: | 185 if tmax < 0: |
| 182 compteur += 1 | 186 compteur += 1 |
| 183 elif tmax >= 0 and compteur >= nbre_jours_gel_consecutifs: | 187 elif tmax >= 0 and compteur >= nbre_jours_gel_consecutifs: |
| 184 nbre_jours_gel_consecutifs = compteur | 188 nbre_jours_gel_consecutifs = compteur |
| 185 compteur = 0 | 189 compteur = 0 |
| 186 else: | 190 else: |
| 187 compteur = 0 | 191 compteur = 0 |
| 188 nbre_jours_gel_consecutifs = max(nbre_jours_gel_consecutifs,compteur) | 192 nbre_jours_gel_consecutifs = max(nbre_jours_gel_consecutifs,compteur) |
| 189 if float(len(tmoys))/nDays >= minProportionMeasures: | 193 if len(tmoys) > 0 and float(len(tmoys))/nDays >= minProportionMeasures: |
| 190 if tmoys != []: | 194 if tmoys != []: |
| 191 ecart_type_T = np.std(tmoys) | 195 ecart_type_T = np.std(tmoys) |
| 192 else: | 196 else: |
| 193 ecart_type = None | 197 ecart_type = None |
| 194 if neige_tot < snowThreshold: | 198 if neige_tot < snowThreshold: |
