def draw(self): if not hasattr(self, 'subplot'): self.subplot = self.figure.add_subplot(111) ofd = ofind.ObjectIdentifier(scope.pa.dsa.astype('f').squeeze().T) ofd.FindObjects(70, 0, splitter=True) #print len(ofd) X = (((ps.xp - ps.currPos[0]) / .00007)[:, None] * numpy.ones(ps.yp.shape)[None, :]).ravel() Y = (((ps.yp - ps.currPos[1]) / .00007)[None, :] * numpy.ones(ps.xp.shape)[:, None]).ravel() self.subplot.cla() for i, o in enumerate(ofd): self.subplot.scatter(o.x + X, o.y + Y, c=i * numpy.ones(X.shape), vmin=0, vmax=len(ofd)) self.subplot.set_xlim(0, 512) self.subplot.set_ylim(0, 256) self.canvas.draw()
def _findFiducials(self, sfunc, debounce): #################################################### # Find Fiducials self.mIm = numpy.ones(self.data.shape, 'f') for dri in self.driftEstInd: bs = bufferManager.dBuffer.getSlice(dri) bs = bs.reshape(self.data.shape) #multiply images together, thus favouring images which are on over multiple frames self.mIm = self.mIm * numpy.maximum( bs.astype('f') - numpy.median(bs.ravel()), 1) #self.mIm = numpy.absolute(self.mIm) if not 'PSFFile' in self.md.getEntryNames(): self.ofdDr = ofind.ObjectIdentifier(self.mIm) else: self.ofdDr = ofind_xcorr.ObjectIdentifier( self.mIm, self.md.getEntry('PSFFile'), 7, 3e-2) thres = self.calObjThresh**10 self.ofdDr.FindObjects(thres, 0, splitter=sfunc, debounceRadius=debounce) while len(self.ofdDr) >= 10: #just go for the brightest ones thres = thres * max(2, len(self.ofdDr) / 5) self.ofdDr.FindObjects(thres, 0, splitter=sfunc, debounceRadius=debounce)
def fitDep(g, r, ofindThresh, dx, dy): rg = r + g #detect objects in sum image ofd = ofind.ObjectIdentifier(rg) ofd.FindObjects(ofindThresh, blurRadius=2) res_d = np.empty(len(ofd), FitResultsDType) class foo: pass md = MetaData.TIRFDefault md.chroma = foo() md.chroma.dx = dx md.chroma.dy = dy ff = FitFactory( np.concatenate((g.reshape(512, -1, 1), r.reshape(512, -1, 1)), 2), md) for i in range(len(ofd)): p = ofd[i] res_d[i] = ff.FromPoint(round(p.x), round(p.y)) return res_d
def fitIndep(g, r, ofindThresh): rg = r + g #detect objects in sum image ofd = ofind.ObjectIdentifier(rg) ofd.FindObjects(ofindThresh, blurRadius=2) res_g = np.empty(len(ofd), FitResultsDType) res_r = np.empty(len(ofd), FitResultsDType) ff_g = FitFactory(g.reshape(512, 256, 1), MetaData.TIRFDefault) ff_r = FitFactory(r.reshape(512, 256, 1), MetaData.TIRFDefault) for i in range(len(ofd)): p = ofd[i] res_g[i] = ff_g.FromPoint(round(p.x), round(p.y)) res_r[i] = ff_r.FromPoint(round(p.x), round(p.y)) return (res_g, res_r)
def __call__(self, gui=False, taskQueue=None): global dBuffer, bBuffer, dataSourceID, nTasksProcessed #import our fitting module fitMod = __import__('PYME.Analysis.FitFactories.' + self.fitModule, fromlist=['PYME', 'Analysis', 'FitFactories']) #create a local copy of the metadata md = copy.copy(self.md) md.tIndex = self.index md.taskQueue = taskQueue md.dataSourceID = self.dataSourceID #make sure we're buffering the right data stream bufferManager.updateBuffers(md, self.dataSourceModule, self.bufferLen) self.data = bufferManager.dBuffer.getSlice(self.index) nTasksProcessed += 1 #print self.index #when camera buffer overflows, empty pictures are produced - deal with these here ----------------- brand if self.data.max() == 0: return fitResult(self, []) #squash 4th dimension self.data = cameraMaps.correctImage(md, self.data.squeeze()).reshape( (self.data.shape[0], self.data.shape[1], 1)) #calculate background self.bg = self.md['Camera.ADOffset'] if not len(self.bgindices) == 0: self.bg = cameraMaps.correctImage( md, bufferManager.bBuffer.getBackground( self.bgindices)).reshape(self.data.shape) #calculate noise self.sigma = self.calcSigma(md, self.data - self.md['Camera.ADOffset']) ############################################# # Special cases - defer object finding to fit module if self.fitModule == 'ConfocCOIR': #special case - no object finding self.res = fitMod.ConfocCOI(self.data, md, background=self.bg) return fitResult(self, self.res, []) if 'MULTIFIT' in dir(fitMod): #fit module does it's own object finding ff = fitMod.FitFactory(self.data, md, background=self.bg) self.res = ff.FindAndFit(self.threshold, gui=gui) return fitResult(self, self.res, []) ############################################## # Find candidate molecule positions bgd = (self.data.astype('f') - self.bg) print bgd.shape, self.calcThreshold().shape if 'Splitter.TransmittedChannel' in self.md.getEntryNames(): #don't find points in transmitted light channel transChan = md.getEntry('Splitter.TransmitedChannel') if transChan == 'Top': bgd[:, :(self.data.shape[1] / 2)] = 0 #set upper half of image to zero #define splitter mapping function (if appropriate) for use in object finding sfunc = None if self.fitModule in splitterFitModules: sfunc = self.__mapSplitterCoords #Choose which version of ofind to use if 'PRI.Axis' in self.md.getEntryNames( ) and not self.md['PRI.Axis'] == 'none': self.ofd = ofind_pri.ObjectIdentifier(bgd * (bgd > 0), md, axis=self.md['PRI.Axis']) else: # not 'PSFFile' in self.md.getEntryNames(): self.ofd = ofind.ObjectIdentifier(bgd * (bgd > 0)) #else: #if we've got a PSF then use cross-correlation object identificatio # self.ofd = ofind_xcorr.ObjectIdentifier(bgd * (bgd > 0), md, 7, 5e-2) debounce = self.md.getOrDefault('Analysis.DebounceRadius', 5) discardClumpRadius = self.md.getOrDefault('Analysis.ClumpRejectRadius', 0) self.ofd.FindObjects(self.calcThreshold(), 0, splitter=sfunc, debounceRadius=debounce, discardClumpRadius=discardClumpRadius) #################################################### # Find Fiducials if self.driftEst: self._findFiducials(sfunc, debounce) ##################################################################### #If we are using a splitter, chop the largest common ROI out of the two channels if self.fitModule in splitterFitModules: self.data = self._splitImage(self.data) if not len(self.bgindices) == 0: self.bg = self._splitImage(self.bg) #If we're running under a gui - display found objects if gui: self._displayFoundObjects() ######################################################### #Create a fit 'factory' fitFac = fitMod.FitFactory(self.data, md, background=self.bg, noiseSigma=self.sigma) #perform fit for each point that we detected if 'FitResultsDType' in dir(fitMod): self.res = numpy.empty(len(self.ofd), fitMod.FitResultsDType) if 'Analysis.ROISize' in md.getEntryNames(): rs = md.getEntry('Analysis.ROISize') for i in range(len(self.ofd)): p = self.ofd[i] self.res[i] = fitFac.FromPoint(p.x, p.y, roiHalfSize=rs) else: for i in range(len(self.ofd)): p = self.ofd[i] self.res[i] = fitFac.FromPoint(p.x, p.y) else: self.res = [fitFac.FromPoint(p.x, p.y) for p in self.ofd] #Fit Fiducials NOTE: This is potentially broken self.drRes = [] if self.driftEst: nToFit = min(10, len( self.ofdDr)) #don't bother fitting lots of calibration objects if 'FitResultsDType' in dir(fitMod): self.drRes = numpy.empty(nToFit, fitMod.FitResultsDType) for i in range(nToFit): p = self.ofdDr[i] self.drRes[i] = fitFac.FromPoint(p.x, p.y) else: self.drRes = [ fitFac.FromPoint(p.x, p.y) for p in self.ofd[:nToFit] ] return fitResult(self, self.res, self.drRes)