def G(intensName, D, tau) : def real_fftnd(a) : a = asarray(a) for i in range(len(a.shape)) : a = real_fft(a, axis=i) return a def inverse_real_fftnd(a) : a = asarray(a) for i in range(len(a.shape)) : a = inverse_real_fft(a, axis=i) return a def unwrap(data) : (Nx,Ny,Nz) = data.shape r = zeros((Nx,Ny,Nz), data.dtype()) (r[:Nx/2,:,:],r[Nx/2:,:,:]) = (data[Nx/2:,:,:],data[:Nx/2,:,:]) (r[:,:Ny/2,:],r[:,Ny/2:,:]) = (r[:,Ny/2:,:],r[:,:Ny/2,:].copy()) (r[:,:,:Nz/2],r[:,:,Nz/2:]) = (r[:,:,Nz/2:],r[:,:,:Nz/2].copy()) return r Psi = lambda r2, D, tau : \ asarray(1./(4.*pi*D*tau)**(1.5),'f') * \ exp(asarray(-1./(4.*D*tau),'f')*r2) (O, Ohat, r2) = fetchData(intensName) return sum(sum(sum(O*unwrap(absolute(inverse_fftnd( fftnd(Psi(r2, D, tau))*Ohat ))) )))
def prepIntens(intens, Pad) : from math import ceil, log from numpy import repeat, transpose, reshape from numpy.oldnumeric.fft import fftnd if Pad : dyadicize = lambda N: 2**int(ceil(log(N)/log(2))) name = "__padded_" + intens.name else : dyadicize = lambda N: N+1 name = intens.name if name in intensPrep : return (name, intensPrep[name]) smds.msg("Preparing intens <%s>" % name, smds.MSG_DBUG) (Nx, Ny, Nz) = map(lambda x : dyadicize(2*x+1), (intens.numBins_x, intens.numBins_x, intens.numBins_z)) r2 = (transpose(repeat([repeat([range(-Nx/2, Nx/2)], Ny, 0)], Nz, 0), (2, 1, 0))*intens.binWidth_x) ** 2 # X r2 += (transpose(repeat([repeat([range(-Ny/2, Ny/2)], Nx, 0)], Nz, 0), (1, 2, 0))*intens.binWidth_x) ** 2 # Y r2 += (repeat([repeat([range(-Nz/2, Nz/2)], Ny, 0)], Nx, 0) * \ intens.binWidth_z) ** 2 # Z r2 = r2.astype('f') O = pad(intens.getData().astype('f'), (Nx, Ny, Nz)) del intens Ohat = fftnd(O) intensPrep[name] = (O, Ohat, r2) return (name, intensPrep[name])