def detectSweep(self,sweep=<NUM_LIT:0>):
if self.APs is False: <EOL><INDENT>self.APs=[] <EOL><DEDENT>for i,ap in enumerate(self.APs):<EOL><INDENT>if ap["<STR_LIT>"]==sweep:<EOL><INDENT>self.APs[i]=None<EOL><DEDENT><DEDENT>if self.APs.count(None):<EOL><INDENT>self.log.debug("<STR_LIT>",self.APs.count(None))<EOL>while None in self.APs:<EOL><INDENT>self.APs.remove(None)<EOL><DEDENT><DEDENT>self.log.debug("<STR_LIT>",len(self.APs))<EOL>self.abf.derivative=True<EOL>self.abf.setsweep(sweep)<EOL>Is = cm.where_cross(self.abf.sweepD,self.detect_over)<EOL>self.log.debug("<STR_LIT>"%len(Is))<EOL>for i,I in enumerate(Is):<EOL><INDENT>if np.min(self.abf.sweepD[I:I+<NUM_LIT:2>*self.abf.pointsPerMs])>-<NUM_LIT:10>:<EOL><INDENT>Is[i]=<NUM_LIT:0><EOL><DEDENT><DEDENT>Is=Is[np.nonzero(Is)]<EOL>self.log.debug("<STR_LIT>"%len(Is))<EOL>for i,I in enumerate(Is):<EOL><INDENT>stepBack=<NUM_LIT:0><EOL>while(self.abf.sweepD[I-stepBack])><NUM_LIT:10> and stepBack/self.abf.pointsPerMs<<NUM_LIT:1>: <EOL><INDENT>stepBack+=<NUM_LIT:1><EOL><DEDENT>Is[i]-=stepBack<EOL><DEDENT>sweepAPs=[]<EOL>for i,I in enumerate(Is):<EOL><INDENT>try:<EOL><INDENT>timeInSweep=I/self.abf.pointsPerSec<EOL>if timeInSweep<self.detect_time1 or timeInSweep>self.detect_time2:<EOL><INDENT>continue <EOL><DEDENT>ap={} <EOL>ap["<STR_LIT>"]=sweep <EOL>ap["<STR_LIT:I>"]=I <EOL>ap["<STR_LIT>"]=I/self.abf.pointsPerSec <EOL>ap["<STR_LIT:T>"]=ap["<STR_LIT>"]+self.abf.sweepInterval*sweep <EOL>ap["<STR_LIT>"]=self.abf.sweepY[I] <EOL>chunk=self.abf.sweepD[I:I+<NUM_LIT:5>*self.abf.pointsPerMs] <EOL>I_toNegTen=np.where(chunk<-<NUM_LIT:10>)[<NUM_LIT:0>][<NUM_LIT:0>]<EOL>chunk=self.abf.sweepD[I+I_toNegTen:I+I_toNegTen+<NUM_LIT:10>*self.abf.pointsPerMs] <EOL>if not max(chunk)>-<NUM_LIT:10>:<EOL><INDENT>self.log.debug("<STR_LIT>"%ap["<STR_LIT:T>"])<EOL>self.log.error("<STR_LIT>")<EOL>continue <EOL><DEDENT>I_recover=np.where(chunk>-<NUM_LIT:10>)[<NUM_LIT:0>][<NUM_LIT:0>]+I_toNegTen+I <EOL>ap["<STR_LIT>"]=[I,I_recover] <EOL>ap["<STR_LIT>"]=(I_recover-I)/self.abf.pointsPerMs <EOL>chunk=self.abf.sweepD[ap["<STR_LIT>"][<NUM_LIT:0>]:ap["<STR_LIT>"][<NUM_LIT:1>]]<EOL>ap["<STR_LIT>"]=np.max(chunk)<EOL>ap["<STR_LIT>"]=np.where(chunk==ap["<STR_LIT>"])[<NUM_LIT:0>][<NUM_LIT:0>]+I<EOL>ap["<STR_LIT>"]=np.min(chunk)<EOL>ap["<STR_LIT>"]=np.where(chunk==ap["<STR_LIT>"])[<NUM_LIT:0>][<NUM_LIT:0>]+I<EOL>if ap["<STR_LIT>"]<<NUM_LIT:10> or ap["<STR_LIT>"]>-<NUM_LIT:10>:<EOL><INDENT>self.log.debug("<STR_LIT>")<EOL>self.log.error("<STR_LIT>")<EOL>continue<EOL><DEDENT>chunkSize=self.abf.pointsPerMs*<NUM_LIT:10> <EOL>if len(Is)-<NUM_LIT:1>>i and Is[i+<NUM_LIT:1>]<(I+chunkSize): <EOL><INDENT>chunkSize=Is[i+<NUM_LIT:1>]-I <EOL><DEDENT>if chunkSize<(self.abf.pointsPerMs*<NUM_LIT:2>):<EOL><INDENT>continue <EOL><DEDENT>ap["<STR_LIT>"]=[I,I+chunkSize] <EOL>chunk=self.abf.sweepY[I:I+chunkSize]<EOL>ap["<STR_LIT>"]=np.max(chunk)<EOL>ap["<STR_LIT>"]=np.where(chunk==ap["<STR_LIT>"])[<NUM_LIT:0>][<NUM_LIT:0>]+I<EOL>chunkForMin=np.copy(chunk) <EOL>chunkForMin[:ap["<STR_LIT>"]-I]=np.inf <EOL>ap["<STR_LIT>"]=np.min(chunkForMin) <EOL>ap["<STR_LIT>"]=np.where(chunkForMin==ap["<STR_LIT>"])[<NUM_LIT:0>][<NUM_LIT:0>]+I<EOL>if ap["<STR_LIT>"]<ap["<STR_LIT>"]:<EOL><INDENT>self.log.error("<STR_LIT>")<EOL>self.log.error("<STR_LIT>") <EOL>self.log.error("<STR_LIT>")<EOL><DEDENT>if (len(chunk))-((I+len(chunk))-ap["<STR_LIT>"])<<NUM_LIT:10>:<EOL><INDENT>self.log.error("<STR_LIT>")<EOL>self.log.error("<STR_LIT>")<EOL>self.log.error("<STR_LIT>")<EOL><DEDENT>ap["<STR_LIT>"]=(ap["<STR_LIT>"]-I)/self.abf.pointsPerMs <EOL>ap["<STR_LIT>"]=(ap["<STR_LIT>"]-ap["<STR_LIT>"])/self.abf.pointsPerMs <EOL>ap["<STR_LIT>"]=np.average([ap["<STR_LIT>"],ap["<STR_LIT>"]]) <EOL>ap["<STR_LIT>"]=cm.where_cross(chunk,ap["<STR_LIT>"])[<NUM_LIT:0>]+I <EOL>ap["<STR_LIT>"]=cm.where_cross(-chunk,-ap["<STR_LIT>"])[<NUM_LIT:1>]+I <EOL>ap["<STR_LIT>"]=(ap["<STR_LIT>"]-ap["<STR_LIT>"])/self.abf.pointsPerMs <EOL>sweepAPs.extend([ap])<EOL><DEDENT>except Exception as e:<EOL><INDENT>self.log.error("<STR_LIT>",i,len(Is))<EOL>self.log.error(cm.exceptionToString(e))<EOL><DEDENT><DEDENT>self.log.debug("<STR_LIT>",len(sweepAPs))<EOL>self.APs.extend(sweepAPs)<EOL>self.abf.derivative=False<EOL>
perform AP detection on current sweep.