예제 #1
0
def genTheoreticalModel(md, zernikes={}, **kwargs):
    from PYME.Analysis.PSFGen import fourierHNA
    global IntXVals, IntYVals, IntZVals, dx, dy, dz

    if True:  #not dx == md.voxelsize.x*1e3 or not dy == md.voxelsize.y*1e3 or not dz == md.voxelsize.z*1e3:

        vs = md.voxelsize_nm
        IntXVals = vs.x * np.mgrid[-150:150]
        IntYVals = vs.y * np.mgrid[-150:150]
        IntZVals = vs.z * np.mgrid[-30:30]

        dx, dy, dz = vs

        P = np.arange(0, 1.01, .01)

        #interpModel = genWidefieldPSF(IntXVals, IntYVals, IntZVals, P ,1e3, 0, 0, 0, 2*pi/525, 1.47, 10e3).astype('f')
        im = fourierHNA.GenZernikeDPSF(IntZVals,
                                       zernikes,
                                       X=IntXVals,
                                       Y=IntYVals,
                                       dx=vs.x,
                                       **kwargs)

        #print('foo')
        #print((interpModel.strides, interpModel.shape))

        for i in range(1, len(interpModel_by_chan)):
            interpModel_by_chan[i] = None

        interpModel_by_chan[0] = np.maximum(
            im / im[:, :, int(len(IntZVals) / 2)].sum(),
            0)  #normalise to 1 and clip
예제 #2
0
    def OnPSFFromZernikeModes(self, event):
        import numpy as np
        #import pylab
        from PYME.Analysis.PSFGen import fourierHNA
        
        from PYME.IO.image import ImageStack
        from PYME.DSView import ViewIm3D
        
        self.configure_traits(kind='modal')

        z_ = np.arange(self.sizeZ)*float(self.zSpacing)
        z_ -= z_.mean()        
        
        #if self.vectorial:
        #    ps = fourierHNA.PsfFromPupilVect(self.image.data[:,:], z_, self.image.mdh['voxelsize.x']*1e3, self.wavelength, apodization=self.apodization, NA=self.NA)#, shape = [self.sizeX, self.sizeX])
        #    #ps = abs(ps*np.conj(ps))
        #else:
        #    ps = fourierHNA.PsfFromPupil(self.image.data[:,:], z_, self.image.mdh['voxelsize.x']*1e3, self.wavelength, apodization=self.apodization, NA=self.NA)#, shape = [self.sizeX, self.sizeX])
        
        ps = fourierHNA.GenZernikeDPSF(z_, dx = self.image.voxelsize_nm.x,
                                       zernikeCoeffs = self.dsviewer.zernModes, lamb=self.wavelength, 
                                       n=1.51, NA = self.NA, ns=1.51, beadsize=0, 
                                       vect=self.vectorial, apodization=self.apodization)
        #ps = ps/ps[:,:,self.sizeZ/2].sum()
        
        ps = ps/ps.max()
        
        im = ImageStack(ps, titleStub = 'Generated PSF')
        im.mdh.copyEntriesFrom(self.image.mdh)
        im.mdh['Parent'] = self.image.filename
        #im.mdh['Processing.CropROI'] = roi
        mode = 'psf'

        dv = ViewIm3D(im, mode=mode, glCanvas=self.dsviewer.glCanvas, parent=wx.GetTopLevelParent(self.dsviewer))     
예제 #3
0
def fitallA(r2, mdh, zCoeffs, ns=1.51, axialShift=200.):
    mdh = MetaDataHandler.NestedClassMDHandler(mdh)
    mdh['Analysis.AxialShift'] = axialShift
    voxelsize = mdh.voxelsize_nm
    voxelsize.z = 50.
    zs = 50. * np.arange(-30., 31)
    p1 = fourierHNA.GenZernikeDPSF(zs, 70, zCoeffs, ns=ns)
    interpolator.setModel('foo', p1, voxelsize)

    estimator.splines.clear()
    estimator.calibrate(interpolator, mdh)

    sp_all = [
        startEstROI(r2[j], mdh, interpolator, estimator,
                    mdh['Analysis.ColourRatio'], mdh['Analysis.AxialShift'])
        for j in range(len(r2))
    ]

    fr = np.array([(fitROI(r2[j], mdh, interpolator, sp_all[j],
                           mdh['Analysis.ColourRatio'],
                           mdh['Analysis.AxialShift'])[0])
                   for j in range(len(r2))])

    #return mf[mf < (median(mf)+ 2*std(mf))].mean()
    return fr
예제 #4
0
def misfallA(r2,
             mdh,
             zCoeffs,
             ns=1.51,
             axialShift=None,
             colourRatio=None,
             beadSize=0):
    mdh = MetaDataHandler.NestedClassMDHandler(mdh)
    if not axialShift == None:
        mdh['Analysis.AxialShift'] = axialShift
    if not colourRatio == None:
        mdh['Analysis.ColourRatio'] = colourRatio
    voxelsize = mdh.voxelsize_nm
    voxelsize.z = 50.
    zs = 50. * np.arange(-30., 31)
    p1 = fourierHNA.GenZernikeDPSF(zs, 70, zCoeffs, ns=ns)
    interpolator.setModel('foo', p1, voxelsize)

    estimator.splines.clear()
    estimator.calibrate(interpolator, mdh)

    sp_all = [
        startEstROI(r2[j], mdh, interpolator, estimator,
                    mdh['Analysis.ColourRatio'], mdh['Analysis.AxialShift'])
        for j in range(len(r2))
    ]

    mf = np.array([(fitROI(r2[j], mdh, interpolator, sp_all[j],
                           mdh['Analysis.ColourRatio'],
                           mdh['Analysis.AxialShift'])[1]).sum()
                   for j in range(len(r2))])

    #return mf[mf < (median(mf)+ 2*std(mf))].mean()
    return np.sqrt(mf).mean()
예제 #5
0
    def genTheoreticalModelZernike(self,
                                   md,
                                   zmodes={},
                                   nDesign=1.51,
                                   nSample=1.51,
                                   NA=1.47,
                                   wavelength=700):
        from PYME.Analysis.PSFGen import fourierHNA
        zs = arange(-1e3, 1e3, 50)

        voxelsize = dummy()
        voxelsize.x = 1e3 * md['voxelsize.x']
        voxelsize.y = 1e3 * md['voxelsize.x']
        voxelsize.z = 1e3 * .05

        ps = fourierHNA.GenZernikeDPSF(zs,
                                       voxelsize.x,
                                       zmodes,
                                       lamb=wavelength,
                                       NA=NA,
                                       n=nDesign,
                                       ns=nSample)
        psc = self.centre2d(ps)  #FIXME: why is this needed / useful?

        return psc, voxelsize
예제 #6
0
    def genTheoreticalModelZernike(self,
                                   md,
                                   zmodes={},
                                   nDesign=1.51,
                                   nSample=1.51,
                                   NA=1.47,
                                   wavelength=700):
        from PYME.Analysis.PSFGen import fourierHNA
        from PYME.IO import MetaDataHandler
        zs = arange(-1e3, 1e3, 50)

        voxelsize = MetaDataHandler.VoxelSize(md.voxelsize_nm)
        voxelsize.z = 50.

        ps = fourierHNA.GenZernikeDPSF(zs,
                                       voxelsize.x,
                                       zmodes,
                                       lamb=wavelength,
                                       NA=NA,
                                       n=nDesign,
                                       ns=nSample)
        psc = self.centre2d(ps)  #FIXME: why is this needed / useful?

        return psc, voxelsize
예제 #7
0
def GenMultiChanZernikeDPSF(Z,
                            zerns2,
                            wavelengths,
                            dx=70.,
                            output_shape=[61, 61, 61],
                            **kwargs):
    from PYME.Analysis.PSFGen import fourierHNA

    psfs = list()

    for i in range(len(zerns2)):
        psf = fourierHNA.GenZernikeDPSF(Z,
                                        dx=dx,
                                        zernikeCoeffs=zerns2[i],
                                        lamb=wavelengths[i],
                                        output_shape=output_shape,
                                        **kwargs)
        psf /= psf.sum(1).sum(0).max()  #, 1)).max()

        psfs.append(psf)

    psfs = np.concatenate(psfs, 0)

    return psfs