def analyzeAP(Y,dY,I,rate,verbose=False):
Ims = int(rate/<NUM_LIT:1000>) <EOL>IsToLook=<NUM_LIT:5>*Ims <EOL>upslope=np.max(dY[I:I+IsToLook]) <EOL>upslopeI=np.where(dY[I:I+IsToLook]==upslope)[<NUM_LIT:0>][<NUM_LIT:0>]+I<EOL>I=upslopeI <EOL>downslope=np.min(dY[I:I+IsToLook]) <EOL>downslopeI=np.where(dY[I:I+IsToLook]==downslope)[<NUM_LIT:0>][<NUM_LIT:0>]+I<EOL>peak=np.max(Y[I:I+IsToLook]) <EOL>peakI=np.where(Y[I:I+IsToLook]==peak)[<NUM_LIT:0>][<NUM_LIT:0>]+I <EOL>thresholdI=I-np.where(dY[I:I+IsToLook:--<NUM_LIT:1>]<<NUM_LIT:10>)[<NUM_LIT:0>] <EOL>if not len(thresholdI):<EOL><INDENT>return False<EOL><DEDENT>thresholdI=thresholdI[<NUM_LIT:0>]<EOL>threshold=Y[thresholdI] <EOL>height=peak-threshold <EOL>halfwidthPoint=np.average((threshold,peak))<EOL>halfwidth=np.where(Y[I-IsToLook:I+IsToLook]>halfwidthPoint)[<NUM_LIT:0>]<EOL>if not len(halfwidth):<EOL><INDENT>return False <EOL><DEDENT>halfwidthI1=halfwidth[<NUM_LIT:0>]+I-IsToLook<EOL>halfwidthI2=halfwidth[-<NUM_LIT:1>]+I-IsToLook<EOL>if Y[halfwidthI1-<NUM_LIT:1>]>halfwidthPoint or Y[halfwidthI2+<NUM_LIT:1>]>halfwidthPoint:<EOL><INDENT>return False <EOL><DEDENT>halfwidth=len(halfwidth)/rate*<NUM_LIT:1000> <EOL>riseTime=(peakI-thresholdI)*<NUM_LIT:1000>/rate <EOL>IsToLook=<NUM_LIT:100>*Ims <EOL>AHPchunk=np.diff(Y[downslopeI:downslopeI+IsToLook]) <EOL>AHPI=np.where(AHPchunk><NUM_LIT:0>)[<NUM_LIT:0>]<EOL>if len(AHPI)==<NUM_LIT:0>:<EOL><INDENT>AHPI=np.nan<EOL><DEDENT>else:<EOL><INDENT>AHPI=AHPI[<NUM_LIT:0>]+downslopeI<EOL>AHPchunk=Y[AHPI:AHPI+IsToLook]<EOL>if max(AHPchunk)>threshold: <EOL><INDENT>AHPchunk=AHPchunk[:np.where(AHPchunk>threshold)[<NUM_LIT:0>][<NUM_LIT:0>]]<EOL><DEDENT>if len(AHPchunk):<EOL><INDENT>AHP=np.nanmin(AHPchunk)<EOL>AHPI=np.where(AHPchunk==AHP)[<NUM_LIT:0>][<NUM_LIT:0>]+AHPI<EOL>AHPheight=threshold-AHP <EOL>IsToLook=<NUM_LIT>*Ims <EOL>AHPreturn=np.average((AHP,threshold)) <EOL>AHPreturnI=np.where(Y[AHPI:AHPI+IsToLook]>AHPreturn)[<NUM_LIT:0>]<EOL>if len(AHPreturnI): <EOL><INDENT>AHPreturnI=AHPreturnI[<NUM_LIT:0>]+AHPI<EOL>AHPrisetime=(AHPreturnI-AHPI)*<NUM_LIT:2>/rate*<NUM_LIT:1000> <EOL>AHPupslope=AHPheight/AHPrisetime <EOL>AHPreturnFullI=(AHPreturnI-AHPI)*<NUM_LIT:2>+AHPI<EOL><DEDENT>else: <EOL><INDENT>AHPreturnI,AHPrisetime,AHPupslope=np.nan,np.nan,np.nan<EOL>downslope=np.nan<EOL><DEDENT><DEDENT><DEDENT>sweepI,sweepT=I,I/rate <EOL>del IsToLook,I, Y, dY, Ims, AHPchunk, verbose <EOL>return locals()<EOL>
given a sweep and a time point, return the AP array for that AP.
APs will be centered in time by their maximum upslope.