Mercurial Hosting > traffic-intelligence
changeset 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 |
files | python/pavement.py |
diffstat | 1 files changed, 17 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/python/pavement.py Wed Feb 19 16:30:45 2014 -0500 +++ b/python/pavement.py Wed Feb 19 16:33:49 2014 -0500 @@ -140,11 +140,12 @@ 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, snowThreshold, minProportionMeasures = 0.): +def ecWeatherIndicators(data, startDate, endDate, snowThreshold, datatype, minProportionMeasures = 0.): '''Computes the indicators from Environment Canada files (loaded as a recarray using csv2rec in data), between start and end dates (datetime.datetime objects) + dataType is to indicate Environnement Canada data ('ec') or else MTQ minProportionMeasures is proportion of measures necessary to consider the indicators''' from matplotlib.mlab import find nbre_jours_T_negatif,nbre_jours_gel_degel,pluie_tot,neige_tot,ecart_type_T = 0,0,0,0,0 @@ -156,27 +157,30 @@ nDays = (endDate - startDate).days+1 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(',','.')) + if not np.isnan(data['tmax'][i]): + tmax = data['tmax'][i] 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 not np.isnan(data['tmin'][i]): + tmin = data['tmin'][i] + else: + tmin = None + if datatype == 'ec': + if data['pluie_tot'][i] != None and not np.isnan(data['pluie_tot'][i]): + pluie_tot += data['pluie_tot'][i] + if data['neige_tot'][i] != None and not np.isnan(data['neige_tot'][i]): + neige_tot += data['neige_tot'][i] 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 != None and tmin != 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 not np.isnan(data['tmoy'][i]): + tmoys.append(data['tmoy'][i]) if tmax != None: if tmax < 0: compteur += 1 @@ -186,7 +190,7 @@ else: compteur = 0 nbre_jours_gel_consecutifs = max(nbre_jours_gel_consecutifs,compteur) - if float(len(tmoys))/nDays >= minProportionMeasures: + if len(tmoys) > 0 and float(len(tmoys))/nDays >= minProportionMeasures: if tmoys != []: ecart_type_T = np.std(tmoys) else: