def GetOStretchByIndices(sep,force,idxStart,idxEnd): mParams = [] mPredictedX = [] mPredictedY = [] # make (linear fits for each) for realIdxInit,realIdxFinal in zip(idxStart,idxEnd): toFitX = sep[realIdxInit:realIdxFinal] toFitY = force[realIdxInit:realIdxFinal] # get the parameters params,_,predictedOStretch = pGenUtil.GenFit(toFitX,toFitY) # add the values we need... mParams.append(params) mPredictedX.append(toFitX) mPredictedY.append(predictedOStretch) # POST: all parameters calculared # need to get the start of the delta L0 L0Init = pGenUtil.lineIntersectParam(mParams[0],mParams[1]) # get the end of the final L0Final = pGenUtil.lineIntersectParam(mParams[1],mParams[2]) approxDelL0 = L0Final-L0Init # get the midpoint, to find the overstretching force midPoint = L0Init + 0.5 * approxDelL0 # get the index of the midpoint idxBetween = np.argmin(np.abs(sep-midPoint)) # if for some reason the data is very noisy, just # use the mean index of the transition (index 2) # to get the indices... indexOStretch = 1 if (idxBetween < idxStart[indexOStretch]): startTx = idxStart[indexOStretch] endTx = idxEnd[indexOStretch] idxBetween = np.mean([startTx,endTx]) whereOStretch = sep[idxBetween] oStretchForce = np.polyval(mParams[1],whereOStretch) return mParams,mPredictedX,mPredictedY,whereOStretch,oStretchForce
def getTouchoffCalibration(timeAppr,forceAppr,mDerivApproach,isApproach): idxStart,idxEnd = getCrossIdxFromApproach(mDerivApproach) # fit lines to the force # start and end *always demarcate the start and end (ish) of the invols # if we are approach, we take everything *before* as constant # if we are touchoff, we take everything *after* as constant if (isApproach): constantSlice = np.s_[0:idxStart] touchoffSlice = np.s_[idxStart:idxEnd] else: constantSlice = np.s_[idxEnd:] touchoffSlice = np.s_[idxStart:idxEnd] timeApprLow = timeAppr[constantSlice] timeTouch = timeAppr[touchoffSlice] paramsFirst,stdFirst,predFirst= pGenUtil.GenFit(timeApprLow, forceAppr[constantSlice]) paramsSecond,stdSecond,predSecond = \ pGenUtil.GenFit(timeTouch,forceAppr[touchoffSlice]) # XXX get error estimate using standard deviations? timeSurface = pGenUtil.lineIntersectParam(paramsFirst, paramsSecond) idxSurface = np.argmin(np.abs(timeAppr-timeSurface)) # set the variables we care about calibObj = CalibrateObject(idxStart,idxEnd, constantSlice,touchoffSlice, paramsFirst,stdFirst,predFirst, paramsSecond,stdSecond,predSecond, timeSurface,idxSurface) return calibObj