# HG changeset patch # User Nicolas Saunier # Date 1391498007 18000 # Node ID a65a14c908345d48bed0e69af8f267c481da6511 # Parent f0ce17ea9273ce30702c1e9f7cbd3d7e2cbb2c6c adding weather info to pavement data diff -r f0ce17ea9273 -r a65a14c90834 python/pavement.py --- a/python/pavement.py Fri Jan 31 00:10:31 2014 -0500 +++ b/python/pavement.py Tue Feb 04 02:13:27 2014 -0500 @@ -5,38 +5,6 @@ __metaclass__ = type -class RTSS: - 'class for data related to a RTSS, including agregating pavement marking measurements' - - def __init__(self, id): - self.id = id - -class MarkingTest: - '''class for a test site for a given product''' - - def __init__(self, siteId, paintingDate, paintingType, color, data): - self.siteId = siteId - self.paintingDate = paintingDate - self.paintingType = paintingType - self.color = color - self.data = data - self.nMeasures = len(data) - - def plot(self, measure, options = 'o', dayRatio = 1., **kwargs): - from matplotlib.pyplot import plot - plot(self.data['jours']/float(dayRatio), - self.data[measure], options, **kwargs) - - def getMarkingMeasures(self, dataLabel): - from numpy import isnan - nonZeroIndices = ~isnan(self.data[dataLabel]) - return self.data[nonZeroIndices]['jours'], self.data[nonZeroIndices][dataLabel] - - def plotMarkingMeasures(self, measure, options = 'o', dayRatio = 1., **kwargs): - for i in range(1,7): - self.plot('{}_{}'.format(measure, i), options, dayRatio, **kwargs) - - def occ_max(a): if a != []: s = set(a) @@ -198,3 +166,65 @@ neigeEC_sup_seuil = 1 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) + + +class RTSS: + 'class for data related to a RTSS, including agregating pavement marking measurements' + + def __init__(self, id): + self.id = id + +class MarkingTest: + '''class for a test site for a given product + + including the series of measurements over the years''' + + def __init__(self, id, paintingDate, paintingType, color, data): + self.id = id + self.paintingDate = paintingDate + self.paintingType = paintingType + self.color = color + self.data = data + self.nMeasures = len(data) + + def getSite(self): + return int(self.id[:2]) + + def getTestAttributes(self): + return [self.paintingType, self.color] + + def plot(self, measure, options = 'o', dayRatio = 1., **kwargs): + from matplotlib.pyplot import plot + plot(self.data['jours']/float(dayRatio), + self.data[measure], options, **kwargs) + + def getMarkingMeasures(self, dataLabel): + from numpy import isnan + nonZeroIndices = ~isnan(self.data[dataLabel]) + return self.data[nonZeroIndices]['jours'], self.data[nonZeroIndices][dataLabel] + + def plotMarkingMeasures(self, measure, options = 'o', dayRatio = 1., **kwargs): + for i in range(1,7): + self.plot('{}_{}'.format(measure, i), options, dayRatio, **kwargs) + + def computeMarkingMeasureVariations(self, dataLabel, lanePositions, weatherData, snowThreshold): + '''Computes for each successive measurement + lanePositions = None + measure variation, initial measure, time duration, weather indicators + + TODO if measurements per lane, add a variable for lane position (position1 to 6) + lanePositions = list of integers (range(1,7)) + measure variation, initial measure, time duration, lane position1, weather indicators + measure variation, initial measure, time duration, lane position2, weather indicators + ...''' + from numpy import isnan + variationData = [] + if lanePositions == None: + nonZeroIndices = ~isnan(self.data[dataLabel]) + days = self.data[nonZeroIndices]['jours'] + dates = self.data[nonZeroIndices]['date_mesure'] + measures = self.data[nonZeroIndices][dataLabel] + for i in range(1, len(dates)): + nDaysTNegative, nDaysThawFreeze, deltaTemp, nConsecutiveFrozenDays, totalRain, totalSnow, snowAboveThreshold, stdevTemp = ecWeatherIndicators(weatherData, dates[i-1], dates[i], snowThreshold) + variationData.append([measures[i-1]-measures[i], measures[i-1], days[i]-days[i-1], nDaysTNegative, nDaysThawFreeze] + deltaTemp + [nConsecutiveFrozenDays, totalRain, totalSnow, snowAboveThreshold, stdevTemp]) + return variationData