comparison 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
comparison
equal deleted inserted replaced
573:cae4e5f3fe9f 574:e24eeb244698
248 ''' Compute point-to-point distance (L2 norm, ie Euclidean distance)''' 248 ''' Compute point-to-point distance (L2 norm, ie Euclidean distance)'''
249 return sqrt((x2-x1)**2+(y2-y1)**2) 249 return sqrt((x2-x1)**2+(y2-y1)**2)
250 250
251 def crossProduct(l1, l2): 251 def crossProduct(l1, l2):
252 return l1[0]*l2[1]-l1[1]*l2[0] 252 return l1[0]*l2[1]-l1[1]*l2[0]
253
254 def cat_mvgavg(cat_list, halfWidth):
255 ''' Return a list of categories/values smoothed according to a window.
256 halfWidth is the search radius on either side'''
257 from copy import deepcopy
258 catgories = deepcopy(cat_list)
259 smoothed = catgories
260 for point in range(len(catgories)):
261 lower_bound_check = max(0,point-halfWidth)
262 upper_bound_check = min(len(catgories)-1,point+halfWidth+1)
263 window_values = catgories[lower_bound_check:upper_bound_check]
264 smoothed[point] = max(set(window_values), key=window_values.count)
265 return smoothed
253 266
254 def filterMovingWindow(inputSignal, halfWidth): 267 def filterMovingWindow(inputSignal, halfWidth):
255 '''Returns an array obtained after the smoothing of the input by a moving average 268 '''Returns an array obtained after the smoothing of the input by a moving average
256 The first and last points are copied from the original.''' 269 The first and last points are copied from the original.'''
257 from numpy import ones,convolve,array 270 from numpy import ones,convolve,array