Mercurial Hosting > traffic-intelligence
changeset 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 | ea907ae19d8c eb8baa080470 |
files | python/pavement.py |
diffstat | 1 files changed, 20 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/python/pavement.py Tue Jan 21 17:30:48 2014 -0500 +++ b/python/pavement.py Wed Jan 22 23:41:32 2014 -0500 @@ -118,7 +118,7 @@ else: peinture_lrd, peinture_lrg, peinture_lc = '','','' - return [exigence, x_moy, y_moy, age_revtm, classe_fonct, type_revtm, milieu, djma, djma_camions, peinture_lrd, peinture_lrg, peinture_lc] + return (exigence, x_moy, y_moy, age_revtm, classe_fonct, type_revtm, milieu, djma, djma_camions, peinture_lrd, peinture_lrg, peinture_lc) def winterMaintenanceIndicators(data, startDate, endDate, circuitReference, snowThreshold): '''Computes several winter maintenance indicators @@ -149,9 +149,9 @@ else: somme_eau, somme_neige, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs, neigeMTQ_sup_seuil = '','','','','','','','','','' - return [somme_eau, somme_neige, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs, neigeMTQ_sup_seuil] + 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): +def ecWeatherIndicators(data, startDate, endDate, snowThreshold): '''Computes the indicators from Environment Canada files (loaded as a recarray using csv2rec in data), between start and end dates (datetime.datetime objects)''' @@ -163,16 +163,18 @@ for i in range(int((endDate - startDate).days)+1): 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 data['tmax'][i] != '' and data['tmax'][i] != None: + if tmax != None: if tmax < 0: nbre_jours_T_negatif += 1 - if data['tmax'][i] != '' and data['tmax'][i] != None and data['tmin'][i] != '' and data['tmin'][i] != None: + 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)): @@ -180,14 +182,19 @@ deltas_T[l] += 1 if data['tmoy'][i] != '' and data['tmoy'][i] != None: tmoys.append(float(data['tmoy'][i].replace(',','.'))) - if data['tmax'][i] != '' and data['tmax'][i] != None and tmax < 0: - compteur += 1 - elif (tmax >= 0 or data['tmax'][i] == '' or data['tmax'][i] == None) and compteur >= nbre_jours_gel_consecutifs: - nbre_jours_gel_consecutifs = compteur - compteur = 0 - else: - compteur = 0 + 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) ecart_type_T = np.std(tmoys) + if neige_tot < snowThreshold: + neigeEC_sup_seuil = 0 + else: + neigeEC_sup_seuil = 1 - return (nbre_jours_T_negatif,nbre_jours_gel_degel, deltas_T, nbre_jours_gel_consecutifs, pluie_tot, neige_tot, ecart_type_T) + 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)