def detect(abf,sweep=None,threshold_upslope=<NUM_LIT:50>,dT=<NUM_LIT>,saveToo=True):
if type(sweep) is int:<EOL><INDENT>sweeps=[sweep]<EOL><DEDENT>else:<EOL><INDENT>sweeps=list(range(abf.sweeps))<EOL><DEDENT>timeStart=time.clock()<EOL>abf.APs=[None]*abf.sweeps<EOL>abf.SAP=[None]*abf.sweeps<EOL>for sweep in sweeps:<EOL><INDENT>abf.setSweep(sweep)<EOL>Y=abf.dataY<EOL>dI = int(dT/<NUM_LIT:1000>*abf.rate) <EOL>dY = (Y[dI:]-Y[:-dI])*(abf.rate/<NUM_LIT:1000>/dI) <EOL>Is = cm.where_cross(dY,threshold_upslope) <EOL>abf.APs[sweep]=[]<EOL>for i in range(len(Is)): <EOL><INDENT>try:<EOL><INDENT>AP=analyzeAP(Y,dY,Is[i],abf.rate) <EOL>if AP:<EOL><INDENT>AP["<STR_LIT>"]=sweep<EOL>AP["<STR_LIT>"]=sweep*abf.sweepInterval*abf.rate*+AP["<STR_LIT>"]<EOL>AP["<STR_LIT>"]=sweep*abf.sweepInterval+AP["<STR_LIT>"]<EOL>AP["<STR_LIT>"]=np.nan <EOL>if len(abf.APs[sweep]):<EOL><INDENT>AP["<STR_LIT>"]=<NUM_LIT:1>/(AP["<STR_LIT>"]-abf.APs[sweep][-<NUM_LIT:1>]["<STR_LIT>"])<EOL><DEDENT>if AP["<STR_LIT>"] is np.nan or AP["<STR_LIT>"]<<NUM_LIT>: <EOL><INDENT>abf.APs[sweep].append(AP)<EOL><DEDENT><DEDENT><DEDENT>except:<EOL><INDENT>print("<STR_LIT>"%(i+<NUM_LIT:1>,len(Is)))<EOL><DEDENT><DEDENT>analyzeAPgroup(abf) <EOL><DEDENT>abf.APs=cm.matrixfromDicts(abf.APs)<EOL>abf.SAP=cm.matrixfromDicts(abf.SAP)<EOL>print("<STR_LIT>"%(len(cm.dictFlat(abf.APs)),(time.clock()-timeStart)*<NUM_LIT:1000>))<EOL>if saveToo:<EOL><INDENT>abf.saveThing(abf.APs,"<STR_LIT>")<EOL>abf.saveThing(abf.SAP,"<STR_LIT>")<EOL><DEDENT>
An AP will be detected by a upslope that exceeds 50V/s. Analyzed too.
    if type(sweep) is int, graph int(sweep)
    if sweep==None, process all sweeps sweep.