def getNeighbourDists(self, forceRetriang=False): from PYME.Analysis.LMVis import visHelpers if forceRetriang or not 'neighbourDistances' in self.GeneratedMeasures.keys( ): statNeigh = statusLog.StatusLogger( "Calculating mean neighbour distances ...") self.GeneratedMeasures['neighbourDistances'] = np.array( visHelpers.calcNeighbourDists( self.getTriangles(forceRetriang))) return self.GeneratedMeasures['neighbourDistances']
def genIm(self, dlg, imb, mdh): pixelSize = dlg.getPixelSize() jitParamName = dlg.getJitterVariable() jitScale = dlg.getJitterScale() mdh['Rendering.JitterVariable'] = jitParamName mdh['Rendering.JitterScale'] = jitScale jitVals = self._genJitVals(jitParamName, jitScale) if dlg.getSoftRender(): status = statusLog.StatusLogger("Rendering triangles ...") return visHelpers.rendJitTriang2(self.pipeline.colourFilter['x'],self.pipeline.colourFilter['y'], dlg.getNumSamples(), jitVals, dlg.getMCProbability(),imb, pixelSize) else: return self.visFr.glCanvas.genJitTim(dlg.getNumSamples(),self.pipeline.colourFilter['x'],self.pipeline.colourFilter['y'], jitVals, dlg.getMCProbability(),pixelSize)
def getTriangles(self, recalc=False): from matplotlib import delaunay if self.Triangles == None or recalc: statTri = statusLog.StatusLogger("Generating Triangulation ...") self.Triangles = delaunay.Triangulation( self.colourFilter['x'] + .1 * np.random.normal(size=len(self.colourFilter['x'])), self.colourFilter['y'] + .1 * np.random.normal(size=len(self.colourFilter['x']))) #reset things which will have changed self.edb = None try: self.GeneratedMeasures.pop('neighbourDistances') except KeyError: pass return self.Triangles
def Generate(self, event=None): jitVars = ['1.0'] jitVars += self.pipeline.colourFilter.keys() self.genMeas = self.pipeline.GeneratedMeasures.keys() if not 'neighbourDistances' in self.genMeas: self.genMeas.append('neighbourDistances') if not 'neighbourErrorMin' in self.genMeas: self.genMeas.append('neighbourErrorMin') jitVars += self.genMeas if 'z' in self.pipeline.mapping.keys(): zvals = self.pipeline.mapping['z'] else: zvals = None dlg = genImageDialog.GenImageDialog(self.mainWind, mode=self.mode, defaultPixelSize=self._defaultPixelSize, colours=self.pipeline.colourFilter.getColourChans(), zvals = zvals, jitterVariables = jitVars, jitterVarDefault=self._getDefaultJitVar(jitVars), jitterVarDefaultZ=self._getDefaultZJitVar(jitVars)) ret = dlg.ShowModal() bCurr = wx.BusyCursor() if ret == wx.ID_OK: mdh = MetaDataHandler.NestedClassMDHandler() mdh['Rendering.Method'] = self.name if 'imageID' in self.pipeline.mdh.getEntryNames(): mdh['Rendering.SourceImageID'] = self.pipeline.mdh['imageID'] mdh['Rendering.SourceFilename'] = self.pipeline.filename mdh.Source = MetaDataHandler.NestedClassMDHandler(self.pipeline.mdh) for cb in renderMetadataProviders: cb(mdh) pixelSize = dlg.getPixelSize() status = statusLog.StatusLogger('Generating %s Image ...' % self.name) imb = self._getImBounds() #record the pixel origin in nm from the corner of the camera for futrue overlays if 'Source.Camera.ROIPosX' in mdh.getEntryNames(): #a rendered image with information about the source ROI voxx, voxy = 1e3*mdh['Source.voxelsize.x'], 1e3*mdh['Source.voxelsize.y'] ox = (mdh['Source.Camera.ROIPosX'] - 1)*voxx + imb.x0 oy = (mdh['Source.Camera.ROIPosY'] - 1)*voxy + imb.y0 if 'Source.Positioning.PIFoc' in mdh.getEntryNames(): oz = mdh['Source.Positioning.PIFoc']*1e3 else: oz = 0 else: ox = imb.x0 oy = imb.y0 oz = 0 mdh['Origin.x'] = ox mdh['Origin.y'] = oy mdh['Origin.z'] = oz colours = dlg.getColour() oldC = self.pipeline.colourFilter.currentColour ims = [] for c in colours: self.pipeline.colourFilter.setColour(c) ims.append(np.atleast_3d(self.genIm(dlg, imb, mdh))) im = GeneratedImage(ims,imb, pixelSize, dlg.getZSliceThickness(), colours, mdh = mdh) imfc = ViewIm3D(im, mode='visGUI', title='Generated %s - %3.1fnm bins' % (self.name, pixelSize), glCanvas=self.visFr.glCanvas, parent=self.mainWind) #imfc = imageView.MultiChannelImageViewFrame(self.visFr, self.visFr.glCanvas, im, title='Generated %s - %3.1fnm bins' % (self.name, pixelSize)) #self.visFr.generatedImages.append(imfc) #imfc.Show() self.pipeline.colourFilter.setColour(oldC) else: imfc = None dlg.Destroy() return imfc
def RefreshView(self): if not self.pipeline.ready: return #get out of here if len(self.pipeline['x']) == 0: wx.MessageBox('No data points - try adjusting the filter', "len(filter['x']) ==0") return if self.glCanvas.init == 0: #glcanvas is not initialised return bCurr = wx.BusyCursor() if self.pipeline.objects == None: # if 'bObjMeasure' in dir(self): # self.bObjMeasure.Enable(False) self.objectMeasures = None if not self.rav == None: #remove previous event viewer i = 0 found = False while not found and i < self.notebook.GetPageCount(): if self.notebook.GetPage(i) == self.rav: self.notebook.DeletePage(i) found = True else: i += 1 self.rav = None if self.viewMode == 'points': self.glCanvas.setPoints(self.pipeline['x'], self.pipeline['y'], self.pointColour()) if 'glCanvas3D' in dir(self): self.glCanvas3D.setPoints(self.pipeline['x'], self.pipeline['y'], self.pipeline['z'], self.pointColour()) self.glCanvas3D.setCLim(self.glCanvas.clim, (-5e5, -5e5)) elif self.viewMode == 'tracks': self.glCanvas.setTracks(self.pipeline['x'], self.pipeline['y'], self.pipeline['clumpIndex'], self.pointColour()) elif self.viewMode == 'triangles': self.glCanvas.setTriang(self.pipeline.getTriangles()) elif self.viewMode == 'voronoi': status = statusLog.StatusLogger("Generating Voronoi Diagram ... ") self.glCanvas.setVoronoi(self.pipeline.getTriangles()) elif self.viewMode == 'quads': if self.pipeline.Quads == None: status = statusLog.StatusLogger("Generating QuadTree ...") self.pipeline.GenQuads() self.glCanvas.setQuads(self.pipeline.Quads) elif self.viewMode == 'interp_triangles': self.glCanvas.setIntTriang(self.pipeline.getTriangles(), self.pointColour()) elif self.viewMode == 'blobs': if self.pipeline.objects == None: #check to see that we don't have too many points if len(self.pipeline['x']) > 1e5: goAhead = wx.MessageBox( 'You have %d events in the selected ROI;\nThis could take a LONG time ...' % len(self.pipeline['x']), 'Continue with blob detection', wx.YES_NO | wx.ICON_EXCLAMATION) if not goAhead == wx.YES: return self.glCanvas.setBlobs(*self.pipeline.getBlobs()) self.objCInd = self.glCanvas.c self.displayPane.hlCLim.SetData(self.glCanvas.c, self.glCanvas.clim[0], self.glCanvas.clim[1]) if not self.colp == None and self.colp.IsShown(): self.colp.refresh() #self.sh.shell.user_ns.update(self.__dict__) wx.EndBusyCursor()