comparison python/utils.py @ 837:e01cabca4c55

minor modifications to merge-features
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 06 Jul 2016 10:58:18 -0400
parents 10dbab1e871d
children 15a82ebc62c4
comparison
equal deleted inserted replaced
836:7058a40a4bbc 837:e01cabca4c55
235 '''Returns the media of Y's corresponding to X's in the interval [x-halfwidth, x+halfwidth]''' 235 '''Returns the media of Y's corresponding to X's in the interval [x-halfwidth, x+halfwidth]'''
236 return median([y for observedx, y in zip(X,Y) if abs(x-observedx)<halfwidth]) 236 return median([y for observedx, y in zip(X,Y) if abs(x-observedx)<halfwidth])
237 237
238 def argmaxDict(d): 238 def argmaxDict(d):
239 return max(d, key=d.get) 239 return max(d, key=d.get)
240
241 def deltaFrames(t1, t2, frameRate):
242 '''Returns the number of frames between t1 and t2
243 positive if t1<=t2, negative otherwise'''
244 if t1 > t2:
245 return -(t1-t2).seconds*frameRate
246 else:
247 return (t2-t1).seconds*frameRate
240 248
241 def framesToTime(nFrames, frameRate, initialTime = time()): 249 def framesToTime(nFrames, frameRate, initialTime = time()):
242 '''returns a datetime.time for the time in hour, minutes and seconds 250 '''returns a datetime.time for the time in hour, minutes and seconds
243 initialTime is a datetime.time''' 251 initialTime is a datetime.time'''
244 seconds = int(floor(float(nFrames)/float(frameRate))+initialTime.hour*3600+initialTime.minute*60+initialTime.second) 252 seconds = int(floor(float(nFrames)/float(frameRate))+initialTime.hour*3600+initialTime.minute*60+initialTime.second)