Mercurial Hosting > traffic-intelligence
changeset 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 | c59a47ce0209 |
children | 62d05436099d |
files | python/pavement.py |
diffstat | 1 files changed, 68 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/python/pavement.py Thu Feb 13 14:10:52 2014 -0500 +++ b/python/pavement.py Thu Feb 13 15:11:31 2014 -0500 @@ -140,39 +140,43 @@ deltas_T = [0,0,0,0] startIndex = find(data['date'] == startDate) nDays = (endDate - startDate).days+1 - for i in range(startIndex, startIndex+int(nDays)): - if data['tmax'][i] != '' and data['tmax'][i] != None: - tmax = float(data['tmax'][i].replace(',','.')) + if startIndex.size != 0: + for i in range(startIndex, startIndex+int(nDays)): + if data['tmax'][i] != '' and data['tmax'][i] != None: + tmax = float(data['tmax'][i].replace(',','.')) + else: + tmax = None + if data['tmin'][i] != '' and data['tmin'][i] != None: + tmin = float(data['tmin'][i].replace(',','.')) + if data['pluie_tot'][i] != '' and data['pluie_tot'][i] != None: + pluie_tot += float(data['pluie_tot'][i].replace(',','.')) + if data['neige_tot'][i] != '' and data['neige_tot'][i] != None: + neige_tot += float(data['neige_tot'][i].replace(',','.')) + if tmax != None: + if tmax < 0: + nbre_jours_T_negatif += 1 + if tmax != None and data['tmin'][i] != '' and data['tmin'][i] != None: + if tmax > 0 and tmin < 0: + nbre_jours_gel_degel += 1 + for l in range(len(seuils_T)): + if tmax - tmin >=seuils_T[l]: + deltas_T[l] += 1 + if data['tmoy'][i] != '' and data['tmoy'][i] != None: + tmoys.append(float(data['tmoy'][i].replace(',','.'))) + if tmax != None: + if tmax < 0: + compteur += 1 + elif tmax >= 0 and compteur >= nbre_jours_gel_consecutifs: + nbre_jours_gel_consecutifs = compteur + compteur = 0 + else: + compteur = 0 + nbre_jours_gel_consecutifs = max(nbre_jours_gel_consecutifs,compteur) + if float(len(tmoys))/nDays >= minProportionMeasures: + if tmoys != []: + ecart_type_T = np.std(tmoys) else: - tmax = None - if data['tmin'][i] != '' and data['tmin'][i] != None: - tmin = float(data['tmin'][i].replace(',','.')) - if data['pluie_tot'][i] != '' and data['pluie_tot'][i] != None: - pluie_tot += float(data['pluie_tot'][i].replace(',','.')) - if data['neige_tot'][i] != '' and data['neige_tot'][i] != None: - neige_tot += float(data['neige_tot'][i].replace(',','.')) - if tmax != None: - if tmax < 0: - nbre_jours_T_negatif += 1 - if tmax != None and data['tmin'][i] != '' and data['tmin'][i] != None: - if tmax > 0 and tmin < 0: - nbre_jours_gel_degel += 1 - for l in range(len(seuils_T)): - if tmax - tmin >=seuils_T[l]: - deltas_T[l] += 1 - if data['tmoy'][i] != '' and data['tmoy'][i] != None: - tmoys.append(float(data['tmoy'][i].replace(',','.'))) - if tmax != None: - if tmax < 0: - compteur += 1 - elif tmax >= 0 and compteur >= nbre_jours_gel_consecutifs: - nbre_jours_gel_consecutifs = compteur - compteur = 0 - else: - compteur = 0 - nbre_jours_gel_consecutifs = max(nbre_jours_gel_consecutifs,compteur) - if tmoys != [] and float(len(tmoys))/nDays >= minProportionMeasures: - ecart_type_T = np.std(tmoys) + ecart_type = None if neige_tot < snowThreshold: neigeEC_sup_seuil = 0 else: @@ -181,6 +185,38 @@ else: return [None]*2+[[None]*len(seuils_T)]+[None]*5 +def mtqWeatherIndicators(data, startDate, endDate,tmax,tmin,tmoy): + 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 + tmoys = [] + seuils_T = [20,15,10,5] + deltas_T = [0,0,0,0] + startIndex = find(data['date'] == startDate) + nDays = (endDate - startDate).days+1 + for i in range(startIndex, startIndex+nDays): + if tmax[i] < 0: + nbre_jours_T_negatif += 1 + if tmax[i] > 0 and tmin[i] < 0: + nbre_jours_gel_degel += 1 + for l in range(len(seuils_T)): + if tmax[i] - tmin[i] >=seuils_T[l]: + deltas_T[l] += 1 + tmoys.append(tmoy[i]) + if tmax[i] < 0: + compteur += 1 + elif tmax[i] >= 0 and compteur >= nbre_jours_gel_consecutifs: + nbre_jours_gel_consecutifs = compteur + compteur = 0 + else: + compteur = 0 + nbre_jours_gel_consecutifs = max(nbre_jours_gel_consecutifs,compteur) + if tmoys != []: + ecart_type_T = np.std(tmoys) + else: + ecart_type = None + + return (nbre_jours_T_negatif,nbre_jours_gel_degel, deltas_T, nbre_jours_gel_consecutifs, ecart_type_T) class RTSS: '''class for data related to a RTSS: