comparison python/pavement.py @ 437:830136bc0e18

integrating Alexandre functions
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 21 Jan 2014 16:31:30 -0500
parents 9a714f32fc9f
children ca114520605f
comparison
equal deleted inserted replaced
436:b64ff7fe7b45 437:830136bc0e18
1 #! /usr/bin/env python 1 #! /usr/bin/env python
2 '''Tools for processing and analyzing pavement marking data''' 2 '''Tools for processing and analyzing pavement marking data'''
3
4 import numpy as np
3 5
4 __metaclass__ = type 6 __metaclass__ = type
5 7
6 class RTSS: 8 class RTSS:
7 'class for data related to a RTSS, including agregating pavement marking measurements' 9 'class for data related to a RTSS, including agregating pavement marking measurements'
8 pass 10
11 def __init__(self, id):
12 self.id = id
9 13
10 class MarkingTest: 14 class MarkingTest:
11 '''class for a test site for a given product''' 15 '''class for a test site for a given product'''
12 16
13 def __init__(self, siteId, paintingDate, paintingType, color, data): 17 def __init__(self, siteId, paintingDate, paintingType, color, data):
29 return self.data[nonZeroIndices]['jours'], self.data[nonZeroIndices][dataLabel] 33 return self.data[nonZeroIndices]['jours'], self.data[nonZeroIndices][dataLabel]
30 34
31 def plotMarkingMeasures(self, measure, options = 'o', dayRatio = 1., **kwargs): 35 def plotMarkingMeasures(self, measure, options = 'o', dayRatio = 1., **kwargs):
32 for i in range(1,7): 36 for i in range(1,7):
33 self.plot('{}_{}'.format(measure, i), options, dayRatio, **kwargs) 37 self.plot('{}_{}'.format(measure, i), options, dayRatio, **kwargs)
38
39
40 def occ_max(a):
41 if a != []:
42 s = set(a)
43 l = list(s)
44 occ = []
45 for i in range(len(l)):
46 b = 0
47 for j in range(len(a)):
48 if a[j] == l[i]:
49 b += 1
50 occ.append([l[i], b])
51 nbre_occs = []
52 for i in range(len(occ)):
53 nbre_occs.append(occ[i][1])
54 return occ[nbre_occs.index(max(nbre_occs))][0]
55 else:
56 return ""
57
58 def caracteristiques(rtss, maintenanceLevel, rtssWeatherStation, fmr, paintType):
59 '''Computes characteristic data for the RTSS (class rtss)
60 maintenanceLevel = pylab.csv2rec('C:\Users\Alexandre\Desktop\Projet_maitrise_recherche\BDD_access\\analyse_donnees_deneigement\\exigence_circuits.txt', delimiter = ';')
61 rtssWeatherStation = pylab.csv2rec('C:\Users\Alexandre\Desktop\Projet_maitrise_recherche\stations_environnement_canada\\rtssWeatherStation\juste_pour_rtss_avec_donnees_entretien_hiv\\rtssWeatherStation_EC3.txt', delimiter = ',')
62 fmr = pylab.csv2rec('C:\Users\Alexandre\Desktop\Projet_maitrise_recherche\BDD_access\\analyse_donnees_deneigement\\fmr.txt', delimiter = ';')
63 paintType = pylab.csv2rec('C:\Users\Alexandre\Desktop\Projet_maitrise_recherche\BDD_access\\analyse_donnees_deneigement\\type_peinture.txt', delimiter = ';')
64 '''
65 # determination exigence deneigement
66 if rtss.id in maintenanceLevel['rtss_debut']:
67 for i in range(len(maintenanceLevel)-1):
68 if maintenanceLevel['rtss_debut'][i] == rtss.id:
69 exigence = maintenanceLevel['exigence'][i]
70 else:
71 exigence = ''
72
73 # determination x/y
74 if rtss.id in rtssWeatherStation['rtss']:
75 for i in range(len(rtssWeatherStation)-1):
76 if rtssWeatherStation['rtss'][i] == rtss.id:
77 x_moy = rtssWeatherStation['x_moy'][i]
78 y_moy = rtssWeatherStation['y_moy'][i]
79 else:
80 x_moy, y_moy = '',''
81
82 # determination info fmr
83 age_revtm, classe_fonct, type_revtm, milieu, djma, pourc_camions = [], [], [], [], [], []
84 if rtss.id in fmr['rtss_debut']:
85 for i in range(len(fmr)-1):
86 if fmr['rtss_debut'][i] == rtss.id:
87 age_revtm.append(fmr['age_revtm'][i])
88 classe_fonct.append(fmr['des_clasf_fonct'][i])
89 type_revtm.append(fmr['des_type_revtm'][i])
90 milieu.append(fmr['des_cod_mil'][i])
91 djma.append(fmr['val_djma'][i])
92 pourc_camions.append(fmr['val_pourc_camns'][i])
93 age_revtm = occ_max(age_revtm)
94 classe_fonct = occ_max(classe_fonct)
95 type_revtm = occ_max(type_revtm)
96 milieu = occ_max(milieu)
97 djma = occ_max(djma)
98 pourc_camions = occ_max(pourc_camions)
99 if pourc_camions == "" or pourc_camions < 0:
100 djma_camions = ""
101 else:
102 djma_camions = pourc_camions*djma/100
103 else:
104 age_revtm, classe_fonct, type_revtm, milieu, djma, djma_camions = '','','','','',''
105
106 # determination type peinture
107 peinture_rd, peinture_rg, peinture_cl = [], [], []
108 peinture_lrd, peinture_lrg, peinture_lc = 0,0,0
109 if rtss.id in paintType['rtss_debut_orig']:
110 for i in range(len(paintType)-1):
111 if paintType['rtss_debut_orig'][i] == rtss.id:
112 peinture_rd.append((paintType['peinture_rd'][i]))
113 peinture_rg.append((paintType['peinture_rg'][i]))
114 peinture_cl.append((paintType['peinture_cl'][i]))
115 peinture_lrd = occ_max(peinture_rd)
116 peinture_lrg = occ_max(peinture_rg)
117 peinture_lc = occ_max(peinture_cl)
118 else:
119 peinture_lrd, peinture_lrg, peinture_lc = '','',''
120
121 return [exigence, x_moy, y_moy, age_revtm, classe_fonct, type_revtm, milieu, djma, djma_camions, peinture_lrd, peinture_lrg, peinture_lc]
122
123 def winterMaintenanceIndicators(data, startDate, endDate, circuitReference, snowThreshold):
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 = ',')'''
126 somme_eau, somme_neige, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, compteur_somme_abrasif = 0,0,0,0,0,0,0,0,0
127
128 if circuitReference in data['ref_circuit']:
129 for i in range(len(data)-1):
130 if data['ref_circuit'][i] == circuitReference and (data['date'][i] + datetime.timedelta(days = 6)) <= endDate and (data['date'][i] + datetime.timedelta(days = 6)) > startDate:
131 premiere_neige += data['premiere_neige'][i]
132 somme_neige += float(data['neige'][i])
133 somme_eau += float(data['eau'][i])
134 somme_abrasif += float(data['abrasif'][i])
135 somme_sel += float(data['sel'][i])
136 somme_lc += float(data['lc'][i])
137 somme_lrg += float(data['lrg'][i])
138 somme_lrd += float(data['lrd'][i])
139 compteur_somme_abrasif += float(data['autre_abrasif_binaire'][i])
140 if compteur_somme_abrasif >= 1:
141 autres_abrasifs = 1
142 else:
143 autres_abrasifs = 0
144 if somme_neige < snowThreshold:
145 neigeMTQ_sup_seuil = 0
146 else:
147 neigeMTQ_sup_seuil = 1
148 else:
149 somme_eau, somme_neige, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs, neigeMTQ_sup_seuil = '','','','','','','','','',''
150
151 return [somme_eau, somme_neige, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs, neigeMTQ_sup_seuil]
152
153 def environmentCanadaIndicators(data, startDate, endDate):
154 '''Computes the indicators from Environment Canada files
155 (loaded as a recarray using csv2rec in data),
156 between start and end dates (datetime.datetime objects)'''
157 nbre_jours_T_negatif,nbre_jours_gel_degel,pluie_tot,neige_tot,ecart_type_T = 0,0,0,0,0
158 compteur,nbre_jours_gel_consecutifs=0,0
159 tmoys = []
160 seuils_T = [20,15,10,5]
161 deltas_T = [0,0,0,0]
162 for i in range(int((endDate - startDate).days)+1):
163 if data['tmax'][i] != '' and data['tmax'][i] != None:
164 tmax = float(data['tmax'][i].replace(',','.'))
165 if data['tmin'][i] != '' and data['tmin'][i] != None:
166 tmin = float(data['tmin'][i].replace(',','.'))
167 if data['pluie_tot'][i] != '' and data['pluie_tot'][i] != None:
168 pluie_tot += float(data['pluie_tot'][i].replace(',','.'))
169 if data['neige_tot'][i] != '' and data['neige_tot'][i] != None:
170 neige_tot += float(data['neige_tot'][i].replace(',','.'))
171 if data['tmax'][i] != '' and data['tmax'][i] != None:
172 if tmax < 0:
173 nbre_jours_T_negatif += 1
174 if data['tmax'][i] != '' and data['tmax'][i] != None and data['tmin'][i] != '' and data['tmin'][i] != None:
175 if tmax > 0 and tmin < 0:
176 nbre_jours_gel_degel += 1
177 for l in range(len(seuils_T)):
178 if tmax - tmin >=seuils_T[l]:
179 deltas_T[l] += 1
180 if data['tmoy'][i] != '' and data['tmoy'][i] != None:
181 tmoys.append(float(data['tmoy'][i].replace(',','.')))
182 if data['tmax'][i] != '' and data['tmax'][i] != None and tmax < 0:
183 compteur += 1
184 elif (tmax >= 0 or data['tmax'][i] == '' or data['tmax'][i] == None) and compteur >= nbre_jours_gel_consecutifs:
185 nbre_jours_gel_consecutifs = compteur
186 compteur = 0
187 else:
188 compteur = 0
189 nbre_jours_gel_consecutifs = max(nbre_jours_gel_consecutifs,compteur)
190 ecart_type_T = np.std(tmoys)
191
192 return [nbre_jours_T_negatif,nbre_jours_gel_degel, deltas_T[0], deltas_T[1], deltas_T[2], deltas_T[3], nbre_jours_gel_consecutifs, pluie_tot, neige_tot, ecart_type_T]