Пример #1
0
    def calcCRB(self, caller=None):
        from PYME.Analysis import cramerRao
        from PYME.Analysis.PSFGen import fourierHNA
        #print 'b'
        import numpy as np
        try:
            d = self.image.data[:, :, :, 0].squeeze()
            I = d[:, :, int(d.shape[2] / 2)].sum()

            vs = self.image.voxelsize_nm

            #print 'fi'
            FI = cramerRao.CalcFisherInformZn2(d * (2e3 / I) + self.background,
                                               100,
                                               voxelsize=vs)
            #print 'crb'
            self.crb = cramerRao.CalcCramerReoZ(FI)
            #print 'crbd'

            z_ = np.arange(d.shape[2]) * vs.z
            self.z_ = z_ - z_.mean()

            ps_as = fourierHNA.GenAstigPSF(self.z_, dx=vs.x, strength=2)
            I = ps_as[:, :, int(ps_as.shape[2] / 2)].sum()
            self.crb_as = (cramerRao.CalcCramerReoZ(
                cramerRao.CalcFisherInformZn2(ps_as * 2000 / I +
                                              self.background,
                                              500,
                                              voxelsize=vs)))

            self.draw()
        except np.linalg.linalg.LinAlgError:
            # don't hang if we can't compute the CRLB
            import traceback
            traceback.print_exc()
Пример #2
0
    def OnCalcCRB3DvsBG(self, event):
        from PYME.Analysis import cramerRao
        from PYME.Analysis.PSFGen import fourierHNA
        #print 'b'
        import numpy as np

        vs = 1e3 * np.array([
            self.image.mdh['voxelsize.x'], self.image.mdh['voxelsize.y'],
            self.image.mdh['voxelsize.z']
        ])

        zf = self.image.data.shape[2] / 2
        dz = 500 / vs[2]

        d = self.image.data[:, :, (zf - dz):(zf + dz + 1)]
        I = d[:, :, d.shape[2] / 2].sum()

        bgv = np.logspace(-1, 2)
        z_ = np.arange(d.shape[2]) * vs[2]
        z_ = z_ - z_.mean()

        ps_as = fourierHNA.GenAstigPSF(z_, vs[0], 2)
        Ias = ps_as[:, :, ps_as.shape[2] / 2].sum()

        crb3D = []
        crb3Das = []

        for bg in bgv:
            FI = cramerRao.CalcFisherInformZn2(d * (2e3 / I) + bg,
                                               100,
                                               voxelsize=vs)
            crb = cramerRao.CalcCramerReoZ(FI)
            crb_as = (cramerRao.CalcCramerReoZ(
                cramerRao.CalcFisherInformZn2(ps_as * 2000 / Ias + bg,
                                              500,
                                              voxelsize=vs)))

            crb3D.append(np.sqrt(crb.sum(1)).mean())
            crb3Das.append(np.sqrt(crb_as.sum(1)).mean())

        import pylab

        pylab.figure()
        pylab.plot(bgv, crb3Das, label='Theoretical PSF')
        pylab.plot(bgv, crb3D, label='Measured PSF')
        pylab.legend()

        pylab.xlabel('Background [photons]')
        pylab.ylabel('Average CRB 3D')
        pylab.title('Cramer-Rao bound vs Background')
Пример #3
0
def genCRB(ps):
    #calculated for a photon number of 2000, bg of 0
    #I = ps[:,:,ps.shape[2]/2].sum()
    return cramerRao.CalcCramerReoZ(
        cramerRao.CalcFisherInformZn2(ps * 2000 / I,
                                      500,
                                      voxelsize=[70, 70, 25]))
Пример #4
0
    def OnCalcCRB(self, event):
        #print 'f'
        from PYME.Analysis import cramerRao
        from PYME.Analysis.PSFGen import fourierHNA
        #print 'b'
        import numpy as np

        d = self.image.data[:, :, :]
        I = d[:, :, d.shape[2] / 2].sum()

        vs = 1e3 * np.array([
            self.image.mdh['voxelsize.x'], self.image.mdh['voxelsize.y'],
            self.image.mdh['voxelsize.z']
        ])

        #print 'fi'
        FI = cramerRao.CalcFisherInformZn2(d * (2e3 / I), 100, voxelsize=vs)
        #print 'crb'
        crb = cramerRao.CalcCramerReoZ(FI)
        #print 'crbd'

        import pylab
        z_ = np.arange(d.shape[2]) * self.image.mdh['voxelsize.z'] * 1.0e3
        z_ = z_ - z_.mean()

        print('p')
        pylab.figure()
        pylab.plot(z_, np.sqrt(crb[:, 0]), label='x')
        pylab.plot(z_, np.sqrt(crb[:, 1]), label='y')
        pylab.plot(z_, np.sqrt(crb[:, 2]), label='z')
        pylab.legend()

        pylab.xlabel('Defocus [nm]')
        pylab.ylabel('Std. Dev. [nm]')
        pylab.title('Cramer-Rao bound for 2000 photons')

        ps_as = fourierHNA.GenAstigPSF(z_, vs[0], 2)
        I = ps_as[:, :, ps_as.shape[2] / 2].sum()
        crb_as = np.sqrt(
            cramerRao.CalcCramerReoZ(
                cramerRao.CalcFisherInformZn2(ps_as * 2000 / I,
                                              500,
                                              voxelsize=vs)))
        pylab.plot(z_, crb_as[:, 0], 'b:')
        pylab.plot(z_, crb_as[:, 1], 'g:')
        pylab.plot(z_, crb_as[:, 2], 'r:')
Пример #5
0
 def calcCRB(self, caller=None):
     from PYME.Analysis import cramerRao
     from PYME.PSFGen import fourierHNA
     #print 'b'
     import numpy as np
     d = self.image.data[:,:,:]
     I = d[:,:,d.shape[2]/2].sum()
     
     vs = 1e3*np.array([self.image.mdh['voxelsize.x'], self.image.mdh['voxelsize.y'],self.image.mdh['voxelsize.z']])
     
     #print 'fi'        
     FI = cramerRao.CalcFisherInformZn2(d*(2e3/I) + self.background, 100, voxelsize=vs)
     #print 'crb'
     self.crb = cramerRao.CalcCramerReoZ(FI)
     #print 'crbd'
     
     z_ = np.arange(d.shape[2])*self.image.mdh['voxelsize.z']*1.0e3
     self.z_ = z_ - z_.mean()
     
     ps_as = fourierHNA.GenAstigPSF(self.z_, vs[0], 2)  
     I = ps_as[:,:,ps_as.shape[2]/2].sum()
     self.crb_as = (cramerRao.CalcCramerReoZ(cramerRao.CalcFisherInformZn2(ps_as*2000/I + self.background, 500, voxelsize=vs)))
     
     self.draw()