def do_n_extended_fits(nfits, xsh, ysh, imsize, gaussfit=False, maxoff=None, return_error=False, powerlaw=2.0, noise=1.0, unsharp_mask=False, smoothfactor=5, zeropad=0, shift_func=cross_correlation_shifts, sfkwargs={}, doplot=False, **kwargs): try: import progressbar widgets = [progressbar.FormatLabel('Processed: %(value)d offsets in %(elapsed)s)'), progressbar.Percentage()] progress = progressbar.ProgressBar(widgets=widgets) except ImportError: def progress(x): yield x image = make_extended(imsize, powerlaw=powerlaw) if zeropad > 0: newsize = [s+zeropad for s in image.shape] ylen,xlen = newsize xcen = xlen/2-(1-xlen%2) ycen = ylen/2-(1-ylen%2) newim = np.zeros(newsize) newim[ycen-image.shape[0]/2:ycen+image.shape[0]/2, xcen-image.shape[1]/2:xcen+image.shape[1]/2] = image image = newim if unsharp_mask: from AG_fft_tools import smooth offsets = [] for ii in progress(xrange(nfits)): inim = image-smooth(image,smoothfactor) offim = make_offset_extended(image, xsh, ysh, noise=noise, **kwargs) offim -= smooth(offim,smoothfactor) offsets.append( shift_func( inim, offim, return_error=return_error, **sfkwargs) ) else: offsets = [] if doplot: import pylab pylab.figure(3); pylab.subplot(221); pylab.imshow(image-image.mean()); pylab.subplot(222); pylab.imshow(offim-offim.mean()) #subplot(223); pylab.imshow((abs(fft2(image-image.mean())*conj(fft2(offim-offim.mean()))))) pylab.subplot(223); pylab.imshow(abs(ifft2((fft2(image)*conj(fft2(offim)))))) pylab.subplot(224); pylab.imshow(abs(ifft2((fft2(image-image.mean())*conj(fft2(offim-offim.mean())))))) draw() for ii in progress(xrange(nfits)): offim = make_offset_extended(image, xsh, ysh, noise=noise, **kwargs) offsets.append( shift_func( image, offim, return_error=return_error, **sfkwargs) ) return offsets
def smooth_cube(cube,cubedim=0,parallel=True,numcores=None,**kwargs): """ parallel-map the smooth function parallel - defaults True. Set to false if you want serial (for debug purposes?) numcores - pass to parallel_map (None = use all available) """ from AG_fft_tools import smooth from contributed import parallel_map if cubedim != 0: cube = cube.swapaxes(0,cubedim) cubelist = [cube[ii,:,:] for ii in xrange(cube.shape[0])] Psmooth = lambda C: smooth(C,**kwargs) if parallel: smoothcube = array(parallel_map(Psmooth,cubelist,numcores=numcores)) else: smoothcube = array(map(Psmooth,cubelist)) if cubedim != 0: smoothcube = smoothcube.swapaxes(0,cubedim) return smoothcube
def plane_smooth(cube,cubedim=0,parallel=True,numcores=None,**kwargs): """ parallel-map the smooth function Parameters ---------- parallel: bool defaults True. Set to false if you want serial (for debug purposes?) numcores: int pass to parallel_map (None = use all available) """ if not smoothOK: return if cubedim != 0: cube = cube.swapaxes(0,cubedim) cubelist = [cube[ii,:,:] for ii in xrange(cube.shape[0])] Psmooth = lambda C: smooth(C,**kwargs) if parallel: smoothcube = array(parallel_map(Psmooth,cubelist,numcores=numcores)) else: smoothcube = array(map(Psmooth,cubelist)) if cubedim != 0: smoothcube = smoothcube.swapaxes(0,cubedim) return smoothcube
def edge_weight(imsize, smoothsize=5, power=2): img = np.ones([imsize,imsize]) smimg = smooth(img, smoothsize, ignore_edge_zeros=False) return smimg**power