Mercurial Hosting > traffic-intelligence
diff python/utils.py @ 574:e24eeb244698
first implementation of projection to curvilinear coordinates
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 13 Aug 2014 00:00:08 -0400 |
parents | 0057c04f94d5 |
children | c5406edbcf12 84690dfe5560 |
line wrap: on
line diff
--- a/python/utils.py Tue Aug 12 17:47:16 2014 -0400 +++ b/python/utils.py Wed Aug 13 00:00:08 2014 -0400 @@ -251,6 +251,19 @@ def crossProduct(l1, l2): return l1[0]*l2[1]-l1[1]*l2[0] +def cat_mvgavg(cat_list, halfWidth): + ''' Return a list of categories/values smoothed according to a window. + halfWidth is the search radius on either side''' + from copy import deepcopy + catgories = deepcopy(cat_list) + smoothed = catgories + for point in range(len(catgories)): + lower_bound_check = max(0,point-halfWidth) + upper_bound_check = min(len(catgories)-1,point+halfWidth+1) + window_values = catgories[lower_bound_check:upper_bound_check] + smoothed[point] = max(set(window_values), key=window_values.count) + return smoothed + def filterMovingWindow(inputSignal, halfWidth): '''Returns an array obtained after the smoothing of the input by a moving average The first and last points are copied from the original.'''