Esempio n. 1
0
    def genIm(self, settings, imb, mdh):
        pixelSize = settings['pixelSize']
        jitParamName = settings['jitterVariable']
        jitScale = settings['jitterScale']

        mdh['Rendering.JitterVariable'] = jitParamName
        mdh['Rendering.JitterScale'] = jitScale

        jitVals = np.maximum(self._genJitVals(jitParamName, jitScale),
                             pixelSize)

        if settings['softRender']:
            status = statusLog.StatusLogger("Rendering triangles ...")
            return visHelpers.rendJitTriang2(self.colourFilter['x'],
                                             self.colourFilter['y'],
                                             settings['numSamples'], jitVals,
                                             settings['MCProbability'], imb,
                                             pixelSize)
        else:
            return self.visFr.glCanvas.genJitTim(settings['numSamples'],
                                                 self.colourFilter['x'],
                                                 self.colourFilter['y'],
                                                 jitVals,
                                                 settings['MCProbability'],
                                                 pixelSize)
Esempio n. 2
0
 def getNeighbourDists(self, forceRetriang = False):
     from PYME.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']
Esempio n. 3
0
    def Generate(self, settings):
        mdh = MetaDataHandler.NestedClassMDHandler()
        copy_sample_metadata(self.pipeline.mdh, mdh)
        mdh['Rendering.Method'] = self.name
        if 'imageID' in self.pipeline.mdh.getEntryNames():
            mdh['Rendering.SourceImageID'] = self.pipeline.mdh['imageID']
        mdh['Rendering.SourceFilename'] = getattr(self.pipeline, 'filename',
                                                  '')
        mdh['Rendering.NEventsRendered'] = len(
            self.pipeline[self.pipeline.keys(
            )[0]])  # in future good to use colourfilter for per channel info?
        mdh.Source = MetaDataHandler.NestedClassMDHandler(self.pipeline.mdh)

        for cb in renderMetadataProviders:
            cb(mdh)

        pixelSize = settings['pixelSize']
        sliceThickness = settings['zSliceThickness']

        status = statusLog.StatusLogger('Generating %s Image ...' % self.name)

        # get image bounds at integer multiple of pixel size
        imb = self._get_image_bounds(pixelSize, sliceThickness,
                                     *settings.get('zBounds', [None, None]))

        #record the pixel origin in nm from the corner of the camera for futrue overlays
        ox, oy, oz = MetaDataHandler.origin_nm(mdh)
        if not imb.z0 == 0:
            # single plane in z stack
            # FIXME - what is z for 3D fitting at a single focal plane? Check for pipeline['focus']==0 instead?
            oz = 0

        mdh['Origin.x'] = ox + imb.x0
        mdh['Origin.y'] = oy + imb.y0
        mdh['Origin.z'] = oz + imb.z0

        colours = settings['colours']
        oldC = self.colourFilter.currentColour

        ims = []

        for c in colours:
            self.colourFilter.setColour(c)
            ims.append(np.atleast_3d(self.genIm(settings, imb, mdh)))

        self.colourFilter.setColour(oldC)

        return GeneratedImage(ims,
                              imb,
                              pixelSize,
                              sliceThickness,
                              colours,
                              mdh=mdh)
Esempio n. 4
0
 def getTriangles(self, recalc = False):
     from matplotlib import tri
     
     if self.Triangles is None or recalc:
         statTri = statusLog.StatusLogger("Generating Triangulation ...")
         self.Triangles = tri.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
Esempio n. 5
0
    def RefreshView(self, event=None, **kwargs):
        #self.CreateFoldPanel()
        if not self.pipeline.ready:
            return  #get out of here

        if self._new_layers:
            #refresh view no longer updates the display

            #FIXME - this doesn't belong here (used to be done in SetPoints)
            self.glCanvas.view.translation[2] = self.pipeline['z'].mean()
            return

        #FIXME - this should be handled within the filter pane
        self.filterPane.stFilterNumPoints.SetLabel(
            '%d of %d events' % (len(self.pipeline.filter['x']),
                                 len(self.pipeline.selectedDataSource['x'])))

        if len(self.pipeline['x']) == 0:
            self.glCanvas.setOverlayMessage(
                'No data points - try adjusting the filter')
            return
        else:
            self.glCanvas.setOverlayMessage('')

        if not self.glCanvas._is_initialized:  #glcanvas is not initialised
            return

        #bCurr = wx.BusyCursor()

        #delete previous layers (new view)
        # self.glCanvas.layers = []

        # only delete the layer we created on the last call - leave other layers alone.
        if self._legacy_layer:
            try:
                self.glCanvas.layers.remove(self._legacy_layer)
            except ValueError:
                pass
            self._legacy_layer = None

        self.glCanvas.pointSize = self.pointDisplaySettings.pointSize

        if self.pipeline.objects is None:
            #            if 'bObjMeasure' in dir(self):
            #                self.bObjMeasure.Enable(False)
            self.objectMeasures = None

            if 'rav' in dir(
                    self
            ) and not self.rav is 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':
            if 'setPoints3D' in dir(
                    self.glCanvas) and 'z' in self.pipeline.keys():
                #new mode
                self.glCanvas.setPoints3D(
                    self.pipeline['x'],
                    self.pipeline['y'],
                    self.pipeline['z'],
                    self.pointColour(),
                    alpha=self.pointDisplaySettings.alpha)
            else:
                self.glCanvas.setPoints(self.pipeline['x'], self.pipeline['y'],
                                        self.pointColour())
        elif self.viewMode == 'pointsprites':
            self.glCanvas.setPoints3D(self.pipeline['x'],
                                      self.pipeline['y'],
                                      self.pipeline['z'],
                                      self.pointColour(),
                                      alpha=self.pointDisplaySettings.alpha,
                                      mode='pointsprites')
        elif self.viewMode == 'shadedpoints':
            try:
                self.glCanvas.setPoints3D(
                    self.pipeline['x'],
                    self.pipeline['y'],
                    self.pipeline['z'],
                    self.pointColour(),
                    alpha=self.pointDisplaySettings.alpha,
                    normal_x=self.pipeline['normal_x'],
                    normal_y=self.pipeline['normal_y'],
                    normal_z=self.pipeline['normal_z'],
                    mode='shadedpoints')
            except KeyError:
                self.glCanvas.setPoints3D(
                    self.pipeline['x'],
                    self.pipeline['y'],
                    self.pipeline['z'],
                    self.pointColour(),
                    alpha=self.pointDisplaySettings.alpha,
                    normal_x=self.pipeline['xn'],
                    normal_y=self.pipeline['yn'],
                    normal_z=self.pipeline['zn'],
                    mode='shadedpoints')
        elif self.viewMode == 'tracks':
            if 'setTracks3D' in dir(
                    self.glCanvas) and 'z' in self.pipeline.keys():
                self.glCanvas.setTracks3D(self.pipeline['x'],
                                          self.pipeline['y'],
                                          self.pipeline['z'],
                                          self.pipeline['clumpIndex'],
                                          self.pointColour())
            else:
                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 == 'triangles3D':
            self.glCanvas.setTriang3D(self.pipeline['x'],
                                      self.pipeline['y'],
                                      self.pipeline['z'],
                                      'z',
                                      sizeCutoff=self.glCanvas.edgeThreshold)

        elif self.viewMode == 'voronoi':
            status = statusLog.StatusLogger("Generating Voronoi Diagram ... ")
            self.glCanvas.setVoronoi(self.pipeline.getTriangles())

        elif self.viewMode == 'quads':
            if self.pipeline.Quads is 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 is 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

        #save the new layer we created so we can remove it
        self._legacy_layer = self.glCanvas.layers[-1]

        self.displayPane.hlCLim.SetData(self.glCanvas.c, self.glCanvas.clim[0],
                                        self.glCanvas.clim[1])

        if 'colp' in dir(
                self) and not self.colp is None and self.colp.IsShown():
            self.colp.refresh()
Esempio n. 6
0
    def Generate(self, settings):
        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'] = getattr(self.pipeline, 'filename',
                                                  '')
        mdh['Rendering.NEventsRendered'] = len(
            self.pipeline[self.pipeline.keys(
            )[0]])  # in future good to use colourfilter for per channel info?
        mdh.Source = MetaDataHandler.NestedClassMDHandler(self.pipeline.mdh)

        for cb in renderMetadataProviders:
            cb(mdh)

        pixelSize = settings['pixelSize']
        sliceThickness = settings['zSliceThickness']

        status = statusLog.StatusLogger('Generating %s Image ...' % self.name)

        # get image bounds at integer multiple of pixel size
        imb = self._get_image_bounds(pixelSize, sliceThickness,
                                     *settings.get('zBounds', [None, None]))

        #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 = imb.z0
        else:
            ox = imb.x0
            oy = imb.y0
            oz = imb.z0

        mdh['Origin.x'] = ox
        mdh['Origin.y'] = oy
        mdh['Origin.z'] = oz

        colours = settings['colours']
        oldC = self.colourFilter.currentColour

        ims = []

        for c in colours:
            self.colourFilter.setColour(c)
            ims.append(np.atleast_3d(self.genIm(settings, imb, mdh)))

        self.colourFilter.setColour(oldC)

        return GeneratedImage(ims,
                              imb,
                              pixelSize,
                              sliceThickness,
                              colours,
                              mdh=mdh)
Esempio n. 7
0
    def Generate(self, settings, splitSettings):
        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'] = getattr(self.pipeline, 'filename',
                                                  '')
        mdh['Rendering.NEventsRendered'] = len(
            self.pipeline[self.pipeline.keys(
            )[0]])  # in future good to use colourfilter for per channel info?
        mdh.Source = MetaDataHandler.NestedClassMDHandler(self.pipeline.mdh)

        if splitSettings is not None:
            for key in splitSettings:
                mdh['Rendering.SplitSettings.%s' % key] = splitSettings[key]

        for cb in renderMetadataProviders:
            cb(mdh)

        pixelSize = settings['pixelSize']

        status = statusLog.StatusLogger('Generating %s Image ...' % self.name)

        imb = self._getImBounds(*settings.get('zBounds', [None, None]))

        #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 = imb.z0
        else:
            ox = imb.x0
            oy = imb.y0
            oz = imb.z0

        mdh['Origin.x'] = ox
        mdh['Origin.y'] = oy
        mdh['Origin.z'] = oz

        colours = settings['colours']
        curCol = self.colourFilter.currentColour
        if curCol is None:
            colnames = ['Everything_even', 'Everything_odd']
        else:
            colnames = ['%s_even' % curCol, '%s_odd' % curCol]

        try:
            oldBlock = self.pipeline.filterKeys['timeBlock']
        except (KeyError, AttributeError):
            oldBlock = None

        ims = []

        for filter in [(-0.1, 0.5), (0.5, 1.5)]:
            self.pipeline.filterKeys['timeBlock'] = filter
            self.pipeline.Rebuild()
            ims.append(np.atleast_3d(self.genIm(settings, imb, mdh)))

        # needs to reset timeBlock in some fashion
        if oldBlock is None:
            del self.pipeline.filterKeys['timeBlock']
        else:
            self.pipeline.filterKeys['timeBlock'] = oldBlock
        self.pipeline.Rebuild()

        return GeneratedImage(ims,
                              imb,
                              pixelSize,
                              settings['zSliceThickness'],
                              colnames,
                              mdh=mdh)