def findspikes(vm,vthresh=0,dvthresh=0.035,slope=True): #f=open("C:\\fs.tmp",'wb') #pickle.dump(vm,f) #f.close() sz=vm.size if slope: dvm=diff(vm) #don't know why these are flipped (up and down) but it works... tmp=findThreshCrossings(dvm,dvthresh) if tmp==None: return array([]) else: vdownthresh,vupthresh=tmp else: vupthresh,vdownthresh=findThreshCrossings(vm,vthresh) peak=zeros(vupthresh.size,dtype='int64') for i in arange(vupthresh.size-1)+1: #peak=index of upthreshold crossing+the index of the peak inbetween the up and downthresh #print 'i:', i #print 'vm: ', vm.shape #print 'vupthresh: ', vupthresh.shape,vupthresh[i] #print 'vdownthresh: ', vdownthresh.shape,vdownthresh[i] temptup=where(vm[vupthresh[i]:vdownthresh[i]]==vm[vupthresh[i]:vdownthresh[i]].max()) peak[i]=vupthresh[i]+temptup[0][0] return peak
def findFlashes(vec, vThresh): errorRes = (arange(0, dtype=float32), arange(0, dtype=float32)) print "Using flash threshold of %1.3f" % vThresh up, down = findThreshCrossings(vec, vThresh) if up == None: return errorRes if len(up) == 0 or len(up) > 3000: print "findFlashes: Found %d up crossings. Returning error." % len(up) return errorRes print "findFlashes: Found %d up crossings and %d down crossings." % (len(up), len(down)) flashSamp = sort(concatenate((up, down))) flashDiff = diff(flashSamp) ind = where(flashDiff < 80)[0] while len(ind) > 0: i = ind[0] flashSamp = flashSamp[setdiff1d(arange(len(flashSamp)), [i + 1, i + 2])] flashDiff = diff(flashSamp) ind = where(flashDiff < 80)[0] up = flashSamp[0::2] down = flashSamp[1::2] if len(up) == len(down): print "Found %d flashes." % len(up) return (up, down) else: print "Found %d up crossings and %d down crossings?" % (len(up), len(down)) return errorRes