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)) 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 gaussian_blob_paint(fwhm=30, n_fluors=18, meanIntensity=1500, meanDuration=3, backGroundIntensity=100, meanEventNumber=2): from PYME.simulation import locify nf = np.random.poisson(n_fluors) + 1 x = (fwhm / 2.35) * np.random.normal(size=nf) y = (fwhm / 2.35) * np.random.normal(size=nf) return locify.eventify2(x, y, meanIntensity, meanDuration, backGroundIntensity, meanEventNumber), len(x)
def ring_paint(radius=30, n_handles=18, labeling_prob=0.5, meanIntensity=1500, meanDuration=3, backGroundIntensity=100, meanEventNumber=2): from PYME.simulation import locify x, y = ring(radius, n_handles) mask = np.random.uniform(size=len(x)) < labeling_prob x = x[mask] y = y[mask] #print len(x), mask return locify.eventify2(x, y, meanIntensity, meanDuration, backGroundIntensity, meanEventNumber), len(x)
def uniform_blob_paint(radius=30, n_fluors=18, meanIntensity=1500, meanDuration=3, backGroundIntensity=100, meanEventNumber=2): from PYME.simulation import locify nf = np.random.poisson(4 * n_fluors / np.pi) + 1 x = radius * (2 * np.random.uniform(size=nf) - 1) y = radius * (2 * np.random.uniform(size=nf) - 1) ind = (x * x + y * y) < radius * radius x = x[ind] y = y[ind] return locify.eventify2(x, y, meanIntensity, meanDuration, backGroundIntensity, meanEventNumber), len(x)
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()