def __init__(self, scope, threshold=100):
     self.scope = scope
     self.mdh = MetaData.TIRFDefault
     self.threshold = threshold
     
     self.mdh['tIndex'] = 0
     self.mdh['Camera.ADOffset'] = scope.frameWrangler.currentFrame.min()
     self.i = 0
     self.dt = np.zeros(512, ConfocCOIR.FitResultsDType)
     
     self.fx = np.zeros(256)
     self.x = self.dt['fitResults']['x0']
     
     self.fy = np.zeros(256)
     self.y = self.dt['fitResults']['y0']
     
     self.vx = View3D(self.x, mode='fgraph')
     self.vfx = View3D(self.fx, mode='fgraph')
     self.vy = View3D(self.y, mode='fgraph')
     self.vfy = View3D(self.fy, mode='fgraph')
     
     #scope.frameWrangler.WantFrameNotification.append(self.frameCOI)
     #scope.frameWrangler.WantFrameGroupNotification.append(self.OnFrameGroup)
     self.scope.frameWrangler.onFrame.connect(self.frameCOI)
     self.scope.frameWrangler.onFrameGroup.connect(self.OnFrameGroup)
예제 #2
0
    def OnExtract(self, event):
        from PYME.DSView import View3D
        #print 'extracting ...'

        mdh = self.image.mdh

        #dark = deTile.genDark(self.vp.do.ds, self.image.mdh)
        dark = mdh.getEntry('Camera.ADOffset')

        #split = False

        frames = mdh.getEntry('Protocol.PrebleachFrames')

        dt = self.image.data[:, :,
                             frames[0]:frames[1]].astype('f').mean(2) - dark

        ROIX1 = mdh.getEntry('Camera.ROIPosX')
        ROIY1 = mdh.getEntry('Camera.ROIPosY')

        ROIX2 = ROIX1 + mdh.getEntry('Camera.ROIWidth')
        ROIY2 = ROIY1 + mdh.getEntry('Camera.ROIHeight')

        if self.split:
            from PYME.Acquire.Hardware import splitter
            unmux = splitter.Unmixer(
                [mdh.getEntry('chroma.dx'),
                 mdh.getEntry('chroma.dy')], 1e3 * mdh.getEntry('voxelsize.x'))

            dt = unmux.Unmix(dt, self.mixmatrix, 0,
                             [ROIX1, ROIY1, ROIX2, ROIY2])

            View3D(dt, 'Prebleach Image')
        else:
            View3D(dt, 'Prebleach Image')
예제 #3
0
    def OnDeconvWiener(self, event):
        #from PYME.Deconv import weiner

        decMDH = MetaDataHandler.NestedClassMDHandler(self.image.mdh)
        decMDH['Deconvolution.OriginalFile'] = self.image.filename
        decMDH['Deconvolution.Method'] = 'Wiener'

        im = numpy.zeros(self.image.data.shape[:3], 'f4')

        decView = View3D(im,
                         'Deconvolution Result',
                         mdh=decMDH,
                         parent=self.dsviewer)

        decView.wienerPanel = WienerDeconvolver(decView, self.image,
                                                decView.image)

        self.pinfo1 = aui.AuiPaneInfo().Name("wienerPanel").Left(
        ).Caption('Wiener Filter').DestroyOnClose(True).CloseButton(
            False
        )  #.MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False)
        decView._mgr.AddPane(decView.wienerPanel, self.pinfo1)
        decView._mgr.Update()

        self.dsviewer.decView = decView
예제 #4
0
    def OnTile(self, event):
        from PYME.Analysis import deTile
        from PYME.DSView import View3D

        x0 = self.image.mdh.getEntry('Positioning.x')
        xm = piecewiseMapping.GenerateBacklashCorrPMFromEventList(
            self.image.events, self.image.mdh,
            self.image.mdh.getEntry('StartTime'), x0, 'ScannerXPos', 0, .0055)

        y0 = self.image.mdh.getEntry('Positioning.y')
        ym = piecewiseMapping.GenerateBacklashCorrPMFromEventList(
            self.image.events, self.image.mdh,
            self.image.mdh.getEntry('StartTime'), y0, 'ScannerYPos', 0, .0035)

        #dark = deTile.genDark(self.vp.do.ds, self.image.mdh)
        dark = self.image.mdh.getEntry('Camera.ADOffset')
        #flat = deTile.guessFlat(self.image.data, self.image.mdh, dark)
        flat = None
        #flat = numpy.load('d:/dbad004/23_7_flat.npy')
        #flat = flat.reshape(list(flat.shape[:2]) + [1,])

        #print dark.shape, flat.shape

        split = False

        dt = deTile.tile(self.image.data,
                         xm,
                         ym,
                         self.image.mdh,
                         split=split,
                         skipMoveFrames=False,
                         dark=dark,
                         flat=flat)  #, mixmatrix = [[.3, .7], [.7, .3]])

        mdh = MetaDataHandler.NestedClassMDHandler(self.image.mdh)

        if dt.ndim > 2:
            View3D([dt[:, :, 0][:, :, None], dt[:, :, 1][:, :, None]],
                   'Tiled Image',
                   mdh=mdh,
                   parent=wx.GetTopLevelParent(self.dsviewer))
        else:
            View3D(dt,
                   'Tiled Image',
                   mdh=mdh,
                   parent=wx.GetTopLevelParent(self.dsviewer))
예제 #5
0
    def SetScanningHex(self,
                       period,
                       exposureMs=100,
                       angle=0,
                       dutyCycle=.5,
                       nSteps=20):
        pats = []
        periodX, periodY, dc = period, int(
            period / np.tan(np.pi / 6)), np.sqrt(dutyCycle)
        widthX, widthY = int(periodX * dc), int(periodY * dc)
        if widthX % 2 == 1:
            widthX += 1
        while widthY % 4 > 0:
            widthY += 1
        nSteps = int(1 / dc)
        periodX, periodY = nSteps * widthX, nSteps * widthY
        for py in np.linspace(0, periodY, nSteps, False):
            for px in np.linspace(0, periodX, nSteps, False):
                pats.append(
                    self.GenHex(periodX,
                                periodY,
                                widthX=widthX,
                                widthY=widthY,
                                phasex=px,
                                phasey=py).T)
        from PYME.DSView import View3D
        pats1, pats2 = pats[:len(pats) // 2], pats[len(pats) // 2:]
        pats3 = [val for pair in zip(pats1, pats2) for val in pair]

        if len(pats3) < len(pats):
            pats3 += [max(pats1, pats2, key=len)[-1]]
        View3D(np.array(pats3).transpose(2, 1, 0), 'stack')
        View3D(np.array(pats3).transpose(2, 1, 0).mean(2), 'mean')

        self.SetPatternDefs(pats3, exposureMs=exposureMs)
        self.StartPatternSeq()

        self.PatternVars['Type'] = 'Hex'
        self.PatternVars['Period'] = periodX
        self.PatternVars['DutyCycle'] = 1.0 * widthX / periodX
        self.PatternVars['Phase'] = ''
        self.PatternVars['Angle'] = angle
        self.PatternVars['ExpTime'] = exposureMs
        self.PatternVars['Steps'] = nSteps
예제 #6
0
    def OnSplitChannels(self, event):
        try:
            names = self.image.mdh.getEntry('ChannelNames')
        except:
            names = ['%d' % d for d in range(self.image.data.shape[3])]

        for i in range(self.image.data.shape[3]):
            mdh = MetaDataHandler.NestedClassMDHandler(self.image.mdh)
            mdh.setEntry('ChannelNames', [names[i]])

            View3D(self.image.data[:,:,:,i], '%s - %s' % (self.image.filename, names[i]), mdh=mdh, parent=wx.GetTopLevelParent(self.dsviewer))
예제 #7
0
    def SetScanningVDC(self,
                       period,
                       exposureMs=100,
                       angle=0,
                       dutyCycle=.5,
                       nSteps=20,
                       double=True):
        width = int(period * dutyCycle)
        dd = 1
        if double:
            if width % 2 == 1:
                width += 1
            dd = 2
        nSteps = int(1 / dutyCycle)
        period = nSteps * width
        nSteps = dd * nSteps
        pats = [
            self.GenVDCLines(period, phase=p, angle=angle, width=width).T
            for p in np.linspace(0, period, nSteps, False)
        ]
        pats1, pats2 = pats[:(len(pats) // 2)], pats[(len(pats) // 2):]
        pats3 = [val for pair in zip(pats1, pats2) for val in pair]
        if len(pats3) < len(pats):
            pats3 += [max(pats1, pats2, key=len)[-1]]

        from PYME.DSView import View3D
        View3D(np.array(pats3).transpose(2, 1, 0), 'stack')
        View3D(np.array(pats3).transpose(2, 1, 0).mean(2), 'mean')

        self.SetPatternDefs(pats3, exposureMs=exposureMs)
        self.StartPatternSeq()

        self.PatternVars['Type'] = 'Lines'
        self.PatternVars['Period'] = period
        self.PatternVars['DutyCycle'] = 1.0 * width / period
        self.PatternVars['Phase'] = ''
        self.PatternVars['Angle'] = angle
        self.PatternVars['ExpTime'] = exposureMs
        self.PatternVars['Steps'] = nSteps
예제 #8
0
    def OnExtract(self, event):
        from PYME.DSView import View3D
        from PYME.IO.MetaDataHandler import get_camera_roi_origin
        #print 'extracting ...'

        mdh = self.image.mdh

        #dark = deTile.genDark(self.vp.do.ds, self.image.mdh)
        dark = mdh.getEntry('Camera.ADOffset')

        #split = False

        frames = mdh.getEntry('Protocol.PrebleachFrames')

        dt = self.image.data[:, :,
                             frames[0]:frames[1]].astype('f').mean(2) - dark

        roi_x0, roi_y0 = get_camera_roi_origin(mdh)

        ROIX1 = roi_x0 + 1
        ROIY1 = roi_y0 + 1

        ROIX2 = ROIX1 + mdh.getEntry('Camera.ROIWidth')
        ROIY2 = ROIY1 + mdh.getEntry('Camera.ROIHeight')

        if self.split:
            from PYME.Acquire.Hardware import splitter
            unmux = splitter.Unmixer(
                [mdh.getEntry('chroma.dx'),
                 mdh.getEntry('chroma.dy')], mdh.voxelsize_nm.x)

            dt = unmux.Unmix(dt, self.mixmatrix, 0,
                             [ROIX1, ROIY1, ROIX2, ROIY2])

            View3D(dt, 'Prebleach Image')
        else:
            View3D(dt, 'Prebleach Image')
예제 #9
0
 def OnDeconEnd(self, sucess):
     if not 'res' in dir(self):
         self.dlgDeconProg.Destroy()
     else:
         self.res._mgr.ClosePane(self.pinfo1)
         self.res._mgr.Update()
         self.res.DataChanged()
     if sucess:
         #if 'decvp' in dir(self):
         #    for pNum in range(self.dsviewer.notebook1.GetPageCount()):
         #        if self.dsviewer.notebook1.GetPage(pNum) == self.decvp:
         #            self.dsviewer.notebook1.DeletePage(pNum)
         #self.decvp = MyViewPanel(self.dsviewer.notebook1, self.decT.res)
         #self.dsviewer.notebook1.AddPage(page=self.decvp, select=True, caption='Deconvolved')
         if not 'res' in dir(self):
             View3D(self.decT.res,
                    '< Deconvolution Result >',
                    parent=self.dsviewer)
예제 #10
0
    def Start(self):
        self.image = np.zeros((self.ds.shape[0], self.ds.shape[1], 2),
                              'uint16')

        self.view = View3D(self.image, 'Live Stack')
        self.running = True

        self.zPoss = np.arange(
            self.sa.GetStartPos(),
            self.sa.GetEndPos() + .95 * self.sa.GetStepSize(),
            self.sa.GetStepSize())
        piezo = self.sa.piezos[self.sa.GetScanChannel()]
        self.piezo = piezo[0]
        self.piezoChan = piezo[1]
        self.startPos = self.piezo.GetPos(self.piezoChan)

        self.scope.pa.stop()
        self.scope.pa.WantFrameNotification.append(self.tick)
        self.scope.pa.WantStartNotification.append(self.OnAqStart)
        self.scope.pa.WantStopNotification.append(self.OnAqStop)
        self.scope.pa.start()
예제 #11
0
    def OnAlignChannels(self, event):
        #try:
        #    names = self.image.mdh.getEntry('ChannelNames')
        #except:
        #    names = ['%d' % d for d in range(self.image.data.shape[3])]
        from PYME.IO.DataSources import AlignDataSource
        from PYME.IO import dataWrap

        if isinstance(self.image.data, dataWrap.ListWrapper):
            nd = [
                AlignDataSource.DataSource(ds)
                for ds in self.image.data.wrapList
            ]
        else:
            nd = [
                AlignDataSource.DataSource(
                    dataWrap.Wrap(self.image.data[:, :, :, i]))
                for i in range(self.image.data.shape[3])
            ]

        mdh = MetaDataHandler.NestedClassMDHandler(self.image.mdh)

        res = View3D(nd,
                     '%s - %s' % (self.image.filename, 'align'),
                     mdh=mdh,
                     parent=wx.GetTopLevelParent(self.dsviewer))

        res.panAlign = ShiftPanel(res)

        pinfo1 = aui.AuiPaneInfo().Name("shiftPanel").Right(
        ).Caption('Alignment').DestroyOnClose(
            True
        ).CloseButton(False).MinimizeButton(True).MinimizeMode(
            aui.AUI_MINIMIZE_CAPT_SMART | aui.AUI_MINIMIZE_POS_RIGHT
        )  #.MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False)
        #pinfo2 = aui.AuiPaneInfo().Name("overlayPanel").Right().Caption('Overlays').CloseButton(False).MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False)
        res._mgr.AddPane(res.panAlign, pinfo1)
        res._mgr.Update()
예제 #12
0
    def OnMakeComposites(self, event):
        import numpy as np
       
        dlg = CompositeDialog(self.dsviewer, self.dsviewer.image)
        imageNames = dlg.imageNames
        #dispNames = dlg.dispNames

        if dlg.ShowModal() == wx.ID_OK:
            #others = [dispNames[n] for n in dlg.GetSelections()]
            others = dlg.GetSelections()            
            #master, mchan = _getImage(dlg.GetMaster())
            ignoreZ = dlg.GetIgnoreZ()
            interp = dlg.GetInterp()
            if interp:
                order = 3
            else:
                order = 0
                
            shape, origin, voxelsize = dlg.shape, dlg.origin, dlg.voxelsize
            print((shape, origin, voxelsize))
            
            if len(others) > 0:    
                newNames = []
                newData = []
                            
                for otherN in others:
                    other, chan = _getImage(otherN)
                        
                    try:
                        cn = other.mdh.getEntry('ChannelNames')[chan]
                        otherName = '%s - %s' % (os.path.split(other.filename)[1], cn) 
                    except:
                        if other.data.shape[3] == 1:
                            otherName = os.path.split(other.filename)[1]
                        else:
                            otherName = '%s -  %d' % (os.path.split(other.filename)[1], chan)
        
                    newNames.append(otherName)
        
                    if isinstance(other.data, dataWrap.ListWrap):
                        od = other.data.dataList[chan]
                    else:
                        od = other.data

                    if ignoreZ:                    
                        originsEqual = np.allclose(other.origin[:2], origin[:2], atol=1)
                    else:
                        originsEqual = np.allclose(other.origin, origin, atol=1)
                        
                    shiftField = dlg.GetShiftmap(otherN)

                    print(shape[:3], other.data.shape[:3])
                    
                    if (not np.allclose(other.pixelSize, voxelsize[0], rtol=.001)) or (not (other.data.shape[:3] == shape[:3])) or (not originsEqual) or shiftField:
                        #need to rescale ...
                        print(('Remapping ', otherN, originsEqual, other.origin, np.allclose(other.pixelSize, voxelsize[0], rtol=.001),(not (other.data.shape[:3] == shape[:3])), shiftField, other.pixelSize, ignoreZ))
                        #print origin, voxelsize
                        od = self.RemapData(other, chan, shape, voxelsize, origin, shiftField = shiftField, ignoreZ=ignoreZ, order=order)
                        
                    newData += [od]
    
                pre = common_prefix(newNames)
                print(pre)
                lPre = len(pre)
                newNames = [n[lPre:] for n in newNames]                
                
                mdh = MetaDataHandler.NestedClassMDHandler(self.image.mdh)
                mdh.setEntry('ChannelNames', newNames)
                
                mdh['voxelsize.x'] = voxelsize[0]/1e3
                mdh['voxelsize.y'] = voxelsize[1]/1e3
                mdh['voxelsize.z'] = voxelsize[2]/1e3
                
                mdh['Origin.x'] = origin[0]
                mdh['Origin.y'] = origin[1]
                mdh['Origin.z'] = origin[2]
    
                View3D(dataWrap.ListWrap(newData, 3), 'Composite', mdh=mdh, mode = self.dsviewer.mode, parent=wx.GetTopLevelParent(self.dsviewer), glCanvas=self.dsviewer.glCanvas)

        dlg.Destroy()
예제 #13
0
def ExtractPupil(ps, zs, dx, lamb=488, NA=1.3, n=1.51, nIters = 50, size=5e3):
    dx = float(dx)
    if not size:
        X, Y = meshgrid(float(dx)*arange(-ps.shape[0]/2, ps.shape[0]/2),float(dx)*arange(-ps.shape[1]/2, ps.shape[1]/2))
    else:
        X, Y = meshgrid(arange(-size, size, dx),arange(-size, size, dx))
        
    X = X - X.mean()
    Y = Y - Y.mean()
    
    sx = ps.shape[0]
    sy = ps.shape[1]
    ox = (X.shape[0] - sx)/2
    oy = (X.shape[1] - sy)/2
    ex = ox + sx
    ey = oy + sy
    
    #print ps.shape
    #print arange(-ps.shape[0]/2, ps.shape[0]/2)
    u = X*lamb/(n*X.shape[0]*dx*dx)
    v = Y*lamb/(n*X.shape[1]*dx*dx)
    
    

    R = sqrt(u**2 + v**2)
    M = 1.0*(R < (NA/n)) # NA/lambda
    
    figure()
    imshow(R)
    
    colorbar()
    contour(M, [0.5])
    figure()
    
    k = 2*pi*n/lamb

    FP = FourierPropagator(u,v,k, lamb)

    pupil = M*exp(1j*0)
    
    sps = sqrt(ps)
    
    View3D(sps)
    
    for i in range(nIters):
        new_pupil = 0*pupil
        
        bps = []
        abp = []
        
        print(i)#, abs(pupil).sum()
        
        #figure()
        #imshow(abs(pupil))
        res = 0
        
        for j in range(ps.shape[2]):
            #propogate to focal plane
            prop_j  = FP.propagate(pupil, zs[j])
            
            #print abs(prop_j).sum(), sqrt(ps[:,:,j]).sum()
            
            #print ps[:,:,j].shape
            #print prop_j.shape
            
            #figure()
            #imshow(angle(prop_j))
            
                        
            #print prop_j[ox:ex, oy:ey].shape, sps[:,:,j].shape
            
            res += ((abs(prop_j[ox:ex, oy:ey]) - sps[:,:,j])**2).sum()
            #replace amplitude, but keep phase
            prop_j[ox:ex, oy:ey] = sps[:,:,j]*exp(1j*angle(prop_j[ox:ex, oy:ey]))
            
            #print abs(prop_j).sum()
            
            #propagate back
            bp = FP.propagate_r(prop_j, zs[j])
            #figure()
            bps.append(abs(bp))
            abp.append(angle(bp))
            new_pupil += bp
            
            #figure()            
            #imshow(abs(new_pupil))
            
        new_pupil /= ps.shape[2]
        
        #View3D(bps)
        #View3D(abp)
        
        print(('res = %f' % (res/ps.shape[2])))
        #print abs(new_pupil).sum()
        
        #np_A = abs(new_pupil)
        #np_A = ndimage.gaussian_filter(np_A,.5)
        #np_A *= M
        
        #np_P = angle(new_pupil)
        #np_P *= M
        #np_P = ndimage.gaussian_filter(np_P, .5)
        
        
        #imshow(abs(new_pupil))
        
        #crop to NA
        #new_pupil = new_pupil*M
        
        #pupil = np_A*exp(1j*np_P)
        pupil = new_pupil*M
    
    return pupil