def fitExp(ds, select=(None, [0], None), newpath='/o4'): dat=getSelection(ds, select) h=getSelectionHeader(ds, select) fs=h['SamplesPerSecond'] start=h.get('StartTime', 0) ld=log(ravel(dat)) m, b = regress(ld, fs, start) x=start+arange(ld.shape[0])/fs y=exp(m*x+b) v=((m, b), y) if newpath: np=ds.getSubData(newpath) if not np: np=ds.createSubData(newpath) np.datinit(v[1], h) else: setSelection(ds, select, v[1])
def showProjection(doc, upath="/Data:DataFile"): nip='/Data:proj' ndat=doc.getInstance(upath).getData() fromTimeSeries(doc, upath, 2.0, width=-1, outputPath=nip) #pad(doc, nip, 10, 10, 50, 50) idat, h=getImageDataAndHeader(doc, nip) ndat-=array(h['SpatialAnchor'][:2]) m, b = regress(ndat) line=255*_makeline(m, b, idat.shape) line=reshape(line, (line.shape[0], line.shape[1], 1, 1)) df=colorOverlay(idat, line) frames=[] for i in range(idat.shape[3]): x, y = _ptoline(ndat[i,0], ndat[i,1], m, b) ball = 255*makeball(x, y, 1.0, idat.shape) ball=reshape(ball, (ball.shape[0], ball.shape[1], 1, 1)) frames.append(concatenate([idat[:,:,:,i:i+1], line, ball], 2)) df=concatenate(frames, 3) setImageData(df, nip, doc)
def findLine(doc, image, outputPath='line'): '''finds the best fit line in the indicated frame''' dat=getImageData(doc, image) if not isBinary(dat): print("Warning: dat is not binary. Using an automatic threshold") me, ma, st= dat.mean(), dat.max(), dat.std() thresh=min(ma-st, me+st) dat=dat>=thresh frames=range(dat.shape[3]) get=[] lines=[] for frame in frames: df=dat[:,:,0,frame] ind=transpose(array(nonzero(df))).astype(float32) m, b = regress(ind) lines.append((m,b)) line=_makeline(m, b, df.shape) df=colorOverlay(df, line) get.append(df) df=concatenate(get, 3) setImageData(df, outputPath or image, doc) setTimeseriesData(doc, image, lines, outputPath, ['Slope', 'Intercept'])
def findPoint(doc, image, outputPath='point'): dat=getImageData(doc, image) if not isBinary(dat): print("Warning: dat is not binary. Using an automatic threshold") me, ma, st= dat.mean(), dat.max(), dat.std() thresh=min(ma-st, me+st) dat=dat>=thresh frames=range(dat.shape[3]) get=[] points=[] for frame in frames: df=dat[:,:,0,frame] ind=transpose(array(nonzero(df))).astype(float32) m, b = regress(ind) x=ind[:,0].mean() y=m*x+b points.append((x,y)) pt=zeros_like(df) pt[x,y]=1.0 df=colorOverlay(df, pt) get.append(df) df=concatenate(get, 3) setImageData(df, outputPath, doc) setTimeseriesData(doc, image, points, outputPath, ['X', 'Y'])