Mercurial Hosting > traffic-intelligence
annotate python/pavement.py @ 460:55b424d98b68
change of interface, distributions are now passed to the prediction paramters constructors if needed
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Sat, 22 Feb 2014 01:18:16 -0500 |
parents | 28ff95845c65 |
children | 16fe64136506 |
rev | line source |
---|---|
431
0bcfa49d179a
began module for pavement marking data processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
0bcfa49d179a
began module for pavement marking data processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
2 '''Tools for processing and analyzing pavement marking data''' |
0bcfa49d179a
began module for pavement marking data processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
3 |
458
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
4 import utils |
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
5 |
437
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
6 import numpy as np |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
7 |
431
0bcfa49d179a
began module for pavement marking data processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
8 __metaclass__ = type |
0bcfa49d179a
began module for pavement marking data processing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
9 |
450
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
10 durabilities = {1: 98, #96 to 100 |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
11 2: 85, #75 to 96 |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
12 3: 72, #50 to 75 |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
13 4: 32, #15 to 50 |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
14 5: 7 #0 to 15 |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
15 } |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
16 |
456 | 17 roadFunctionalClasses = {40: "Collectrice", |
18 20: "Nationale", | |
19 30: "Regionale", | |
20 10: "Autoroute", | |
21 60: "Acces ressources", | |
22 51: "Local 1", | |
23 52: "Local 2", | |
458
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
24 53: "Local 3", |
456 | 25 15: "Aut (PRN)", |
26 25: "Nat (PRN)", | |
27 70: "Acces isolees", | |
28 99: "Autres" | |
29 } | |
30 | |
437
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
31 def caracteristiques(rtss, maintenanceLevel, rtssWeatherStation, fmr, paintType): |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
32 '''Computes characteristic data for the RTSS (class rtss) |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
33 maintenanceLevel = pylab.csv2rec('C:\Users\Alexandre\Desktop\Projet_maitrise_recherche\BDD_access\\analyse_donnees_deneigement\\exigence_circuits.txt', delimiter = ';') |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
34 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 = ',') |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
35 fmr = pylab.csv2rec('C:\Users\Alexandre\Desktop\Projet_maitrise_recherche\BDD_access\\analyse_donnees_deneigement\\fmr.txt', delimiter = ';') |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
36 paintType = pylab.csv2rec('C:\Users\Alexandre\Desktop\Projet_maitrise_recherche\BDD_access\\analyse_donnees_deneigement\\type_peinture.txt', delimiter = ';') |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
37 ''' |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
38 # determination exigence deneigement |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
39 if rtss.id in maintenanceLevel['rtss_debut']: |
439
ad61d21d3d1b
corrected bug with last array position lookup
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
438
diff
changeset
|
40 for i in range(len(maintenanceLevel)): |
437
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
41 if maintenanceLevel['rtss_debut'][i] == rtss.id: |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
42 exigence = maintenanceLevel['exigence'][i] |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
43 else: |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
44 exigence = '' |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
45 |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
46 # determination x/y |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
47 if rtss.id in rtssWeatherStation['rtss']: |
439
ad61d21d3d1b
corrected bug with last array position lookup
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
438
diff
changeset
|
48 for i in range(len(rtssWeatherStation)): |
437
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
49 if rtssWeatherStation['rtss'][i] == rtss.id: |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
50 x_moy = rtssWeatherStation['x_moy'][i] |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
51 y_moy = rtssWeatherStation['y_moy'][i] |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
52 else: |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
53 x_moy, y_moy = '','' |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
54 |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
55 # determination info fmr |
458
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
56 age_revtm, classe_fonct, type_revtm, milieu, djma, pourc_camions, vit_max = [], [], [], [], [], [], [] |
437
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
57 if rtss.id in fmr['rtss_debut']: |
439
ad61d21d3d1b
corrected bug with last array position lookup
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
438
diff
changeset
|
58 for i in range(len(fmr)): |
437
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
59 if fmr['rtss_debut'][i] == rtss.id: |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
60 age_revtm.append(fmr['age_revtm'][i]) |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
61 classe_fonct.append(fmr['des_clasf_fonct'][i]) |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
62 type_revtm.append(fmr['des_type_revtm'][i]) |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
63 milieu.append(fmr['des_cod_mil'][i]) |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
64 djma.append(fmr['val_djma'][i]) |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
65 pourc_camions.append(fmr['val_pourc_camns'][i]) |
458
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
66 vit_max.append(fmr['val_limt_vitss'][i]) |
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
67 age_revtm = utils.mostCommon(age_revtm) |
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
68 classe_fonct = utils.mostCommon(classe_fonct) |
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
69 type_revtm = utils.mostCommon(type_revtm) |
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
70 milieu = utils.mostCommon(milieu) |
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
71 djma = utils.mostCommon(djma) |
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
72 vit_max = utils.mostCommon(vit_max) |
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
73 if vit_max < 0: |
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
74 vit_max = '' |
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
75 pourc_camions = utils.mostCommon(pourc_camions) |
437
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
76 if pourc_camions == "" or pourc_camions < 0: |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
77 djma_camions = "" |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
78 else: |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
79 djma_camions = pourc_camions*djma/100 |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
80 else: |
458
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
81 age_revtm, classe_fonct, type_revtm, milieu, djma, djma_camions, vit_max = '','','','','','','' |
437
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
82 |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
83 # determination type peinture |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
84 peinture_rd, peinture_rg, peinture_cl = [], [], [] |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
85 peinture_lrd, peinture_lrg, peinture_lc = 0,0,0 |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
86 if rtss.id in paintType['rtss_debut_orig']: |
439
ad61d21d3d1b
corrected bug with last array position lookup
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
438
diff
changeset
|
87 for i in range(len(paintType)): |
437
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
88 if paintType['rtss_debut_orig'][i] == rtss.id: |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
89 peinture_rd.append((paintType['peinture_rd'][i])) |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
90 peinture_rg.append((paintType['peinture_rg'][i])) |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
91 peinture_cl.append((paintType['peinture_cl'][i])) |
458
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
92 peinture_lrd = utils.mostCommon(peinture_rd) |
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
93 peinture_lrg = utils.mostCommon(peinture_rg) |
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
94 peinture_lc = utils.mostCommon(peinture_cl) |
437
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
95 else: |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
96 peinture_lrd, peinture_lrg, peinture_lc = '','','' |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
97 |
458
28ff95845c65
update to include speed limit
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
457
diff
changeset
|
98 return (exigence, x_moy, y_moy, age_revtm, classe_fonct, type_revtm, milieu, djma, djma_camions, vit_max, peinture_lrd, peinture_lrg, peinture_lc) |
437
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
99 |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
100 def winterMaintenanceIndicators(data, startDate, endDate, circuitReference, snowThreshold): |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
101 '''Computes several winter maintenance indicators |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
102 data = entretien_hivernal = pylab.csv2rec('C:\Users\Alexandre\Documents\Cours\Poly\Projet\mesures_entretien_hivernal\mesures_deneigement.txt', delimiter = ',')''' |
438
ca114520605f
minor bug update
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
437
diff
changeset
|
103 import datetime |
437
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
104 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 |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
105 |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
106 if circuitReference in data['ref_circuit']: |
439
ad61d21d3d1b
corrected bug with last array position lookup
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
438
diff
changeset
|
107 for i in range(len(data)): |
437
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
108 if data['ref_circuit'][i] == circuitReference and (data['date'][i] + datetime.timedelta(days = 6)) <= endDate and (data['date'][i] + datetime.timedelta(days = 6)) > startDate: |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
109 premiere_neige += data['premiere_neige'][i] |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
110 somme_neige += float(data['neige'][i]) |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
111 somme_eau += float(data['eau'][i]) |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
112 somme_abrasif += float(data['abrasif'][i]) |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
113 somme_sel += float(data['sel'][i]) |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
114 somme_lc += float(data['lc'][i]) |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
115 somme_lrg += float(data['lrg'][i]) |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
116 somme_lrd += float(data['lrd'][i]) |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
117 compteur_somme_abrasif += float(data['autre_abrasif_binaire'][i]) |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
118 if compteur_somme_abrasif >= 1: |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
119 autres_abrasifs = 1 |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
120 else: |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
121 autres_abrasifs = 0 |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
122 if somme_neige < snowThreshold: |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
123 neigeMTQ_sup_seuil = 0 |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
124 else: |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
125 neigeMTQ_sup_seuil = 1 |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
126 else: |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
127 somme_eau, somme_neige, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs, neigeMTQ_sup_seuil = '','','','','','','','','','' |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
128 |
440
b5cc6b001ae6
correction for tmax and returns as tuples
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
439
diff
changeset
|
129 return (somme_eau, somme_neige, neigeMTQ_sup_seuil, somme_abrasif, somme_sel, somme_lc, somme_lrg, somme_lrd, premiere_neige, autres_abrasifs) |
437
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
130 |
457
95a8eb38d9a2
update to weather function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
456
diff
changeset
|
131 def ecWeatherIndicators(data, startDate, endDate, snowThreshold, datatype, minProportionMeasures = 0.): |
437
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
132 '''Computes the indicators from Environment Canada files |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
133 (loaded as a recarray using csv2rec in data), |
447
7ef40014236c
updated weather indicator calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
446
diff
changeset
|
134 between start and end dates (datetime.datetime objects) |
7ef40014236c
updated weather indicator calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
446
diff
changeset
|
135 |
457
95a8eb38d9a2
update to weather function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
456
diff
changeset
|
136 dataType is to indicate Environnement Canada data ('ec') or else MTQ |
447
7ef40014236c
updated weather indicator calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
446
diff
changeset
|
137 minProportionMeasures is proportion of measures necessary to consider the indicators''' |
7ef40014236c
updated weather indicator calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
446
diff
changeset
|
138 from matplotlib.mlab import find |
437
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
139 nbre_jours_T_negatif,nbre_jours_gel_degel,pluie_tot,neige_tot,ecart_type_T = 0,0,0,0,0 |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
140 compteur,nbre_jours_gel_consecutifs=0,0 |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
141 tmoys = [] |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
142 seuils_T = [20,15,10,5] |
830136bc0e18
integrating Alexandre functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
434
diff
changeset
|
143 deltas_T = [0,0,0,0] |
447
7ef40014236c
updated weather indicator calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
446
diff
changeset
|
144 startIndex = find(data['date'] == startDate) |
7ef40014236c
updated weather indicator calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
446
diff
changeset
|
145 nDays = (endDate - startDate).days+1 |
453
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
146 if startIndex.size != 0: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
147 for i in range(startIndex, startIndex+int(nDays)): |
457
95a8eb38d9a2
update to weather function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
456
diff
changeset
|
148 if not np.isnan(data['tmax'][i]): |
95a8eb38d9a2
update to weather function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
456
diff
changeset
|
149 tmax = data['tmax'][i] |
453
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
150 else: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
151 tmax = None |
457
95a8eb38d9a2
update to weather function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
456
diff
changeset
|
152 if not np.isnan(data['tmin'][i]): |
95a8eb38d9a2
update to weather function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
456
diff
changeset
|
153 tmin = data['tmin'][i] |
95a8eb38d9a2
update to weather function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
456
diff
changeset
|
154 else: |
95a8eb38d9a2
update to weather function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
456
diff
changeset
|
155 tmin = None |
95a8eb38d9a2
update to weather function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
456
diff
changeset
|
156 if datatype == 'ec': |
95a8eb38d9a2
update to weather function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
456
diff
changeset
|
157 if data['pluie_tot'][i] != None and not np.isnan(data['pluie_tot'][i]): |
95a8eb38d9a2
update to weather function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
456
diff
changeset
|
158 pluie_tot += data['pluie_tot'][i] |
95a8eb38d9a2
update to weather function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
456
diff
changeset
|
159 if data['neige_tot'][i] != None and not np.isnan(data['neige_tot'][i]): |
95a8eb38d9a2
update to weather function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
456
diff
changeset
|
160 neige_tot += data['neige_tot'][i] |
453
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
161 if tmax != None: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
162 if tmax < 0: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
163 nbre_jours_T_negatif += 1 |
457
95a8eb38d9a2
update to weather function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
456
diff
changeset
|
164 if tmax != None and tmin != None: |
453
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
165 if tmax > 0 and tmin < 0: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
166 nbre_jours_gel_degel += 1 |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
167 for l in range(len(seuils_T)): |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
168 if tmax - tmin >=seuils_T[l]: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
169 deltas_T[l] += 1 |
457
95a8eb38d9a2
update to weather function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
456
diff
changeset
|
170 if not np.isnan(data['tmoy'][i]): |
95a8eb38d9a2
update to weather function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
456
diff
changeset
|
171 tmoys.append(data['tmoy'][i]) |
453
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
172 if tmax != None: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
173 if tmax < 0: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
174 compteur += 1 |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
175 elif tmax >= 0 and compteur >= nbre_jours_gel_consecutifs: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
176 nbre_jours_gel_consecutifs = compteur |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
177 compteur = 0 |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
178 else: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
179 compteur = 0 |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
180 nbre_jours_gel_consecutifs = max(nbre_jours_gel_consecutifs,compteur) |
457
95a8eb38d9a2
update to weather function
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
456
diff
changeset
|
181 if len(tmoys) > 0 and float(len(tmoys))/nDays >= minProportionMeasures: |
453
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
182 if tmoys != []: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
183 ecart_type_T = np.std(tmoys) |
440
b5cc6b001ae6
correction for tmax and returns as tuples
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
439
diff
changeset
|
184 else: |
453
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
185 ecart_type = None |
447
7ef40014236c
updated weather indicator calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
446
diff
changeset
|
186 if neige_tot < snowThreshold: |
7ef40014236c
updated weather indicator calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
446
diff
changeset
|
187 neigeEC_sup_seuil = 0 |
7ef40014236c
updated weather indicator calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
446
diff
changeset
|
188 else: |
7ef40014236c
updated weather indicator calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
446
diff
changeset
|
189 neigeEC_sup_seuil = 1 |
7ef40014236c
updated weather indicator calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
446
diff
changeset
|
190 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) |
440
b5cc6b001ae6
correction for tmax and returns as tuples
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
439
diff
changeset
|
191 else: |
447
7ef40014236c
updated weather indicator calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
446
diff
changeset
|
192 return [None]*2+[[None]*len(seuils_T)]+[None]*5 |
446
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
193 |
453
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
194 def mtqWeatherIndicators(data, startDate, endDate,tmax,tmin,tmoy): |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
195 from matplotlib.mlab import find |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
196 nbre_jours_T_negatif,nbre_jours_gel_degel,ecart_type_T = 0,0,0 |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
197 compteur,nbre_jours_gel_consecutifs=0,0 |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
198 tmoys = [] |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
199 seuils_T = [20,15,10,5] |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
200 deltas_T = [0,0,0,0] |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
201 startIndex = find(data['date'] == startDate) |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
202 nDays = (endDate - startDate).days+1 |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
203 for i in range(startIndex, startIndex+nDays): |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
204 if tmax[i] < 0: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
205 nbre_jours_T_negatif += 1 |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
206 if tmax[i] > 0 and tmin[i] < 0: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
207 nbre_jours_gel_degel += 1 |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
208 for l in range(len(seuils_T)): |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
209 if tmax[i] - tmin[i] >=seuils_T[l]: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
210 deltas_T[l] += 1 |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
211 tmoys.append(tmoy[i]) |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
212 if tmax[i] < 0: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
213 compteur += 1 |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
214 elif tmax[i] >= 0 and compteur >= nbre_jours_gel_consecutifs: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
215 nbre_jours_gel_consecutifs = compteur |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
216 compteur = 0 |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
217 else: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
218 compteur = 0 |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
219 nbre_jours_gel_consecutifs = max(nbre_jours_gel_consecutifs,compteur) |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
220 if tmoys != []: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
221 ecart_type_T = np.std(tmoys) |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
222 else: |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
223 ecart_type = None |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
224 |
15c6f1bc30a2
added function for MTQ weather indicators (use generic EC function preferrably)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
450
diff
changeset
|
225 return (nbre_jours_T_negatif,nbre_jours_gel_degel, deltas_T, nbre_jours_gel_consecutifs, ecart_type_T) |
450
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
226 |
446
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
227 class RTSS: |
450
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
228 '''class for data related to a RTSS: |
449
1e4c1b6b0e0b
added comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
448
diff
changeset
|
229 - agregating pavement marking measurements |
1e4c1b6b0e0b
added comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
448
diff
changeset
|
230 - RTSS characteristics from FMR: pavement type, age, AADT, truck AADT |
450
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
231 - winter maintenance level from V155 |
446
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
232 |
450
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
233 If divided highway, the RTSS ends with G or D and are distinct: there is no ambiguity |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
234 - retroreflectivity types: there are CB, RJ and RB |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
235 If undivided, ending with C |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
236 - durability is fine: ETAT_MARQG_RG ETAT_MARQG_CL ETAT_MARQG_RD (+SG/SD, but recent) |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
237 - retroreflectivity: CJ is center line, RB and SB are left/right if DEBUT-FIN>0 or <0 |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
238 ''' |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
239 |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
240 def __init__(self, _id, name, data): |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
241 self.id = _id |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
242 self.name = name |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
243 self.data = data |
446
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
244 |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
245 class MarkingTest: |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
246 '''class for a test site for a given product |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
247 |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
248 including the series of measurements over the years''' |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
249 |
450
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
250 def __init__(self, _id, paintingDate, paintingType, color, data): |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
251 self.id = _id |
446
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
252 self.paintingDate = paintingDate |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
253 self.paintingType = paintingType |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
254 self.color = color |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
255 self.data = data |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
256 self.nMeasures = len(data) |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
257 |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
258 def getSite(self): |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
259 return int(self.id[:2]) |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
260 |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
261 def getTestAttributes(self): |
447
7ef40014236c
updated weather indicator calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
446
diff
changeset
|
262 return [self.paintingType, self.color, self.paintingDate.year] |
446
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
263 |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
264 def plot(self, measure, options = 'o', dayRatio = 1., **kwargs): |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
265 from matplotlib.pyplot import plot |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
266 plot(self.data['jours']/float(dayRatio), |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
267 self.data[measure], options, **kwargs) |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
268 |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
269 def getMarkingMeasures(self, dataLabel): |
447
7ef40014236c
updated weather indicator calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
446
diff
changeset
|
270 nonZeroIndices = ~np.isnan(self.data[dataLabel]) |
446
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
271 return self.data[nonZeroIndices]['jours'], self.data[nonZeroIndices][dataLabel] |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
272 |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
273 def plotMarkingMeasures(self, measure, options = 'o', dayRatio = 1., **kwargs): |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
274 for i in range(1,7): |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
275 self.plot('{}_{}'.format(measure, i), options, dayRatio, **kwargs) |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
276 |
447
7ef40014236c
updated weather indicator calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
446
diff
changeset
|
277 def computeMarkingMeasureVariations(self, dataLabel, lanePositions, weatherData, snowThreshold, minProportionMeasures = 0.): |
446
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
278 '''Computes for each successive measurement |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
279 lanePositions = None |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
280 measure variation, initial measure, time duration, weather indicators |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
281 |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
282 TODO if measurements per lane, add a variable for lane position (position1 to 6) |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
283 lanePositions = list of integers (range(1,7)) |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
284 measure variation, initial measure, time duration, lane position1, weather indicators |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
285 measure variation, initial measure, time duration, lane position2, weather indicators |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
286 ...''' |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
287 variationData = [] |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
288 if lanePositions == None: |
447
7ef40014236c
updated weather indicator calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
446
diff
changeset
|
289 nonZeroIndices = ~np.isnan(self.data[dataLabel]) |
446
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
290 days = self.data[nonZeroIndices]['jours'] |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
291 dates = self.data[nonZeroIndices]['date_mesure'] |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
292 measures = self.data[nonZeroIndices][dataLabel] |
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
293 for i in range(1, len(dates)): |
447
7ef40014236c
updated weather indicator calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
446
diff
changeset
|
294 nDaysTNegative, nDaysThawFreeze, deltaTemp, nConsecutiveFrozenDays, totalRain, totalSnow, snowAboveThreshold, stdevTemp = ecWeatherIndicators(weatherData, dates[i-1], dates[i], snowThreshold, minProportionMeasures) |
450
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
295 if dates[i-1].year+1 == dates[i].year: |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
296 winter = 1 |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
297 if days[i-1]<365: |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
298 firstWinter = 1 |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
299 else: |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
300 winter = 0 |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
301 firstWinter = 0 |
c0786fe4ad94
small additions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
449
diff
changeset
|
302 variationData.append([measures[i-1]-measures[i], measures[i-1], days[i]-days[i-1], days[i-1], winter, firstWinter, nDaysTNegative, nDaysThawFreeze] + deltaTemp + [nConsecutiveFrozenDays, totalRain, totalSnow, snowAboveThreshold, stdevTemp]) |
446
a65a14c90834
adding weather info to pavement data
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
440
diff
changeset
|
303 return variationData |