def execute(self, namespace): from PYME.localization.FitFactories import GaussMultifitSR import pandas as pd img = namespace[self.inputImage] img.mdh['Analysis.PSFSigma'] = self.blobSigma res = [] for i in range(img.data.shape[2]): md = MetaDataHandler.NestedClassMDHandler(img.mdh) md['tIndex'] = i ff = GaussMultifitSR.FitFactory(self.scale * img.data[:, :, i], img.mdh, noiseSigma=np.ones_like( img.data[:, :, i].squeeze())) res.append(tabular.FitResultsSource(ff.FindAndFit(self.threshold))) #FIXME - this shouldn't be a DataFrame res = pd.DataFrame(np.vstack(res)) res.mdh = img.mdh namespace[self.outputName] = res
def _add_new_results(self, newResults): if len(newResults) > 0: if len(self.fitResults) == 0: self.fitResults = newResults self.ds = tabular.FitResultsSource(self.fitResults) self.ds.mdh = self.resultsMdh self.dsviewer.pipeline.OpenFile( ds=self.ds, imBounds=self.dsviewer.image.imgBounds) self.dsviewer.pipeline.mdh = self.resultsMdh try: self.dsviewer.LMDisplay.SetFit() except: pass else: self.fitResults = np.concatenate((self.fitResults, newResults)) self.ds.setResults(self.fitResults) self.dsviewer.pipeline.recipe.prune_dependencies_from_namespace( [ 'Localizations', ], True) self.dsviewer.pipeline.recipe.invalidate_data() self.progPan.fitResults = self.fitResults self.view.points = np.vstack((self.fitResults['fitResults']['x0'], self.fitResults['fitResults']['y0'], self.fitResults['tIndex'])).T self.numEvents = len(self.fitResults) try: self.dsviewer.LMDisplay.RefreshView() except: pass
def OnGenEvents(self, event): from PYME.simulation import locify #from PYME.Acquire.Hardware.Simulator import wormlike2 from PYME.IO import tabular from PYME.IO.image import ImageBounds import pylab #wc = wormlike2.wormlikeChain(100) pipeline = self.visFr.pipeline pipeline.filename = 'Simulation' pylab.figure() pylab.plot(self.xp, self.yp, 'x') #, lw=2) if isinstance(self.source, WormlikeSource): pylab.plot(self.xp, self.yp, lw=2) res = locify.eventify(self.xp, self.yp, self.meanIntensity, self.meanDuration, self.backgroundIntensity, self.meanEventNumber, self.scaleFactor, self.meanTime, z=self.zp) pylab.plot(res['fitResults']['x0'], res['fitResults']['y0'], '+') ds = tabular.MappingFilter(tabular.FitResultsSource(res)) if isinstance(self.source, ImageSource): pipeline.imageBounds = image.openImages[ self.source.image].imgBounds else: pipeline.imageBounds = ImageBounds.estimateFromSource(ds) pipeline.addDataSource('Generated Points', ds) pipeline.selectDataSource('Generated Points') from PYME.IO.MetaDataHandler import NestedClassMDHandler pipeline.mdh = NestedClassMDHandler() pipeline.mdh['Camera.ElectronsPerCount'] = 1 pipeline.mdh['Camera.TrueEMGain'] = 1 pipeline.mdh['Camera.CycleTime'] = 1 pipeline.mdh['voxelsize.x'] = .110 try: pipeline.filterKeys.pop('sig') except: pass pipeline.Rebuild() if len(self.visFr.layers) < 1: self.visFr.add_pointcloud_layer( ) #TODO - move this logic so that layer added automatically when datasource is added? #self.visFr.CreateFoldPanel() self.visFr.SetFit()
def analRefresh(self): newNumAnalysed = self.tq.getNumberTasksCompleted(self.queueName) if newNumAnalysed > self.numAnalysed: self.numAnalysed = newNumAnalysed newResults = self.tq.getQueueData(self.queueName, 'FitResults', len(self.fitResults)) if len(newResults) > 0: if len(self.fitResults) == 0: self.fitResults = newResults self.ds = tabular.FitResultsSource(self.fitResults) self.dsviewer.pipeline.OpenFile( ds=self.ds, imBounds=self.dsviewer.image.imgBounds) self.dsviewer.pipeline.mdh = self.resultsMdh try: self.dsviewer.LMDisplay.SetFit() except: pass else: self.fitResults = np.concatenate( (self.fitResults, newResults)) self.ds.setResults(self.fitResults) #self.dsviewer.pipeline.Rebuild() self.dsviewer.pipeline.recipe.prune_dependencies_from_namespace( [ 'Localizations', ], True) #logger.debug('Namespace keys (should just be Localizations): %s' % self.dsviewer.pipeline.recipe.namespace.keys()) self.dsviewer.pipeline.recipe.invalidate_data() #self.dsviewer.pipeline.Rebuild() self.progPan.fitResults = self.fitResults self.view.points = np.vstack( (self.fitResults['fitResults']['x0'], self.fitResults['fitResults']['y0'], self.fitResults['tIndex'])).T self.numEvents = len(self.fitResults) try: self.dsviewer.LMDisplay.RefreshView() except: pass if (self.tq.getNumberOpenTasks(self.queueName) + self.tq.getNumberTasksInProgress(self.queueName) ) == 0 and 'SpoolingFinished' in self.image.mdh.getEntryNames(): self.dsviewer.statusbar.SetBackgroundColour(wx.GREEN) self.dsviewer.statusbar.Refresh() self.progPan.draw() self.progPan.Refresh() self.dsviewer.Refresh() self.dsviewer.update()
def execute(self, namespace): #from PYME.localization.FitFactories import DumbellFitR from PYME.IO import MetaDataHandler img = namespace[self.inputImage] md = MetaDataHandler.NestedClassMDHandler() #set metadata entries needed for fitting to suitable defaults md['Camera.ADOffset'] = img.data[:, :, 0].min() md['Camera.TrueEMGain'] = 1.0 md['Camera.ElectronsPerCount'] = 1.0 md['Camera.ReadNoise'] = 1.0 md['Camera.NoiseFactor'] = 1.0 md['voxelsize.x'] = .001 md['voxelsize.y'] = .001 #copy across the entries from the real image, replacing the defaults #if necessary md.copyEntriesFrom(img.mdh) inp = namespace[self.inputPositions] fitMod = __import__('PYME.localization.FitFactories.' + self.fitModule, fromlist=['PYME', 'localization', 'FitFactories' ]) #import our fitting module r = np.zeros(len(inp['x']), dtype=fitMod.FitResultsDType) ff_t = -1 ps = img.pixelSize print('pixel size: %s' % ps) for x, y, t, i in zip(inp['x'], inp['y'], inp['t'], range(len(inp['x']))): if not t == ff_t: md['tIndex'] = t ff = fitMod.FitFactory(img.data[:, :, t, self.channel], md) ff_t = t #print x/ps, y/ps r[i] = ff.FromPoint(x / ps, y / ps, roiHalfSize=self.roiHalfSize) res = tabular.FitResultsSource(r, sort=False) res.mdh = md namespace[self.outputName] = res
def _OnCoalesce(self, event=None): from PYME.IO import tabular from PYME.Analysis.points.DeClump import pyDeClump pipeline = self.visFr.pipeline try: nphotons = pipeline.selectedDataSource['nPhotons'] except KeyError: nphotons = None #TODO - check what nPhotons is doing here!!! dclumped = pyDeClump.coalesceClumps(pipeline.selectedDataSource.resultsSource.fitResults, pipeline.selectedDataSource['clumpIndex'], nphotons) ds = tabular.FitResultsSource(dclumped) pipeline.addDataSource('Coalesced', ds) pipeline.selectDataSource('Coalesced')
def execute(self, namespace): from PYME.localization.FitFactories import DumbellFitR from PYME.IO import MetaDataHandler img = namespace[self.inputImage] md = MetaDataHandler.NestedClassMDHandler() #set metadata entries needed for fitting to suitable defaults md['Camera.ADOffset'] = img.data[:,:,0].min() md['Camera.TrueEMGain'] = 1.0 md['Camera.ElectronsPerCount'] = 1.0 md['Camera.ReadNoise'] = 1.0 md['Camera.NoiseFactor'] = 1.0 #copy across the entries from the real image, replacing the defaults #if necessary md.copyEntriesFrom(img.mdh) inp = namespace[self.inputPositions] r = np.zeros(len(inp['x']), dtype=DumbellFitR.FitResultsDType) ff_t = -1 ps = img.pixelSize for x, y, t, i in zip(inp['x'], inp['y'], inp['t'], range(len(inp['x']))): if not t == ff_t: md['tIndex'] = t ff = DumbellFitR.FitFactory(img.data[:,:,t], md) ff_t = t r[i] = ff.FromPoint(x/ps, y/ps) res = tabular.FitResultsSource(r) res.mdh = md namespace[self.outputName] = res
def OnGenEvents(self, event): from PYME.simulation import locify #from PYME.Acquire.Hardware.Simulator import wormlike2 from PYME.IO import tabular from PYME.IO.image import ImageBounds # import pylab import matplotlib.pyplot as plt #wc = wormlike2.wormlikeChain(100) pipeline = self.visFr.pipeline pipeline.filename = 'Simulation' plt.figure() plt.plot(self.xp, self.yp, 'x') #, lw=2) if isinstance(self.source, WormlikeSource): plt.plot(self.xp, self.yp, lw=2) if self.mode == 'STORM': res = locify.eventify(self.xp, self.yp, self.meanIntensity, self.meanDuration, self.backgroundIntensity, self.meanEventNumber, self.scaleFactor, self.meanTime, z=self.zp) else: res = locify.eventify2(self.xp, self.yp, self.meanIntensity, self.meanDuration, self.backgroundIntensity, self.meanEventNumber, self.scaleFactor, self.meanTime, z=self.zp) plt.plot(res['fitResults']['x0'], res['fitResults']['y0'], '+') ds = tabular.MappingFilter(tabular.FitResultsSource(res)) try: # some data sources (current ImageSource) have image bound info. Use this if available # this could fail on either an AttributeError (if the data source doesn't implement bounds # or another error if something fails in get_bounds(). Only catch the AttributeError, as we have # should not be handling other errors here. pipeline.imageBounds = self.source.get_bounds() except AttributeError: pipeline.imageBounds = ImageBounds.estimateFromSource(ds) pipeline.addDataSource('Generated Points', ds) pipeline.selectDataSource('Generated Points') from PYME.IO.MetaDataHandler import NestedClassMDHandler pipeline.mdh = NestedClassMDHandler() pipeline.mdh['Camera.ElectronsPerCount'] = 1 pipeline.mdh['Camera.TrueEMGain'] = 1 pipeline.mdh['Camera.CycleTime'] = 1 pipeline.mdh['voxelsize.x'] = .110 # some info about the parameters pipeline.mdh['GeneratedPoints.MeanIntensity'] = self.meanIntensity pipeline.mdh['GeneratedPoints.MeanDuration'] = self.meanDuration pipeline.mdh['GeneratedPoints.MeanEventNumber'] = self.meanEventNumber pipeline.mdh[ 'GeneratedPoints.BackgroundIntensity'] = self.backgroundIntensity pipeline.mdh['GeneratedPoints.ScaleFactor'] = self.scaleFactor pipeline.mdh['GeneratedPoints.MeanTime'] = self.meanTime pipeline.mdh['GeneratedPoints.Mode'] = self.mode # the source info self.source.genMetaData(pipeline.mdh) try: pipeline.filterKeys.pop('sig') except: pass pipeline.Rebuild() if len(self.visFr.layers) < 1: self.visFr.add_pointcloud_layer( ) #TODO - move this logic so that layer added automatically when datasource is added? #self.visFr.CreateFoldPanel() self.visFr.SetFit()