def __init__(self, ps, vox, PSSize): ps = ps.max(2) ps = ps - ps.min() ps = ps*scipy.signal.hanning(ps.shape[0])[:,None]*scipy.signal.hanning(ps.shape[1])[None,:] ps = ps/ps.sum() #PSFFileName = PSFFilename pw = (numpy.array(PSSize) - ps.shape)/2. pw1 = numpy.floor(pw) pw2 = numpy.ceil(pw) self.cachedPSF = pad.with_constant(ps, ((pw2[0], pw1[0]), (pw2[1], pw1[1])), (0,)) self.cachedOTFH = (ifftn(self.cachedPSF)*self.cachedPSF.size).astype('complex64') self.cachedOTF2 = (self.cachedOTFH*fftn(self.cachedPSF)).astype('complex64') self.weinerFT = fftw3.create_aligned_array(self.cachedOTFH.shape, 'complex64') self.weinerR = fftw3.create_aligned_array(self.cachedOTFH.shape, 'float32') self.planForward = fftw3.Plan(self.weinerR, self.weinerFT, flags = FFTWFLAGS, nthreads=NTHREADS) self.planInverse = fftw3.Plan(self.weinerFT, self.weinerR, direction='reverse', flags = FFTWFLAGS, nthreads=NTHREADS) fftwWisdom.save_wisdom() self.otf2mean = self.cachedOTF2.mean()
def preparePSF(md, PSSize): global PSFFileName, cachedPSF, cachedOTF2, cachedOTFH, autocorr PSFFilename = md.PSFFile if (not (PSFFileName == PSFFilename)) or (not (cachedPSF.shape == PSSize)): try: ps, vox = md.taskQueue.getQueueData(md.dataSourceID, 'PSF') except: fid = open(getFullExistingFilename(PSFFilename), 'rb') ps, vox = pickle.load(fid) fid.close() ps = ps.max(2) ps = ps - ps.min() #ps = ps*(ps > 0) ps = ps * scipy.signal.hanning( ps.shape[0])[:, None] * scipy.signal.hanning(ps.shape[1])[None, :] ps = ps / ps.sum() PSFFileName = PSFFilename pw = (numpy.array(PSSize) - ps.shape) / 2. pw1 = numpy.floor(pw) pw2 = numpy.ceil(pw) cachedPSF = pad.with_constant(ps, ((pw2[0], pw1[0]), (pw2[1], pw1[1])), (0, )) cachedOTFH = ifftn(cachedPSF) * cachedPSF.size cachedOTF2 = cachedOTFH * fftn(cachedPSF)
def preparePSF(md, PSSize): global PSFFileName, cachedPSF, cachedOTF2, cachedOTFH, autocorr PSFFilename = md.PSFFile if (not (PSFFileName == PSFFilename)) or (not (cachedPSF.shape == PSSize)): try: ps, vox = md.taskQueue.getQueueData(md.dataSourceID, 'PSF') except: fid = open(getFullExistingFilename(PSFFilename), 'rb') ps, vox = pickle.load(fid) fid.close() ps = ps.max(2) ps = ps - ps.min() #ps = ps*(ps > 0) ps = ps*scipy.signal.hanning(ps.shape[0])[:,None]*scipy.signal.hanning(ps.shape[1])[None,:] ps = ps/ps.sum() PSFFileName = PSFFilename pw = (numpy.array(PSSize) - ps.shape)/2. pw1 = numpy.floor(pw) pw2 = numpy.ceil(pw) cachedPSF = pad.with_constant(ps, ((pw2[0], pw1[0]), (pw2[1], pw1[1])), (0,)) cachedOTFH = ifftn(cachedPSF)*cachedPSF.size cachedOTF2 = cachedOTFH*fftn(cachedPSF)
def __init__(self, ps, vox, PSSize): ps = ps.max(2) ps = ps - ps.min() ps = ps * scipy.signal.hanning( ps.shape[0])[:, None] * scipy.signal.hanning(ps.shape[1])[None, :] ps = ps / ps.sum() #PSFFileName = PSFFilename pw = (numpy.array(PSSize) - ps.shape) / 2. pw1 = numpy.floor(pw) pw2 = numpy.ceil(pw) self.cachedPSF = pad.with_constant(ps, ((pw2[0], pw1[0]), (pw2[1], pw1[1])), (0, )) self.cachedOTFH = (ifftn(self.cachedPSF) * self.cachedPSF.size).astype('complex64') self.cachedOTF2 = (self.cachedOTFH * fftn(self.cachedPSF)).astype('complex64') self.weinerFT = fftw3.create_aligned_array(self.cachedOTFH.shape, 'complex64') self.weinerR = fftw3.create_aligned_array(self.cachedOTFH.shape, 'float32') self.planForward = fftw3.Plan(self.weinerR, self.weinerFT, flags=FFTWFLAGS, nthreads=NTHREADS) self.planInverse = fftw3.Plan(self.weinerFT, self.weinerR, direction='reverse', flags=FFTWFLAGS, nthreads=NTHREADS) fftwWisdom.save_wisdom() self.otf2mean = self.cachedOTF2.mean()