Exemplo n.º 1
0
    def OnDeconvMovie(self, event, beadMode=False):
        from PYME.Deconv.deconvDialogs import DeconvSettingsDialog #,DeconvProgressDialog,DeconvProgressPanel
        #import multiprocessing

        dlg = DeconvSettingsDialog(self.dsviewer, beadMode, self.image.data.shape[3])
        if dlg.ShowModal() == wx.ID_OK:
            from PYME.Deconv import dec, richardsonLucy #, decThread
            nIter = dlg.GetNumIterationss()
            regLambda = dlg.GetRegularisationLambda()

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

            #self.dlgDeconProg = DeconvProgressDialog(self.dsviewer, nIter)
            #self.dlgDeconProg.Show()
            vx = self.image.mdh.getEntry('voxelsize.x')
            vy = self.image.mdh.getEntry('voxelsize.y')
            vz = self.image.mdh.getEntry('voxelsize.z')

            if beadMode:
                from PYME.Deconv import beadGen
                psf = beadGen.genBeadImage(dlg.GetBeadRadius(), (1e3*vx, 1e3*vy, 1e3*vz))

                decMDH['Deconvolution.BeadRadius'] = dlg.GetBeadRadius()
                
            else:
                #psf, vs = numpy.load(dlg.GetPSFFilename())
                #psf = numpy.atleast_3d(psf)
                
                psfFilename, psf, vs = dlg.GetPSF(vshint = vx)

                decMDH['Deconvolution.PSFFile'] = psfFilename

                if not (vs.x == vx and vs.y == vy):# and vs.z ==vz):
                    #rescale psf to match data voxel size
                    psf = ndimage.zoom(psf, [vs.x/vx, vs.y/vy, 1])

            data = self.image.data[:,:,:, dlg.GetChannel()].astype('f') - dlg.GetOffset()
            decMDH['Deconvolution.Offset'] = dlg.GetOffset()
            
            bg = dlg.GetBackground()
            decMDH['Deconvolution.Background'] = bg

            #crop PSF in z if bigger than stack

            #print psf.shape, data.shape
            if psf.shape[2] > data.shape[2]:
                dz = psf.shape[2] - data.shape[2]

                psf = psf[:,:,numpy.floor(dz/2):(psf.shape[2]-numpy.ceil(dz/2))]

            print((data.shape, psf.shape))


            dp = numpy.array(data)
            weights = 1

            if dlg.GetBlocking():
                decMDH['Deconvolution.Method'] = 'Blocked ICTM'
                self.checkTQ()
                from PYME.Deconv import tq_block_dec
                bs = dlg.GetBlockSize()
                self.decT = tq_block_dec.blocking_deconv(self.tq, data, psf, self.image.seriesName, blocksize={'y': bs, 'x': bs, 'z': 256})
                self.decT.go()

            else:
                decMDH['Deconvolution.Method'] = dlg.GetMethod()
                if dlg.GetMethod() == 'ICTM':
                    decMDH['Deconvolution.RegularisationParameter'] = regLambda
                    if beadMode:
                        self.dec = dec.dec_bead()
                    else:
                        self.dec = dec.dec_conv()
                else:
                    if beadMode:
                        self.dec = richardsonLucy.rlbead()
                    else:
                        self.dec = richardsonLucy.dec_conv()

                self.dec.psf_calc(psf, dp[:,:,0:1].shape)

                #print dp.__class__

                #self.decT = decThread.decThread(self.dec, dp, regLambda, nIter, weights)
                #self.decT.start()

#                p = multiprocessing.Pool()
#                slices = [(self.dec, psf, dp[:,:,i:(i+1)],regLambda, nIter, weights)  for i in range(dp.shape[2])]                
#                r = p.map(_pt, slices)
#                res = numpy.concatenate(r, 2)

                res = numpy.concatenate([self.dec.deconv(dp[:,:,i:(i+1)], regLambda, nIter, weights, bg=bg).reshape(self.dec.shape) for i in range(dp.shape[2])], 2)
                
                
                im = ImageStack(data = res, mdh = decMDH, titleStub = 'Deconvolution Result')
                mode = 'lite'
                
                self.res = ViewIm3D(im, mode=mode, parent=wx.GetTopLevelParent(self.dsviewer))                    
Exemplo n.º 2
0
    def OnDeconvICTM(self, event, beadMode=False):
        from PYME.Deconv.deconvDialogs import DeconvSettingsDialog,DeconvProgressDialog,DeconvProgressPanel

        dlg = DeconvSettingsDialog(self.dsviewer, beadMode, self.image.data.shape[3])
        if dlg.ShowModal() == wx.ID_OK:
            from PYME.Deconv import dec, decThread, richardsonLucy
            nIter = dlg.GetNumIterationss()
            regLambda = dlg.GetRegularisationLambda()

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

            #self.dlgDeconProg = DeconvProgressDialog(self.dsviewer, nIter)
            #self.dlgDeconProg.Show()
            vx = self.image.mdh.getEntry('voxelsize.x')
            vy = self.image.mdh.getEntry('voxelsize.y')
            vz = self.image.mdh.getEntry('voxelsize.z')

            if beadMode:
                from PYME.Deconv import beadGen
                psf = beadGen.genBeadImage(dlg.GetBeadRadius(), (1e3*vx, 1e3*vy, 1e3*vz))

                decMDH['Deconvolution.BeadRadius'] = dlg.GetBeadRadius()
                
            else:
                #psf, vs = numpy.load(dlg.GetPSFFilename())
                #psf = numpy.atleast_3d(psf)
                psfFilename, psf, vs = dlg.GetPSF(vshint = vx)

                decMDH['Deconvolution.PSFFile'] = dlg.GetPSFFilename()

                if not (vs.x == vx and vs.y == vy and vs.z ==vz):
                    #rescale psf to match data voxel size
                    psf = ndimage.zoom(psf, [vs.x/vx, vs.y/vy, vs.z/vz])

            data = self.image.data[:,:,:, dlg.GetChannel()].astype('f') - dlg.GetOffset()
            decMDH['Deconvolution.Offset'] = dlg.GetOffset()
            
            bg = dlg.GetBackground()
            decMDH['Deconvolution.Background'] = bg

            #crop PSF in z if bigger than stack

            print psf.shape, data.shape
            if psf.shape[2] > data.shape[2]:
                dz = psf.shape[2] - data.shape[2]

                psf = psf[:,:,numpy.floor(dz/2):(psf.shape[2]-numpy.ceil(dz/2))]

            print((data.shape, psf.shape))

            if dlg.GetPadding():
                padsize = numpy.array(dlg.GetPadSize())
                decMDH['Deconvolution.Padding'] = padsize
                dp = numpy.ones(numpy.array(data.shape) + 2*padsize, 'f')*data.mean()
                weights = numpy.zeros_like(dp)
                px, py, pz = padsize

                #print data.shape, dp[px:-(px+1), py:-(py+1), pz:-(pz+1)].shape
                dp[px:-px, py:-py, pz:-pz] = data
                #if dlg.GetRemovePadding():
                #    data = dp[px:-px, py:-py, pz:-pz]#should be a slice
                #else:
                #    data = dp
                weights[px:-px, py:-py, pz:-pz] = 1.

                weights = weights.ravel()
            else:
                dp = data
                weights = 1

            if dlg.GetBlocking():
                decMDH['Deconvolution.Method'] = 'Blocked ICTM'
                self.checkTQ()
                from PYME.Deconv import tq_block_dec
                bs = dlg.GetBlockSize()
                self.decT = tq_block_dec.blocking_deconv(self.tq, data, psf, self.image.seriesName, blocksize={'y': bs, 'x': bs, 'z': 256})
                self.decT.go()

            else:
                decMDH['Deconvolution.Method'] = dlg.GetMethod()
                if dlg.GetMethod() == 'ICTM':
                    decMDH['Deconvolution.RegularisationParameter'] = regLambda
                    if beadMode:
                        self.dec = dec.dec_bead()
                    else:
                        self.dec = dec.dec_conv()
                else:
                    if beadMode:
                        self.dec = richardsonLucy.rlbead()
                    else:
                        self.dec = richardsonLucy.dec_conv()

                self.dec.psf_calc(psf, dp.shape)

                self.decT = decThread.decThread(self.dec, dp, regLambda, nIter, weights, bg = bg)
                self.decT.start()

                tries = 0
                while tries < 10 and not hasattr(self.dec, 'fs'):
                    time.sleep(1)
                    tries += 1

                if dlg.GetPadding() and dlg.GetRemovePadding():
                    fs =  self.dec.fs[px:-px, py:-py, pz:-pz]
                else:
                    fs = self.dec.fs

                
                
                im = ImageStack(data = fs, mdh = decMDH, titleStub = 'Deconvolution Result')
                mode = 'lite'
                if beadMode:
                    mode = 'psf'
                    im.defaultExt = '*.psf' #we want to save as PSF by default
                self.res = ViewIm3D(im, mode=mode, parent=wx.GetTopLevelParent(self.dsviewer))                    
                    
                #self.res = View3D(fs, 'Deconvolution Result', mdh=decMDH, parent=wx.GetTopLevelParent(self.dsviewer), mode=mode)

                self.dlgDeconProg = DeconvProgressPanel(self.res, nIter)

                self.pinfo1 = aui.AuiPaneInfo().Name("deconvPanel").Top().Caption('Deconvolution Progress').DestroyOnClose(True).CloseButton(False)#.MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False)
                self.res._mgr.AddPane(self.dlgDeconProg, self.pinfo1)
                self.res._mgr.Update()

            self.deconTimer = mytimer()
            self.deconTimer.WantNotification.append(self.OnDeconTimer)

            self.deconTimer.Start(500)
Exemplo n.º 3
0
    image = ImageStack(filename='/data/zar_cropped.tif')

    data = image.data[:, :, :]
    psf, vs = np.load('/home/david/Desktop/id.psf')
    import Pyro.core
    import os
    tq = Pyro.core.getProxyForURI('PYRONAME://' +
                                  os.environ['PYME_TASKQUEUENAME'])
    from PYME.Deconv import tq_block_dec
    bd = tq_block_dec.blocking_deconv(tq,
                                      data,
                                      psf,
                                      'foo',
                                      blocksize={
                                          'y': 128,
                                          'x': 128,
                                          'z': 256
                                      },
                                      blockoverlap={
                                          'y': 10,
                                          'x': 10,
                                          'z': 50
                                      })
    bd.go()
    #bd.push_deconv_tasks()
    bd.fake_push_deconv()
    #bd.pull_and_deblock()

    mProfile.report()
Exemplo n.º 4
0
    def OnDeconvICTM(self, event, beadMode=False):
        from PYME.Deconv.deconvDialogs import DeconvSettingsDialog, DeconvProgressPanel

        dlg = DeconvSettingsDialog(self.dsviewer, beadMode,
                                   self.image.data.shape[3])
        if dlg.ShowModal() == wx.ID_OK:
            from PYME.Deconv import dec, decThread, richardsonLucy
            nIter = dlg.GetNumIterationss()
            regLambda = dlg.GetRegularisationLambda()

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

            vx, vy, vz = self.image.voxelsize_nm

            if beadMode:
                from PYME.Deconv import beadGen
                psf = beadGen.genBeadImage(dlg.GetBeadRadius(), (vx, vy, vz))

                decMDH['Deconvolution.BeadRadius'] = dlg.GetBeadRadius()

            else:
                psfFilename, psf, vs = dlg.GetPSF(vshint=vx)

                if psf.shape[2] < 2:
                    raise RuntimeError(
                        'Expepected a 3D PSF for 3D deconvolution. For 2D deconvolution use the DeconvMovie function'
                    )

                decMDH['Deconvolution.PSFFile'] = dlg.GetPSFFilename()

                if not (vs.x == vx and vs.y == vy and vs.z == vz):
                    #rescale psf to match data voxel size
                    psf = ndimage.zoom(psf, [vs.x / vx, vs.y / vy, vs.z / vz])

            #crop PSF in z if bigger than stack
            if psf.shape[2] > self.image.data.shape[2]:
                dz = psf.shape[2] - self.image.data.shape[2]

                psf = psf[:, :,
                          int(numpy.floor(dz / 2)):int(psf.shape[2] -
                                                       numpy.ceil(dz / 2))]

            decMDH['Deconvolution.Offset'] = dlg.GetOffset()

            bg = dlg.GetBackground()
            decMDH['Deconvolution.Background'] = bg

            if beadMode and self.image.data.shape[3] > 1:
                #special case for deconvolving multi-channel PSFs
                data = np.concatenate([
                    self.image.data[:, :, :, i].astype('f') - dlg.GetOffset()
                    for i in range(self.image.data.shape[3])
                ], 0)
            else:
                data = self.image.data[:, :, :, dlg.GetChannel()].astype(
                    'f') - dlg.GetOffset()

            if dlg.GetPadding():
                padsize = numpy.array(dlg.GetPadSize())
                decMDH['Deconvolution.Padding'] = padsize
                dp = numpy.ones(numpy.array(data.shape) + 2 * padsize,
                                'f') * data.mean()
                weights = numpy.zeros_like(dp)
                px, py, pz = padsize

                dp[px:-px, py:-py, pz:-pz] = data
                weights[px:-px, py:-py, pz:-pz] = 1.

                weights = weights.ravel()
            else:
                dp = data
                weights = 1

            if dlg.GetBlocking():
                decMDH['Deconvolution.Method'] = 'Blocked ICTM'
                self.checkTQ()
                from PYME.Deconv import tq_block_dec
                bs = dlg.GetBlockSize()
                self.decT = tq_block_dec.blocking_deconv(self.tq,
                                                         data,
                                                         psf,
                                                         self.image.seriesName,
                                                         blocksize={
                                                             'y': bs,
                                                             'x': bs,
                                                             'z': 256
                                                         })
                self.decT.go()

            else:
                decMDH['Deconvolution.Method'] = dlg.GetMethod()
                if dlg.GetMethod() == 'ICTM':
                    decMDH['Deconvolution.RegularisationParameter'] = regLambda
                    if beadMode:
                        self.dec = dec.dec_bead()
                    else:
                        self.dec = dec.dec_conv()
                else:
                    if beadMode:
                        self.dec = richardsonLucy.rlbead()
                    else:
                        self.dec = richardsonLucy.dec_conv()

                self.dec.psf_calc(psf, dp.shape)

                self.decT = decThread.decThread(self.dec,
                                                dp,
                                                regLambda,
                                                nIter,
                                                weights,
                                                bg=bg)
                self.decT.start()

                tries = 0
                while not hasattr(self.dec, 'fs'):
                    if tries > 60:
                        self.decT.kill()
                        raise RuntimeError(
                            'Initialization not complete after 60s, giving up.'
                        )

                    time.sleep(1)
                    tries += 1

                if dlg.GetPadding() and dlg.GetRemovePadding():
                    fs = self.dec.fs[px:-px, py:-py, pz:-pz]
                else:
                    fs = self.dec.fs

                if beadMode and self.image.data.shape[3] > 1:
                    #special case for bead deconvolution - unwind the stacking
                    nChans = self.image.data.shape[3]
                    xs = int(fs.shape[0] / nChans)
                    #NOTE: this relies on the slicing returning a view into the underlying data, not a copy

                    fs = [
                        fs[(i * xs):((i + 1) * xs), :, :]
                        for i in range(nChans)
                    ]

                im = ImageStack(data=fs,
                                mdh=decMDH,
                                titleStub='Deconvolution Result')
                mode = 'lite'
                if beadMode and im.data.shape[1] < 100:
                    mode = 'psf'
                    im.defaultExt = '*.psf'  #we want to save as PSF by default
                self.res = ViewIm3D(im,
                                    mode=mode,
                                    parent=wx.GetTopLevelParent(self.dsviewer))

                #self.res = View3D(fs, 'Deconvolution Result', mdh=decMDH, parent=wx.GetTopLevelParent(self.dsviewer), mode=mode)

                self.dlgDeconProg = DeconvProgressPanel(self.res, nIter)

                self.pinfo1 = aui.AuiPaneInfo().Name("deconvPanel").Top(
                ).Caption('Deconvolution Progress').DestroyOnClose(
                    True
                ).CloseButton(
                    False
                )  #.MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False)
                self.res._mgr.AddPane(self.dlgDeconProg, self.pinfo1)
                self.res._mgr.Update()

            self.deconTimer = mytimer()
            self.deconTimer.WantNotification.append(self.OnDeconTimer)

            self.deconTimer.Start(500)
Exemplo n.º 5
0
    def OnDeconvMovie(self, event, beadMode=False):
        from PYME.Deconv.deconvDialogs import DeconvSettingsDialog  #,DeconvProgressDialog,DeconvProgressPanel
        #import multiprocessing

        dlg = DeconvSettingsDialog(self.dsviewer, beadMode,
                                   self.image.data.shape[3])
        if dlg.ShowModal() == wx.ID_OK:
            from PYME.Deconv import dec, richardsonLucy  #, decThread
            nIter = dlg.GetNumIterationss()
            regLambda = dlg.GetRegularisationLambda()

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

            vx, vy, vz = self.image.voxelsize_nm

            if beadMode:
                from PYME.Deconv import beadGen
                psf = beadGen.genBeadImage(dlg.GetBeadRadius(), (vx, vy, vz))

                decMDH['Deconvolution.BeadRadius'] = dlg.GetBeadRadius()

            else:
                psfFilename, psf, vs = dlg.GetPSF(vshint=vx)

                decMDH['Deconvolution.PSFFile'] = psfFilename

                if not (vs.x == vx and vs.y == vy):  # and vs.z ==vz):
                    #rescale psf to match data voxel size
                    psf = ndimage.zoom(psf, [vs.x / vx, vs.y / vy, 1])

            data = self.image.data[:, :, :, dlg.GetChannel()].astype(
                'f') - dlg.GetOffset()
            decMDH['Deconvolution.Offset'] = dlg.GetOffset()

            bg = dlg.GetBackground()
            decMDH['Deconvolution.Background'] = bg

            #crop PSF in z if bigger than stack

            #print psf.shape, data.shape
            if psf.shape[2] > data.shape[2]:
                dz = psf.shape[2] - data.shape[2]

                psf = psf[:, :,
                          numpy.floor(dz / 2):(psf.shape[2] -
                                               numpy.ceil(dz / 2))]

            print((data.shape, psf.shape))

            dp = numpy.array(data)
            weights = 1

            if dlg.GetBlocking():
                decMDH['Deconvolution.Method'] = 'Blocked ICTM'
                self.checkTQ()
                from PYME.Deconv import tq_block_dec
                bs = dlg.GetBlockSize()
                self.decT = tq_block_dec.blocking_deconv(self.tq,
                                                         data,
                                                         psf,
                                                         self.image.seriesName,
                                                         blocksize={
                                                             'y': bs,
                                                             'x': bs,
                                                             'z': 256
                                                         })
                self.decT.go()

            else:
                decMDH['Deconvolution.Method'] = dlg.GetMethod()
                if dlg.GetMethod() == 'ICTM':
                    decMDH['Deconvolution.RegularisationParameter'] = regLambda
                    if beadMode:
                        self.dec = dec.dec_bead()
                    else:
                        self.dec = dec.dec_conv()
                else:
                    if beadMode:
                        self.dec = richardsonLucy.rlbead()
                    else:
                        self.dec = richardsonLucy.dec_conv()

                self.dec.psf_calc(psf, dp[:, :, 0:1].shape)

                #print dp.__class__

                #self.decT = decThread.decThread(self.dec, dp, regLambda, nIter, weights)
                #self.decT.start()

                #                p = multiprocessing.Pool()
                #                slices = [(self.dec, psf, dp[:,:,i:(i+1)],regLambda, nIter, weights)  for i in range(dp.shape[2])]
                #                r = p.map(_pt, slices)
                #                res = numpy.concatenate(r, 2)

                res = numpy.concatenate([
                    self.dec.deconv(
                        dp[:, :, i:(i + 1)], regLambda, nIter, weights,
                        bg=bg).reshape(self.dec.shape)
                    for i in range(dp.shape[2])
                ], 2)

                im = ImageStack(data=res,
                                mdh=decMDH,
                                titleStub='Deconvolution Result')
                mode = 'lite'

                self.res = ViewIm3D(im,
                                    mode=mode,
                                    parent=wx.GetTopLevelParent(self.dsviewer))
Exemplo n.º 6
0
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

#
################
__test__ = False
if __name__ == '__main__':
    from PYME import mProfile
    mProfile.profileOn(['tq_block_dec.py', 'dec.py'])
    
    from PYME.DSView import View3D, ViewIm3D
    from PYME.DSView.image import ImageStack
    
    image = ImageStack(filename = '/data/zar_cropped.tif')
    
    data = image.data[:,:,:]
    psf, vs = np.load('/home/david/Desktop/id.psf')
    import Pyro.core
    import os
    tq = Pyro.core.getProxyForURI('PYRONAME://' + os.environ['PYME_TASKQUEUENAME'])
    from PYME.Deconv import tq_block_dec
    bd = tq_block_dec.blocking_deconv(tq, data, psf, 'foo', blocksize={'y': 128, 'x': 128, 'z': 256}, blockoverlap={'y': 10, 'x': 10, 'z': 50})
    bd.go()
    #bd.push_deconv_tasks()
    bd.fake_push_deconv()
    #bd.pull_and_deblock()
    
    mProfile.report()
Exemplo n.º 7
0
    def OnDeconvICTM(self, event, beadMode=False):
        from PYME.Deconv.deconvDialogs import DeconvSettingsDialog, DeconvProgressDialog, DeconvProgressPanel

        dlg = DeconvSettingsDialog(self.dsviewer, beadMode,
                                   self.image.data.shape[3])
        if dlg.ShowModal() == wx.ID_OK:
            from PYME.Deconv import dec, decThread, richardsonLucy
            nIter = dlg.GetNumIterationss()
            regLambda = dlg.GetRegularisationLambda()

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

            #self.dlgDeconProg = DeconvProgressDialog(self.dsviewer, nIter)
            #self.dlgDeconProg.Show()
            vx = self.image.mdh.getEntry('voxelsize.x')
            vy = self.image.mdh.getEntry('voxelsize.y')
            vz = self.image.mdh.getEntry('voxelsize.z')

            if beadMode:
                from PYME.Deconv import beadGen
                psf = beadGen.genBeadImage(dlg.GetBeadRadius(),
                                           (1e3 * vx, 1e3 * vy, 1e3 * vz))

                decMDH['Deconvolution.BeadRadius'] = dlg.GetBeadRadius()

            else:
                #psf, vs = numpy.load(dlg.GetPSFFilename())
                #psf = numpy.atleast_3d(psf)
                psfFilename, psf, vs = dlg.GetPSF(vshint=vx)

                decMDH['Deconvolution.PSFFile'] = dlg.GetPSFFilename()

                if not (vs.x == vx and vs.y == vy and vs.z == vz):
                    #rescale psf to match data voxel size
                    psf = ndimage.zoom(psf, [vs.x / vx, vs.y / vy, vs.z / vz])

            data = self.image.data[:, :, :, dlg.GetChannel()].astype(
                'f') - dlg.GetOffset()
            decMDH['Deconvolution.Offset'] = dlg.GetOffset()

            bg = dlg.GetBackground()
            decMDH['Deconvolution.Background'] = bg

            #crop PSF in z if bigger than stack

            print psf.shape, data.shape
            if psf.shape[2] > data.shape[2]:
                dz = psf.shape[2] - data.shape[2]

                psf = psf[:, :,
                          numpy.floor(dz / 2):(psf.shape[2] -
                                               numpy.ceil(dz / 2))]

            print((data.shape, psf.shape))

            if dlg.GetPadding():
                padsize = numpy.array(dlg.GetPadSize())
                decMDH['Deconvolution.Padding'] = padsize
                dp = numpy.ones(numpy.array(data.shape) + 2 * padsize,
                                'f') * data.mean()
                weights = numpy.zeros_like(dp)
                px, py, pz = padsize

                #print data.shape, dp[px:-(px+1), py:-(py+1), pz:-(pz+1)].shape
                dp[px:-px, py:-py, pz:-pz] = data
                #if dlg.GetRemovePadding():
                #    data = dp[px:-px, py:-py, pz:-pz]#should be a slice
                #else:
                #    data = dp
                weights[px:-px, py:-py, pz:-pz] = 1.

                weights = weights.ravel()
            else:
                dp = data
                weights = 1

            if dlg.GetBlocking():
                decMDH['Deconvolution.Method'] = 'Blocked ICTM'
                self.checkTQ()
                from PYME.Deconv import tq_block_dec
                bs = dlg.GetBlockSize()
                self.decT = tq_block_dec.blocking_deconv(self.tq,
                                                         data,
                                                         psf,
                                                         self.image.seriesName,
                                                         blocksize={
                                                             'y': bs,
                                                             'x': bs,
                                                             'z': 256
                                                         })
                self.decT.go()

            else:
                decMDH['Deconvolution.Method'] = dlg.GetMethod()
                if dlg.GetMethod() == 'ICTM':
                    decMDH['Deconvolution.RegularisationParameter'] = regLambda
                    if beadMode:
                        self.dec = dec.dec_bead()
                    else:
                        self.dec = dec.dec_conv()
                else:
                    if beadMode:
                        self.dec = richardsonLucy.rlbead()
                    else:
                        self.dec = richardsonLucy.dec_conv()

                self.dec.psf_calc(psf, dp.shape)

                self.decT = decThread.decThread(self.dec,
                                                dp,
                                                regLambda,
                                                nIter,
                                                weights,
                                                bg=bg)
                self.decT.start()

                tries = 0
                while tries < 10 and not hasattr(self.dec, 'fs'):
                    time.sleep(1)
                    tries += 1

                if dlg.GetPadding() and dlg.GetRemovePadding():
                    fs = self.dec.fs[px:-px, py:-py, pz:-pz]
                else:
                    fs = self.dec.fs

                im = ImageStack(data=fs,
                                mdh=decMDH,
                                titleStub='Deconvolution Result')
                mode = 'lite'
                if beadMode:
                    mode = 'psf'
                    im.defaultExt = '*.psf'  #we want to save as PSF by default
                self.res = ViewIm3D(im,
                                    mode=mode,
                                    parent=wx.GetTopLevelParent(self.dsviewer))

                #self.res = View3D(fs, 'Deconvolution Result', mdh=decMDH, parent=wx.GetTopLevelParent(self.dsviewer), mode=mode)

                self.dlgDeconProg = DeconvProgressPanel(self.res, nIter)

                self.pinfo1 = aui.AuiPaneInfo().Name("deconvPanel").Top(
                ).Caption('Deconvolution Progress').DestroyOnClose(
                    True
                ).CloseButton(
                    False
                )  #.MinimizeButton(True).MinimizeMode(aui.AUI_MINIMIZE_CAPT_SMART|aui.AUI_MINIMIZE_POS_RIGHT)#.CaptionVisible(False)
                self.res._mgr.AddPane(self.dlgDeconProg, self.pinfo1)
                self.res._mgr.Update()

            self.deconTimer = mytimer()
            self.deconTimer.WantNotification.append(self.OnDeconTimer)

            self.deconTimer.Start(500)