def phasicTonic(self,m1=None,m2=None,chunkMs=<NUM_LIT:50>,quietPercentile=<NUM_LIT:10>,<EOL>histResolution=<NUM_LIT>,plotToo=False):
<EOL>m1=<NUM_LIT:0> if m1 is None else m1*self.pointsPerSec<EOL>m2=len(abf.sweepY) if m2 is None else m2*self.pointsPerSec<EOL>m1,m2=int(m1),int(m2)<EOL>padding=<NUM_LIT:200> <EOL>chunkPoints=int(chunkMs*self.pointsPerMs)<EOL>histBins=int((padding*<NUM_LIT:2>)/histResolution)<EOL>Y=self.sweepY[m1:m2]<EOL>hist,bins=np.histogram(Y,bins=<NUM_LIT:2>*padding)<EOL>Yoffset=bins[np.where(hist==max(hist))[<NUM_LIT:0>][<NUM_LIT:0>]]<EOL>Y=Y-Yoffset <EOL>nChunks=int(len(Y)/chunkPoints)<EOL>hist,bins=np.histogram(Y,bins=histBins,range=(-padding,padding))<EOL>Xs=bins[<NUM_LIT:1>:]<EOL>chunks=np.reshape(Y[:nChunks*chunkPoints],(nChunks,chunkPoints))<EOL>variances=np.var(chunks,axis=<NUM_LIT:1>)<EOL>percentiles=np.empty(len(variances))<EOL>for i,variance in enumerate(variances):<EOL><INDENT>percentiles[i]=sorted(variances).index(variance)/len(variances)*<NUM_LIT:100><EOL><DEDENT>blData=chunks[np.where(percentiles<=quietPercentile)[<NUM_LIT:0>]].flatten()<EOL>sigma=np.sqrt(np.var(blData))<EOL>center=np.average(blData)+histResolution/<NUM_LIT:2><EOL>blCurve=mlab.normpdf(Xs,center,sigma)<EOL>blCurve=blCurve*max(hist)/max(blCurve)<EOL>diff=hist-blCurve<EOL>if plotToo:<EOL><INDENT>plt.figure(figsize=(<NUM_LIT:15>,<NUM_LIT:5>))<EOL>plt.plot(Y)<EOL>plt.figure(figsize=(<NUM_LIT:7>,<NUM_LIT:7>))<EOL>ax1=plt.subplot(<NUM_LIT>)<EOL>plt.title(abf.ID+"<STR_LIT>")<EOL>plt.ylabel("<STR_LIT>")<EOL>plt.plot(Xs,hist,'<STR_LIT:->',alpha=<NUM_LIT>,color='<STR_LIT:b>',lw=<NUM_LIT:3>)<EOL>plt.plot(Xs,blCurve,lw=<NUM_LIT:3>,alpha=<NUM_LIT>,color='<STR_LIT:r>')<EOL>plt.margins(<NUM_LIT:0>,<NUM_LIT>)<EOL>plt.subplot(<NUM_LIT>,sharex=ax1)<EOL>plt.title("<STR_LIT>")<EOL>plt.ylabel("<STR_LIT>")<EOL>plt.xlabel("<STR_LIT>"%abf.units)<EOL>plt.plot(Xs,diff,'<STR_LIT:->',alpha=<NUM_LIT>,color='<STR_LIT:b>',lw=<NUM_LIT:3>)<EOL>plt.axhline(<NUM_LIT:0>,lw=<NUM_LIT:3>,alpha=<NUM_LIT>,color='<STR_LIT:r>')<EOL>plt.axvline(<NUM_LIT:0>,lw=<NUM_LIT:3>,alpha=<NUM_LIT>,color='<STR_LIT:k>')<EOL>plt.margins(<NUM_LIT:0>,<NUM_LIT>)<EOL>plt.axis([-<NUM_LIT:50>,<NUM_LIT:50>,None,None])<EOL>plt.tight_layout()<EOL>plt.show()<EOL><DEDENT>return [Xs,diff]<EOL>
let's keep the chunkMs as high as we reasonably can. 50ms is good.
Things get flakey at lower numbers like 10ms.

IMPORTANT! for this to work, prevent 0s from averaging in, so keep
bin sizes well above the data resolution.