def gaussianArrND(shape=(256, 256), sigma=2., peakVal=None, orig=None, rot=0): try: ndim = len(shape) except TypeError: shape = [shape] ndim = 1 sidx = ndim + 2 slices = [Ellipsis] + [slice(0, m) for m in shape] inds, LD = imgFit.rotateIndicesND(slices, N.float32, rot) #inds = N.indices(shape, N.float32) try: if len(sigma) != ndim: raise ValueError, 'len(sigma) must be the same as len(shape)' except TypeError: sigma = [sigma] * ndim if orig is None: c = N.asarray(shape, N.float32) / 2. else: c = N.asarray(orig, N.float32) if peakVal: k0 = peakVal else: k0 = 1. / (N.average(sigma) * ((2 * N.pi)**0.5)) param = [0, k0] + list(c) + list(sigma) param = N.asarray(param, N.float32) return imgFit.yGaussianND(param, inds, sidx)
def getSphericalAbbe(arr3D, kmin=2, kmax=60, plot=False): """ compare frequency above and below the focus return amplitude var(above)/var(below) """ afz = getFourierZprofile(arr3D) # get z profile around the reasonable frequency aa = N.abs(N.average(afz[:, kmin:kmax], axis=1)) # previously it was N.average(N.abs(afz[:,kmin:kmax]), axis=1), but that seems wrong... # findMax inds = N.indices(aa.shape, dtype=N.float64) v, _0, _1, z = U.findMax(aa) parm, check = imgFit.fitGaussianND(aa, [z], window=len(aa)) if check == 5: raise RuntimeError, 'Peak not found check=%i' % check gg = imgFit.yGaussianND(parm, inds, 3) amg = aa - gg z0 = parm[2] mask = (parm[-1] * 3) / 2. # sigma * 3 / 2 ms0 = N.ceil(z0 - mask) ms1 = N.ceil(z0 + mask) amg[ms0:ms1] = 0 below = N.var(amg[:ms0]) above = N.var(amg[ms1:]) if plot: Y.ploty(N.array((aa, gg, amg))) print 'below: ', below print 'above: ', above print ms0, ms1, z0 return above / (above + below) #above / below